From bba9ed1f26a883c4d7094696781e06fc34ff3a18 Mon Sep 17 00:00:00 2001 From: nazar-kutz Date: Tue, 2 Feb 2021 10:13:01 +0200 Subject: [PATCH] Improve calculation algorithm of memory usage / fix "used memory of Hillshade doesn't calculated" --- .../task/RefreshUsedMemoryTask.java | 25 +++++++++++-------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/settings/datastorage/task/RefreshUsedMemoryTask.java b/OsmAnd/src/net/osmand/plus/settings/datastorage/task/RefreshUsedMemoryTask.java index 6f45676888..0af4cf34cb 100644 --- a/OsmAnd/src/net/osmand/plus/settings/datastorage/task/RefreshUsedMemoryTask.java +++ b/OsmAnd/src/net/osmand/plus/settings/datastorage/task/RefreshUsedMemoryTask.java @@ -99,16 +99,19 @@ public class RefreshUsedMemoryTask extends AsyncTask { for (MemoryItem memoryItem : items) { DirectoryItem[] targetDirectories = memoryItem.getDirectories(); if (targetDirectories != null) { - for (DirectoryItem targetDirectory : targetDirectories) { - String allowedDirPath = targetDirectory.getAbsolutePath(); - if (objectEquals(directoryPath, allowedDirPath) - || (directoryPath.startsWith(allowedDirPath))) { - if (targetDirectory.shouldProcessInternalDirectories()) { - calculateMultiTypes(directory, items); - return; - } else if (!targetDirectory.shouldAddUnmatchedToOtherMemory()) { - return; - } + for (DirectoryItem dir : targetDirectories) { + String allowedDirPath = dir.getAbsolutePath(); + boolean isPerfectlyMatch = objectEquals(directoryPath, allowedDirPath); + boolean isParentDirectory = !isPerfectlyMatch && (directoryPath.startsWith(allowedDirPath)); + boolean isMatchDirectory = isPerfectlyMatch || isParentDirectory; + if (isPerfectlyMatch) { + calculateMultiTypes(directory, items); + return; + } else if (isParentDirectory && dir.shouldProcessInternalDirectories()) { + calculateMultiTypes(directory, items); + return; + } else if (isMatchDirectory && !dir.shouldAddUnmatchedToOtherMemory()) { + return; } } } @@ -122,7 +125,7 @@ public class RefreshUsedMemoryTask extends AsyncTask { @NonNull MemoryItem... items) { for (MemoryItem item : items) { DirectoryItem[] targetDirectories = item.getDirectories(); - if (targetDirectories == null) continue; + if (targetDirectories == null) return; String rootDirPath = rootDir.getAbsolutePath(); for (DirectoryItem targetDirectory : targetDirectories) {