diff options
author | Nazar <vitaminkuna@gmail.com> | 2019-10-25 12:32:21 +0300 |
---|---|---|
committer | Nazar <vitaminkuna@gmail.com> | 2019-10-25 12:32:21 +0300 |
commit | 416318eca606a4ab7228eba6305c2a5948587d67 (patch) | |
tree | 43f0278efa023fe81f0e1bc1c5601a04754c01a5 | |
parent | 7a52d04245bd98598b656fd78d0327ebea5d7ca4 (diff) | |
download | Osmand-416318eca606a4ab7228eba6305c2a5948587d67.tar.gz |
Fix screen hang during calculation bug (add a timer)
Fix UI refreshing stop after screen flipping bug
-rw-r--r-- | OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java | 1 | ||||
-rw-r--r-- | OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java | 36 |
2 files changed, 33 insertions, 4 deletions
diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java index 785edb070c..016f0e89d8 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageFragment.java @@ -56,6 +56,7 @@ import static net.osmand.plus.settings.bottomsheets.SelectFolderBottomSheet.NEW_ public class DataStorageFragment extends BaseSettingsFragment implements DataStorageHelper.UpdateMemoryInfoUIAdapter { public final static int PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE = 500; + public final static int UI_REFRESH_TIME_MS = 500; private final static String CHANGE_DIRECTORY_BUTTON = "change_directory"; private final static String OSMAND_USAGE = "osmand_usage"; diff --git a/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java b/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java index 91359ebd18..57ab5b4ae7 100644 --- a/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java +++ b/OsmAnd/src/net/osmand/plus/settings/DataStorageHelper.java @@ -292,6 +292,23 @@ public class DataStorageHelper implements Parcelable { private DataStorageMemoryItem otherMemory; private String[] directoriesToAvoid; private String[] prefixesToAvoid; + private String taskKey; + private boolean refreshing = false; + + private Runnable refreshingTimer = new Runnable() { + + @Override + public void run() { + try { + Thread.sleep(DataStorageFragment.UI_REFRESH_TIME_MS); + } catch (InterruptedException e) { + e.printStackTrace(); + } + refreshing = false; + publishProgress(); + } + + }; public RefreshMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener, DataStorageMemoryItem otherMemory, File rootDir, String[] directoriesToAvoid, String[] prefixesToAvoid, String taskKey) { this.listener = listener; @@ -335,9 +352,13 @@ public class DataStorageHelper implements Parcelable { } for (Directory dir : directories) { if (file.getAbsolutePath().equals(dir.getAbsolutePath()) - || (file.getAbsolutePath().startsWith(dir.getAbsolutePath()) && dir.isGoDeeper())) { - calculateMultiTypes(file, items); - break nextFile; + || (file.getAbsolutePath().startsWith(dir.getAbsolutePath()))) { + if (dir.isGoDeeper()) { + calculateMultiTypes(file, items); + break nextFile; + } else if (dir.isSkipOther()) { + break nextFile; + } } } } @@ -404,7 +425,7 @@ public class DataStorageHelper implements Parcelable { otherMemory.addBytes(file.length()); } } - publishProgress(); + refreshUI(); } } @@ -441,6 +462,13 @@ public class DataStorageHelper implements Parcelable { listener.onFinishUpdating(taskKey); } } + + private void refreshUI() { + if (!refreshing) { + refreshing = true; + new Thread(refreshingTimer).start(); + } + } } public long getTotalUsedBytes() { |