Show Picasso cache size

This commit is contained in:
Alex Sytnyk 2018-04-17 12:52:16 +03:00
parent ed18a08cdb
commit 14b027d2a6
2 changed files with 17 additions and 1 deletions

View file

@ -59,6 +59,10 @@ public class PicassoUtils {
}
}
public static long getDiskCacheSizeBytes() throws IOException {
return diskCache.size();
}
private static File createDefaultCacheDir(Context context) {
File cache = new File(context.getApplicationContext().getCacheDir(), PICASSO_CACHE);
if (!cache.exists()) {

View file

@ -12,6 +12,7 @@ import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import net.osmand.AndroidUtils;
import net.osmand.PicassoUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
@ -27,6 +28,7 @@ import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import java.io.File;
import java.io.IOException;
import java.util.List;
public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment {
@ -93,7 +95,7 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
BaseBottomSheetItem clearCacheItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.shared_string_clear))
.setDescriptionColorId(nightMode ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light)
.setTitle(getString(R.string.images_cache) + ": ???") // TODO : show images cache size
.setTitle(getString(R.string.images_cache) + getCacheSize())
.setLayoutId(R.layout.bottom_sheet_item_with_right_descr)
.setOnClickListener(new View.OnClickListener() {
@Override
@ -156,4 +158,14 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
.setNegativeButton(R.string.shared_string_dismiss, null)
.show();
}
private String getCacheSize() {
long cacheBytes = 0;
try {
cacheBytes += PicassoUtils.getDiskCacheSizeBytes();
} catch (IOException e) {
e.printStackTrace();
}
return ": " + AndroidUtils.formatSize(cacheBytes);
}
}