1

I am working on a Sports App that fetches game data from one API call and Team Logos from another. Every time i choose a new date/week to load both API's are called again. What is the best way i can store the results from the initial Team Logo call so i will not have to call it again when loading new set of games. I am currently using RXJava/Retrofit for my API calls. Should i store the results from the Logo api call in a SQL database?

Below is my Retrofit call

 public static Retrofit getMLBLogo(Context context) {


        retrofit2 = new retrofit2.Retrofit.Builder()
                .baseUrl(ConstMLBScoreBoard.LOGO_URL)
                .client(okHttpClient)
               .addCallAdapterFactory(RxJava2CallAdapterFactory.createWithScheduler(Schedulers.io()))
                .addConverterFactory(GsonConverterFactory.create())
                .build();



    return retrofit2;
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

1

If you want to do that, you can generate code easily with Room of Android Architecture Component.

Room Document

Room automatically generate codes for SQLite transaction just using some class with annotations.

then, you can save image to database with Blob data type

Blob is a byte array data type

For more information about blob, See this answer

How to store image to SQLite

Then, you can code like this.

    fun getBitmap(name : String) : Bitmap {
    if(name in database...){
        return database.getBitmap(name)
    }else{
        return loadBitmapWithURL(url)
    }
}
MJ Studio
  • 3,947
  • 1
  • 26
  • 37
  • Thanks for the quick reply!! I am going to implement Room into my app. Since the API returns URLs for the images, i should be fine storing the url String in the database and then retrieving the URL and loading into the ImageView with Picasso correct? So in this case i would not need to store it as a Blob data type – Ernest Ovalles Feb 08 '19 at 15:34
  • yes that is right. in your case, it is url cache rather than image cache. If your images are kind of static something, you can also use disk cache or sd card cache using other libraries like Universal Image Loader, picasso, glide... You’re welcome! – MJ Studio Feb 14 '19 at 00:36