-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve sorting functionality of Track folders / Tracks #21310
base: r4.9
Are you sure you want to change the base?
Conversation
# Conflicts: # OsmAnd/src/net/osmand/plus/myplaces/tracks/dialogs/BaseTrackFolderFragment.java
@@ -4,6 +4,7 @@ import net.osmand.shared.gpx.filters.TrackFolderAnalysis | |||
|
|||
interface ComparableTracksGroup { | |||
fun getFolderAnalysis(): TrackFolderAnalysis | |||
fun getDirName(): String | |||
fun getDirName(useExtendedName: Boolean): String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useExtendedName > includingSubdirs
@@ -33,15 +35,22 @@ public class TracksComparator implements Comparator<Object> { | |||
public final TrackTab trackTab; | |||
public final TracksSortMode sortMode; | |||
public final Collator collator = OsmAndCollator.primaryCollator(); | |||
private boolean useExtendedName = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
useExtendedName > useSubdirs
return name; | ||
} | ||
|
||
@NonNull | ||
public static String getExtendedFolderName(@NonNull File directory, @NonNull String initialName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getFolderPath
Changes implemented after the Last Review
|
@alex-osm There's also an issue I noticed but haven't fixed yet. The If the logic for reading subfolders from the database is fixed so that they are also stored in the |
putUpgradedKey(upgradedCache, TrackTabType.ON_MAP.name()); | ||
putUpgradedKey(upgradedCache, TrackTabType.ALL.name()); | ||
putUpgradedKey(upgradedCache, TrackTabType.FOLDERS.name()); | ||
List<GpxDirItem> gpxDirs = gpxDbHelper.getDirItems(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We use GpxDirItem-s here in request
Summary of Changes and Future Considerations
1. Unified Interfaces
Implemented shared interfaces TracksGroup and ComparableTracksGroup for:
TrackTab
,TracksFolder
,SmartFolder
.Added a
getId()
method to TracksGroup, returning:TrackFolder
: Relative path (e.g., "A/B/C" for "tracks/A/B/C"). Relative path doesn't include global tracks root folder ("tracks" in Adnroid, "GPX" in iOS).SmartFolder
: Prefixed name, e.g., for "test" folder name, id is "SMART_FOLDER___test". The prefixe "SMART_FOLDERS___" is used to determine whether a given id belongs to a smart folder or not.TrackTab
: Replaces previously implemented method getTypeName() on getId() to return folder/smart folder ID or type name (ON_MAP
,ALL
,FOLDERS
).2. Enhanced TrackFolder Functionality
getRootFolder()
returns root folder ("tracks" for Android, "GPX" for iOS).Updated
getDirName()
to support an extended name format (useExtendedName
parameter):TrackFolder
: Returns relative path.SmartFolder
: Unaffected by parameter.TrackTab
: Includes parent folder if not root.3. Optimized PreselectedTabParams
Replaced name with id field and removed redundant code for parsing
SmartFolder
IDs.4. Refactored TrackTabsHelper
Created
SelectTrackTabsHelper
subclass for logic specific toSelectTrackTabsFragment
.5. TrackFolder ID Methodology
Replaced usage of folder name as ID with the getId() method that will return a relative path to the folder from the root folder ("tracks" for Android, "GPX" for "iOS"). Also fixed relative path retrieving to always exclude root folder name. It meens that previously for root folder
getRelativePath()
returned a string "tracks". Now it returns an empty string "". It was implemented because of different names of root tracks forlder for Android and iOS for implementing consistency between these platforms.6. TrackSortModesCollection Wrapper
Implemented a new class
TrackSortModesCollection
. It centralized sort mode management:askUpgradeCachedKeys
during runtime. We try to update the keys each time we requestTrackSortModesCollection
fromOsmandSettings
. To ensure the keys are updated correctly, access to allTrackFolders
is required. This means that at the time of the update, all track folders must be loaded usingTrackFolderLoaderTask
. The key upgrade to the new version occurs only once per application session. This is done to avoid redundant operations, as all cached keys are updated during the first run, and new keys are immediately added in the form of a relative path.7. Improved TrackTab sorting functionality
TrackFolderAnalysis
. Currently without recalculating on tracks changes, such as moving track to another folder or remove it.8. Sorting Logic depends on context
Sorting is applied differently depending on the context:
My Places
→Tracks
screenConfigure Map
→Tracks
(tabs and bottom sheet)ON_MAP
andALL
), followed by sorted smart folders and regular folders.To account for tab type during sorting, the
ComparableTracksGroup
class introduces thegetDefaultOrder()
method:TrackTab
and returns the index of the tab type viaTrackTabType.ordinal()
.Suggestions for iOS
Unifying sort modes handling across Android and iOS
To ensure better compatibility between Android and iOS, consider implementing functionality similar to
TrackSortModesCollection
. While it doesn’t have to be an identical bundle, the following should be ensured:folder name
tofolder path
as implemented in methodaskUpgradeKeysWithSync
.This will help maintain consistency across Android and iOS implementations, improving support for shared features.
Updating the getRelativePath method for TrackFolder
The getRelativePath method in
TrackFolder
has been modified to no longer return "GPX" as the relative path for the root folder. This change ensures key consistency between Android and iOS.However, on iOS, it is necessary to verify whether this update disrupts existing logic. Other settings might have used the path as a key, and if so, they should be adjusted accordingly.
Replacing getRelativePath with getId
It is recommended to replace all calls to
getRelativePath()
withgetId()
forTrackFolder
. Although both methods currently return the same value, using getId explicitly makes the code clearer and better reflects its purpose.