From 7a52d04245bd98598b656fd78d0327ebea5d7ca4 Mon Sep 17 00:00:00 2001 From: Nazar Date: Fri, 25 Oct 2019 12:10:01 +0300 Subject: [PATCH] Fix screen hang during calculation bug (add a timer) Fix UI refreshing stop after screen flipping bug --- .../net/osmand/plus/settings/DataStorageFragment.java | 11 ++++++++++- .../net/osmand/plus/settings/DataStorageHelper.java | 11 +++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java index 802db74758..785edb070c 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java @@ -324,6 +324,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto if (calculateTilesMemoryTask != null) { calculateTilesMemoryTask.cancel(true); } + setRetainInstance(false); } super.onDestroy(); } @@ -450,6 +451,7 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto } private void refreshDataInfo() { + setRetainInstance(true); calculateTilesBtnPressed = false; itemsHolder = DataStorageHelper.refreshInfo(app); calculateMemoryTask = itemsHolder.calculateMemoryUsedInfo(this); @@ -483,9 +485,16 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto @Override public void onMemoryInfoUpdate() { updateAllSettings(); - app.getSettings().OSMAND_USAGE_SPACE.set(itemsHolder.getTotalUsedBytes()); } + @Override + public void onFinishUpdating(String taskKey) { + updateAllSettings(); + if (taskKey != null && taskKey.equals(TILES_MEMORY)) { + app.getSettings().OSMAND_USAGE_SPACE.set(itemsHolder.getTotalUsedBytes()); + } + } + public static class MoveFilesToDifferentDirectory extends AsyncTask { protected WeakReference activity; diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java index f2b611f21e..91359ebd18 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java @@ -274,14 +274,14 @@ public class DataStorageHelper implements Parcelable { public RefreshMemoryUsedInfo calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener) { File rootDir = new File(currentStoragePath); - RefreshMemoryUsedInfo task = new RefreshMemoryUsedInfo(listener, otherMemory, rootDir, null, null); + RefreshMemoryUsedInfo task = new RefreshMemoryUsedInfo(listener, otherMemory, rootDir, null, null, OTHER_MEMORY); task.execute(mapsMemory, srtmAndHillshadeMemory, tracksMemory, notesMemory); return task; } public RefreshMemoryUsedInfo calculateTilesMemoryUsed(UpdateMemoryInfoUIAdapter listener) { File rootDir = new File(tilesMemory.getDirectories()[0].getAbsolutePath()); - RefreshMemoryUsedInfo task = new RefreshMemoryUsedInfo(listener, otherMemory, rootDir, null, srtmAndHillshadeMemory.getPrefixes()); + RefreshMemoryUsedInfo task = new RefreshMemoryUsedInfo(listener, otherMemory, rootDir, null, srtmAndHillshadeMemory.getPrefixes(), TILES_MEMORY); task.execute(tilesMemory); return task; } @@ -293,12 +293,13 @@ public class DataStorageHelper implements Parcelable { private String[] directoriesToAvoid; private String[] prefixesToAvoid; - public RefreshMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener, DataStorageMemoryItem otherMemory, File rootDir, String[] directoriesToAvoid, String[] prefixesToAvoid) { + public RefreshMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener, DataStorageMemoryItem otherMemory, File rootDir, String[] directoriesToAvoid, String[] prefixesToAvoid, String taskKey) { this.listener = listener; this.otherMemory = otherMemory; this.rootDir = rootDir; this.directoriesToAvoid = directoriesToAvoid; this.prefixesToAvoid = prefixesToAvoid; + this.taskKey = taskKey; } @Override @@ -437,7 +438,7 @@ public class DataStorageHelper implements Parcelable { protected void onPostExecute(Void aVoid) { super.onPostExecute(aVoid); if (listener != null) { - listener.onMemoryInfoUpdate(); + listener.onFinishUpdating(taskKey); } } } @@ -467,6 +468,8 @@ public class DataStorageHelper implements Parcelable { public interface UpdateMemoryInfoUIAdapter { void onMemoryInfoUpdate(); + + void onFinishUpdating(String taskKey); }