add disk cache for images

This commit is contained in:
Conny Duck 2018-04-06 22:02:46 +02:00
parent 6d6c9575c4
commit 6120072730

View file

@ -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);
}
}
public ServiceLocator getServiceLocator() {