Add cache for images (#88)
This commit is contained in:
committed by
Jannis Mattheis
parent
cbc4e4a30b
commit
9571898287
@@ -51,9 +51,12 @@ import com.google.android.material.navigation.NavigationView;
|
|||||||
import com.squareup.picasso.OkHttp3Downloader;
|
import com.squareup.picasso.OkHttp3Downloader;
|
||||||
import com.squareup.picasso.Picasso;
|
import com.squareup.picasso.Picasso;
|
||||||
import com.squareup.picasso.Target;
|
import com.squareup.picasso.Target;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import okhttp3.Cache;
|
||||||
import okhttp3.OkHttpClient;
|
import okhttp3.OkHttpClient;
|
||||||
|
|
||||||
import static java.util.Collections.emptyList;
|
import static java.util.Collections.emptyList;
|
||||||
@@ -99,6 +102,8 @@ public class MessagesActivity extends AppCompatActivity
|
|||||||
private boolean isLoadMore = false;
|
private boolean isLoadMore = false;
|
||||||
private Integer selectAppIdOnDrawerClose = null;
|
private Integer selectAppIdOnDrawerClose = null;
|
||||||
|
|
||||||
|
int PICASSO_CACHE_SIZE = 50 * 1024 * 1024; // 50 MB
|
||||||
|
private Cache picassoCache;
|
||||||
private Picasso picasso;
|
private Picasso picasso;
|
||||||
|
|
||||||
// we need to keep the target references otherwise they get gc'ed before they can be called.
|
// we need to keep the target references otherwise they get gc'ed before they can be called.
|
||||||
@@ -113,6 +118,7 @@ public class MessagesActivity extends AppCompatActivity
|
|||||||
Log.i("Entering " + getClass().getSimpleName());
|
Log.i("Entering " + getClass().getSimpleName());
|
||||||
settings = new Settings(this);
|
settings = new Settings(this);
|
||||||
|
|
||||||
|
picassoCache = new Cache(new File(getCacheDir(), "picasso-cache"), PICASSO_CACHE_SIZE);
|
||||||
picasso = makePicasso();
|
picasso = makePicasso();
|
||||||
|
|
||||||
client =
|
client =
|
||||||
@@ -145,6 +151,11 @@ public class MessagesActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void onRefreshAll(View view) {
|
public void onRefreshAll(View view) {
|
||||||
|
try {
|
||||||
|
picassoCache.evictAll();
|
||||||
|
} catch (IOException e) {
|
||||||
|
Log.e("Problem evicting Picasso cache", e);
|
||||||
|
}
|
||||||
startActivity(new Intent(this, InitializationActivity.class));
|
startActivity(new Intent(this, InitializationActivity.class));
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
@@ -178,6 +189,8 @@ public class MessagesActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private Picasso makePicasso() {
|
private Picasso makePicasso() {
|
||||||
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
OkHttpClient.Builder builder = new OkHttpClient.Builder();
|
||||||
|
builder.cache(picassoCache);
|
||||||
|
|
||||||
CertUtils.applySslSettings(builder, settings.sslSettings());
|
CertUtils.applySslSettings(builder, settings.sslSettings());
|
||||||
|
|
||||||
OkHttp3Downloader downloader = new OkHttp3Downloader(builder.build());
|
OkHttp3Downloader downloader = new OkHttp3Downloader(builder.build());
|
||||||
|
|||||||
Reference in New Issue
Block a user