From 14b027d2a6ee65c7826a0b22e65f0f91a19a941d Mon Sep 17 00:00:00 2001 From: Alex Sytnyk Date: Tue, 17 Apr 2018 12:52:16 +0300 Subject: [PATCH] Show Picasso cache size --- OsmAnd/src/net/osmand/PicassoUtils.java | 4 ++++ ...WikivoyageOptionsBottomSheetDialogFragment.java | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/PicassoUtils.java b/OsmAnd/src/net/osmand/PicassoUtils.java index 17caf47246..af127dfdd4 100644 --- a/OsmAnd/src/net/osmand/PicassoUtils.java +++ b/OsmAnd/src/net/osmand/PicassoUtils.java @@ -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()) { diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java index 534faa9e1f..73ab5346a2 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/explore/WikivoyageOptionsBottomSheetDialogFragment.java @@ -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); + } }