Data storage refactoring, step 3
This commit is contained in:
parent
7041c4ecc9
commit
8f302f8558
4 changed files with 41 additions and 38 deletions
|
@ -462,9 +462,9 @@ public class DataStorageFragment extends BaseSettingsFragment implements DataSto
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFinishUpdating(String taskKey) {
|
public void onFinishUpdating(String tag) {
|
||||||
updateAllSettings();
|
updateAllSettings();
|
||||||
if (taskKey != null && taskKey.equals(TILES_MEMORY)) {
|
if (tag != null && tag.equals(TILES_MEMORY)) {
|
||||||
app.getSettings().OSMAND_USAGE_SPACE.set(dataStorageHelper.getTotalUsedBytes());
|
app.getSettings().OSMAND_USAGE_SPACE.set(dataStorageHelper.getTotalUsedBytes());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,6 +67,11 @@ public class DataStorageHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prepareData() {
|
private void prepareData() {
|
||||||
|
initStorageItems();
|
||||||
|
initUsedMemoryItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initStorageItems() {
|
||||||
OsmandSettings settings = app.getSettings();
|
OsmandSettings settings = app.getSettings();
|
||||||
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
|
if (settings.getExternalStorageDirectoryTypeV19() >= 0) {
|
||||||
currentStorageType = settings.getExternalStorageDirectoryTypeV19();
|
currentStorageType = settings.getExternalStorageDirectoryTypeV19();
|
||||||
|
@ -169,20 +174,18 @@ public class DataStorageHelper {
|
||||||
if (currentDataStorage == null) {
|
if (currentDataStorage == null) {
|
||||||
currentDataStorage = manuallySpecified;
|
currentDataStorage = manuallySpecified;
|
||||||
}
|
}
|
||||||
|
|
||||||
initMemoryUsed();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initMemoryUsed() {
|
private void initUsedMemoryItems() {
|
||||||
mapsMemory = MemoryItem.builder()
|
mapsMemory = MemoryItem.builder()
|
||||||
.setKey(MAPS_MEMORY)
|
.setKey(MAPS_MEMORY)
|
||||||
.setExtensions(IndexConstants.BINARY_MAP_INDEX_EXT)
|
.setExtensions(IndexConstants.BINARY_MAP_INDEX_EXT)
|
||||||
.setDirectories(
|
.setDirectories(
|
||||||
createDirectory((MAPS_PATH), false, EXTENSIONS, false),
|
createDirectory(MAPS_PATH, false, EXTENSIONS, true),
|
||||||
createDirectory((ROADS_INDEX_DIR), true, EXTENSIONS, false),
|
createDirectory(ROADS_INDEX_DIR, true, EXTENSIONS, true),
|
||||||
createDirectory((WIKI_INDEX_DIR), true, EXTENSIONS, false),
|
createDirectory(WIKI_INDEX_DIR, true, EXTENSIONS, true),
|
||||||
createDirectory((WIKIVOYAGE_INDEX_DIR), true, EXTENSIONS, false),
|
createDirectory(WIKIVOYAGE_INDEX_DIR, true, EXTENSIONS, true),
|
||||||
createDirectory((BACKUP_INDEX_DIR), true, EXTENSIONS, false))
|
createDirectory(BACKUP_INDEX_DIR, true, EXTENSIONS, true))
|
||||||
.createItem();
|
.createItem();
|
||||||
memoryItems.add(mapsMemory);
|
memoryItems.add(mapsMemory);
|
||||||
|
|
||||||
|
@ -190,8 +193,8 @@ public class DataStorageHelper {
|
||||||
.setKey(TERRAIN_MEMORY)
|
.setKey(TERRAIN_MEMORY)
|
||||||
.setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|
.setExtensions(IndexConstants.BINARY_SRTM_MAP_INDEX_EXT)
|
||||||
.setDirectories(
|
.setDirectories(
|
||||||
createDirectory((SRTM_INDEX_DIR), true, EXTENSIONS, false),
|
createDirectory(SRTM_INDEX_DIR, true, EXTENSIONS, true),
|
||||||
createDirectory((TILES_INDEX_DIR), false, PREFIX, true))
|
createDirectory(TILES_INDEX_DIR, false, PREFIX, false))
|
||||||
.setPrefixes("Hillshade")
|
.setPrefixes("Hillshade")
|
||||||
.createItem();
|
.createItem();
|
||||||
memoryItems.add(terrainMemory);
|
memoryItems.add(terrainMemory);
|
||||||
|
@ -200,7 +203,7 @@ public class DataStorageHelper {
|
||||||
.setKey(TRACKS_MEMORY)
|
.setKey(TRACKS_MEMORY)
|
||||||
// .setExtensions(IndexConstants.GPX_FILE_EXT, ".gpx.bz2")
|
// .setExtensions(IndexConstants.GPX_FILE_EXT, ".gpx.bz2")
|
||||||
.setDirectories(
|
.setDirectories(
|
||||||
createDirectory((GPX_INDEX_DIR), true, EXTENSIONS, false))
|
createDirectory(GPX_INDEX_DIR, true, EXTENSIONS, true))
|
||||||
.createItem();
|
.createItem();
|
||||||
memoryItems.add(tracksMemory);
|
memoryItems.add(tracksMemory);
|
||||||
|
|
||||||
|
@ -208,7 +211,7 @@ public class DataStorageHelper {
|
||||||
.setKey(NOTES_MEMORY)
|
.setKey(NOTES_MEMORY)
|
||||||
// .setExtensions("")
|
// .setExtensions("")
|
||||||
.setDirectories(
|
.setDirectories(
|
||||||
createDirectory((AV_INDEX_DIR), true, EXTENSIONS, false))
|
createDirectory(AV_INDEX_DIR, true, EXTENSIONS, true))
|
||||||
.createItem();
|
.createItem();
|
||||||
memoryItems.add(notesMemory);
|
memoryItems.add(notesMemory);
|
||||||
|
|
||||||
|
@ -216,7 +219,7 @@ public class DataStorageHelper {
|
||||||
.setKey(TILES_MEMORY)
|
.setKey(TILES_MEMORY)
|
||||||
// .setExtensions("")
|
// .setExtensions("")
|
||||||
.setDirectories(
|
.setDirectories(
|
||||||
createDirectory((TILES_INDEX_DIR), true, EXTENSIONS, false))
|
createDirectory(TILES_INDEX_DIR, true, EXTENSIONS, true))
|
||||||
.createItem();
|
.createItem();
|
||||||
memoryItems.add(tilesMemory);
|
memoryItems.add(tilesMemory);
|
||||||
|
|
||||||
|
@ -264,9 +267,9 @@ public class DataStorageHelper {
|
||||||
return memoryItems;
|
return memoryItems;
|
||||||
}
|
}
|
||||||
|
|
||||||
public RefreshUsedMemoryTask calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter listener) {
|
public RefreshUsedMemoryTask calculateMemoryUsedInfo(UpdateMemoryInfoUIAdapter uiAdapter) {
|
||||||
File rootDir = new File(currentStoragePath);
|
File rootDir = new File(currentStoragePath);
|
||||||
RefreshUsedMemoryTask task = new RefreshUsedMemoryTask(listener, otherMemory, rootDir, null, null, OTHER_MEMORY);
|
RefreshUsedMemoryTask task = new RefreshUsedMemoryTask(uiAdapter, otherMemory, rootDir, null, null, OTHER_MEMORY);
|
||||||
task.execute(mapsMemory, terrainMemory, tracksMemory, notesMemory);
|
task.execute(mapsMemory, terrainMemory, tracksMemory, notesMemory);
|
||||||
return task;
|
return task;
|
||||||
}
|
}
|
||||||
|
@ -292,9 +295,9 @@ public class DataStorageHelper {
|
||||||
public DirectoryItem createDirectory(@NonNull String relativePath,
|
public DirectoryItem createDirectory(@NonNull String relativePath,
|
||||||
boolean processInternalDirectories,
|
boolean processInternalDirectories,
|
||||||
CheckingType checkingType,
|
CheckingType checkingType,
|
||||||
boolean skipUnmatchedInDirectory) {
|
boolean addUnmatchedToOtherMemory) {
|
||||||
String path = app.getAppPath(relativePath).getAbsolutePath();
|
String path = app.getAppPath(relativePath).getAbsolutePath();
|
||||||
return new DirectoryItem(path, processInternalDirectories, checkingType, skipUnmatchedInDirectory);
|
return new DirectoryItem(path, processInternalDirectories, checkingType, addUnmatchedToOtherMemory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getFormattedMemoryInfo(long bytes, String[] formatStrings) {
|
public static String getFormattedMemoryInfo(long bytes, String[] formatStrings) {
|
||||||
|
@ -312,7 +315,7 @@ public class DataStorageHelper {
|
||||||
|
|
||||||
void onMemoryInfoUpdate();
|
void onMemoryInfoUpdate();
|
||||||
|
|
||||||
void onFinishUpdating(String taskKey);
|
void onFinishUpdating(String tag);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,7 +5,7 @@ public class DirectoryItem {
|
||||||
private final String absolutePath;
|
private final String absolutePath;
|
||||||
private final boolean processInternalDirectories;
|
private final boolean processInternalDirectories;
|
||||||
private final CheckingType checkingType;
|
private final CheckingType checkingType;
|
||||||
private final boolean skipUnmatchedInDirectory;
|
private final boolean addUnmatchedToOtherMemory;
|
||||||
|
|
||||||
public enum CheckingType {
|
public enum CheckingType {
|
||||||
EXTENSIONS,
|
EXTENSIONS,
|
||||||
|
@ -15,11 +15,11 @@ public class DirectoryItem {
|
||||||
public DirectoryItem(String absolutePath,
|
public DirectoryItem(String absolutePath,
|
||||||
boolean processInternalDirectories,
|
boolean processInternalDirectories,
|
||||||
CheckingType checkingType,
|
CheckingType checkingType,
|
||||||
boolean skipUnmatchedInDirectory) {
|
boolean addUnmatchedToOtherMemory) {
|
||||||
this.absolutePath = absolutePath;
|
this.absolutePath = absolutePath;
|
||||||
this.processInternalDirectories = processInternalDirectories;
|
this.processInternalDirectories = processInternalDirectories;
|
||||||
this.checkingType = checkingType;
|
this.checkingType = checkingType;
|
||||||
this.skipUnmatchedInDirectory = skipUnmatchedInDirectory;
|
this.addUnmatchedToOtherMemory = addUnmatchedToOtherMemory;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAbsolutePath() {
|
public String getAbsolutePath() {
|
||||||
|
@ -34,7 +34,7 @@ public class DirectoryItem {
|
||||||
return checkingType;
|
return checkingType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldSkipUnmatchedInDirectory() {
|
public boolean shouldAddUnmatchedToOtherMemory() {
|
||||||
return skipUnmatchedInDirectory;
|
return addUnmatchedToOtherMemory;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,16 +97,16 @@ public class RefreshUsedMemoryTask extends AsyncTask<MemoryItem, Void, Void> {
|
||||||
@NonNull MemoryItem... items) {
|
@NonNull MemoryItem... items) {
|
||||||
String directoryPath = directory.getAbsolutePath();
|
String directoryPath = directory.getAbsolutePath();
|
||||||
for (MemoryItem memoryItem : items) {
|
for (MemoryItem memoryItem : items) {
|
||||||
DirectoryItem[] allowedDirectories = memoryItem.getDirectories();
|
DirectoryItem[] targetDirectories = memoryItem.getDirectories();
|
||||||
if (allowedDirectories != null) {
|
if (targetDirectories != null) {
|
||||||
for (DirectoryItem allowedDir : allowedDirectories) {
|
for (DirectoryItem targetDirectory : targetDirectories) {
|
||||||
String allowedDirPath = allowedDir.getAbsolutePath();
|
String allowedDirPath = targetDirectory.getAbsolutePath();
|
||||||
if (objectEquals(directoryPath, allowedDirPath)
|
if (objectEquals(directoryPath, allowedDirPath)
|
||||||
|| (directoryPath.startsWith(allowedDirPath))) {
|
|| (directoryPath.startsWith(allowedDirPath))) {
|
||||||
if (allowedDir.shouldProcessInternalDirectories()) {
|
if (targetDirectory.shouldProcessInternalDirectories()) {
|
||||||
calculateMultiTypes(directory, items);
|
calculateMultiTypes(directory, items);
|
||||||
return;
|
return;
|
||||||
} else if (allowedDir.shouldSkipUnmatchedInDirectory()) {
|
} else if (!targetDirectory.shouldAddUnmatchedToOtherMemory()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -121,16 +121,16 @@ public class RefreshUsedMemoryTask extends AsyncTask<MemoryItem, Void, Void> {
|
||||||
@NonNull File file,
|
@NonNull File file,
|
||||||
@NonNull MemoryItem... items) {
|
@NonNull MemoryItem... items) {
|
||||||
for (MemoryItem item : items) {
|
for (MemoryItem item : items) {
|
||||||
DirectoryItem[] allowedDirectories = item.getDirectories();
|
DirectoryItem[] targetDirectories = item.getDirectories();
|
||||||
if (allowedDirectories == null) continue;
|
if (targetDirectories == null) continue;
|
||||||
String rootDirPath = rootDir.getAbsolutePath();
|
String rootDirPath = rootDir.getAbsolutePath();
|
||||||
|
|
||||||
for (DirectoryItem allowedDir : allowedDirectories) {
|
for (DirectoryItem targetDirectory : targetDirectories) {
|
||||||
String allowedDirPath = allowedDir.getAbsolutePath();
|
String allowedDirPath = targetDirectory.getAbsolutePath();
|
||||||
boolean processInternal = allowedDir.shouldProcessInternalDirectories();
|
boolean processInternal = targetDirectory.shouldProcessInternalDirectories();
|
||||||
if (objectEquals(rootDirPath, allowedDirPath)
|
if (objectEquals(rootDirPath, allowedDirPath)
|
||||||
|| (rootDirPath.startsWith(allowedDirPath) && processInternal)) {
|
|| (rootDirPath.startsWith(allowedDirPath) && processInternal)) {
|
||||||
CheckingType checkingType = allowedDir.getCheckingType();
|
CheckingType checkingType = targetDirectory.getCheckingType();
|
||||||
switch (checkingType) {
|
switch (checkingType) {
|
||||||
case EXTENSIONS: {
|
case EXTENSIONS: {
|
||||||
if (isSuitableExtension(file, item)) {
|
if (isSuitableExtension(file, item)) {
|
||||||
|
@ -147,7 +147,7 @@ public class RefreshUsedMemoryTask extends AsyncTask<MemoryItem, Void, Void> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (allowedDir.shouldSkipUnmatchedInDirectory()) {
|
if (!targetDirectory.shouldAddUnmatchedToOtherMemory()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue