Skip to content

Commit

Permalink
Upgrade sort modes collection keys in the proper places
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-kutz committed Nov 20, 2024
1 parent d455627 commit de5e683
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

public class TrackSortModesCollection {

private static final String ROOT_FOLDER = IndexConstants.GPX_INDEX_DIR;
private static final String SEPARATOR = ",,";

private final Map<String, TracksSortMode> cachedSortModes = new HashMap<>();
private final Map<String, TracksSortMode> cachedSortModes = new ConcurrentHashMap<>();
private final ListStringPreference preference;

public TrackSortModesCollection(@NonNull OsmandSettings settings) {
Expand Down Expand Up @@ -103,8 +104,8 @@ private void putUpgradedKey(@NonNull Map<String, TracksSortMode> map, @NonNull S
}
}

public void updateMovedTrackFolder(@NonNull OsmandApplication app,
@NonNull TrackFolder trackFolder, @NonNull File oldDir) {
public void updateAfterMoveTrackFolder(@NonNull OsmandApplication app,
@NonNull TrackFolder trackFolder, @NonNull File oldDir) {
String previousId = getFolderId(oldDir.getAbsolutePath());
TracksSortMode sortMode = getSortMode(previousId);
if (sortMode != null) {
Expand All @@ -113,6 +114,12 @@ public void updateMovedTrackFolder(@NonNull OsmandApplication app,
}
}

public void updateAfterDeleteTrackFolder(@NonNull OsmandApplication app,
@NonNull TrackFolder trackFolder) {
cachedSortModes.remove(trackFolder.getId());
askSyncWithUpgrade(app, trackFolder, true);
}

public void syncSettings() {
saveToPreference();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ private void showDeleteDialog() {

@Override
public void onFolderDeleted() {
FileUtils.updateAfterDeleteTrackFolder(app, trackFolder);

// Close options dialog after folder deleted
dialogManager.askDismissDialog(PROCESS_ID);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,10 +363,6 @@ private void sortFolders(@NonNull TrackFolder trackFolder, @NonNull TrackSortMod
}
}

private void removeSurplusSortModes() {
settings.getTrackSortModes().askSyncWithUpgrade(app, rootFolder);
}

@Override
public void importTracks() {
Intent intent = ImportHelper.getImportFileIntent();
Expand Down Expand Up @@ -478,13 +474,11 @@ public ScreenPositionData getFirstSuitableItemScreenPosition() {
@Override
public void onFolderRenamed(@NonNull File newDir) {
updateContent();
removeSurplusSortModes();
}

@Override
public void onFolderDeleted() {
reloadTracks();
removeSurplusSortModes();
}

@Override
Expand Down
8 changes: 5 additions & 3 deletions OsmAnd/src/net/osmand/plus/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,11 @@ public static void updateMovedTrackFolder(@NonNull OsmandApplication app, @NonNu
}
updateMovedGpxFiles(app, files, srcDir, destDir);

OsmandSettings settings = app.getSettings();
TrackSortModesCollection sortModes = settings.getTrackSortModes();
sortModes.updateMovedTrackFolder(app, trackFolder, srcDir);
app.getSettings().getTrackSortModes().updateAfterMoveTrackFolder(app, trackFolder, srcDir);
}

public static void updateAfterDeleteTrackFolder(@NonNull OsmandApplication app, @NonNull TrackFolder trackFolder) {
app.getSettings().getTrackSortModes().updateAfterDeleteTrackFolder(app, trackFolder);
}

private static void updateMovedGpxFiles(@NonNull OsmandApplication app, @NonNull List<File> files,
Expand Down

0 comments on commit de5e683

Please sign in to comment.