Fix screen hang during calculation bug (add a timer)

Fix UI refreshing stop after screen flipping bug
This commit is contained in:
Nazar 2019-10-25 12:10:01 +03:00
parent 425535c6c0
commit 7a52d04245
2 changed files with 17 additions and 5 deletions

View file

@ -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,8 +485,15 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
@Override
public void onMemoryInfoUpdate() {
updateAllSettings();
}
@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<Void, Void, Boolean> {

View file

@ -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);
}
}
}
@ -468,6 +469,8 @@ public class DataStorageHelper implements Parcelable {
void onMemoryInfoUpdate();
void onFinishUpdating(String taskKey);
}
@Override