add disk cache for images

main
Conny Duck 7 years ago
parent 645e849a22
commit c2382e7d3b
  1. 18
      app/src/main/java/com/keylesspalace/tusky/TuskyApplication.java

@ -39,6 +39,8 @@ import javax.inject.Inject;
import dagger.android.AndroidInjector;
import dagger.android.DispatchingAndroidInjector;
import dagger.android.HasActivityInjector;
import okhttp3.Cache;
import okhttp3.OkHttpClient;
public class TuskyApplication extends Application implements HasActivityInjector {
public static final String APP_THEME_DEFAULT = ThemeUtils.THEME_NIGHT;
@ -102,15 +104,19 @@ public class TuskyApplication extends Application implements HasActivityInjector
// Initialize Picasso configuration
Picasso.Builder builder = new Picasso.Builder(this);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
builder.downloader(new OkHttp3Downloader(OkHttpUtils.getCompatibleClient(preferences)));
OkHttpClient.Builder okHttpBuilder = OkHttpUtils.getCompatibleClientBuilder(preferences);
int cacheSize = 10*1024*1024; // 10 MiB
okHttpBuilder.cache(new Cache(getCacheDir(), cacheSize));
builder.downloader(new OkHttp3Downloader(okHttpBuilder.build()));
if (BuildConfig.DEBUG) {
builder.listener((picasso, uri, exception) -> exception.printStackTrace());
}
try {
Picasso.setSingletonInstance(builder.build());
} catch (IllegalStateException e) {
throw new RuntimeException(e);
}
Picasso.setSingletonInstance(builder.build());
}
public ServiceLocator getServiceLocator() {

Loading…
Cancel
Save