Skip to content

Commit

Permalink
Never display root folder name in tracks folder's relative path and id
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-kutz committed Nov 22, 2024
1 parent dae43cb commit 1dbe52d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
lastModified = folder.lastModified
}

override fun getId() = getRelativePath(true)
override fun getId() = relativePath

override fun getName(): String {
return GpxHelper.getFolderName(dirFile, false)
Expand All @@ -51,7 +51,15 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
}

val relativePath: String
get() = getRelativePath(false)
get() =
if (!isRootFolder) {
val dirName = dirFile.name()
val parent = getParentFolder()
if (parent?.isRootFolder == false) parent.relativePath + "/" + dirName else dirName
} else {
""
}


val isRootFolder: Boolean
get() = getParentFolder() == null
Expand Down Expand Up @@ -147,13 +155,6 @@ class TrackFolder(dirFile: KFile, parentFolder: TrackFolder?) :
return if (useExtendedName) relativePath else dirFile.name()
}

private fun getRelativePath(includeRootFolder: Boolean): String {
val dirName = dirFile.name()
val parent = getParentFolder()
val includeParent = parent != null && (!parent.isRootFolder || includeRootFolder)
return if (includeParent) parent!!.getRelativePath(includeRootFolder) + "/" + dirName else dirName
}

fun getLastModified(): Long {
if (lastModified < 0) {
lastModified = dirFile.lastModified()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public TrackSortModesCollection(@NonNull OsmandSettings settings) {

@NonNull
public TracksSortMode getRootSortMode() {
return requireSortMode(ROOT_FOLDER);
return requireSortMode("");
}

@NonNull
Expand All @@ -50,11 +50,9 @@ public TracksSortMode requireSortMode(@Nullable String id) {
public TracksSortMode getSortMode(@Nullable String id) {
id = removeExtraFileSeparator(id);
TracksSortMode sortMode = cachedSortModes.get(id);
if (sortMode == null && id != null && isFolderIdV2(id)) {
if (sortMode == null) {
String idV1 = getFolderIdV1(id);
if (idV1 != null) {
sortMode = cachedSortModes.get(idV1);
}
return idV1 != null ? cachedSortModes.get(idV1) : null;
}
return sortMode;
}
Expand Down Expand Up @@ -148,17 +146,19 @@ private void saveToPreference() {
@NonNull
public static String getFolderId(@NonNull String absolutePath) {
int index = absolutePath.indexOf(ROOT_FOLDER);
if (index > 0) {
index += ROOT_FOLDER.length();
}
return index > 0 ? absolutePath.substring(index) : absolutePath;
}

private static boolean isFolderIdV2(@NonNull String id) {
return id.startsWith(ROOT_FOLDER);
}

@Nullable
private static String getFolderIdV1(@NonNull String idV2) {
int index = idV2.lastIndexOf(File.separator);
return index > 0 ? idV2.substring(index + 1) : null;
private static String getFolderIdV1(@Nullable String id) {
if (id != null && id.isEmpty()) {
return removeExtraFileSeparator(ROOT_FOLDER);
}
int index = id != null ? id.lastIndexOf(File.separator) : -1;
return index > 0 ? id.substring(index + 1) : null;
}

@Nullable
Expand Down

0 comments on commit 1dbe52d

Please sign in to comment.