Skip to content

Commit

Permalink
Merge pull request #17749 from osmandapp/fix_track_move
Browse files Browse the repository at this point in the history
Fix tracks move
  • Loading branch information
Chumva authored Jul 28, 2023
2 parents 306998d + 3adb2e1 commit b223e99
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 41 deletions.
16 changes: 8 additions & 8 deletions OsmAnd-java/src/main/java/net/osmand/util/Algorithms.java
Original file line number Diff line number Diff line change
Expand Up @@ -284,15 +284,15 @@ public static List<File> collectDirs(File parentDir, List<File> dirs) {
}

public static List<File> collectDirs(File parentDir, List<File> dirs, File exclDir) {
File[] listFiles = parentDir.listFiles();
if (listFiles != null) {
Arrays.sort(listFiles);
for (File f : listFiles) {
if (f.isDirectory()) {
if (!f.equals(exclDir)) {
dirs.add(f);
File[] files = parentDir.listFiles();
if (files != null) {
Arrays.sort(files);
for (File file : files) {
if (file.isDirectory()) {
if (!file.equals(exclDir)) {
dirs.add(file);
}
collectDirs(f, dirs);
collectDirs(file, dirs, exclDir);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ private void openTrackOptions(@NonNull FragmentActivity activity, @NonNull View
.setIcon(getContentIcon(R.drawable.ic_action_folder_stroke))
.setOnClickListener(v -> {
FragmentManager manager = activity.getSupportFragmentManager();
MoveGpxFileBottomSheet.showInstance(manager, file, this, false, false);
MoveGpxFileBottomSheet.showInstance(manager, file, file.getParentFile(), this, false, false);
})
.create());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ public void afterTextChanged(Editable s) {
FragmentActivity activity = getActivity();
if (activity != null) {
File dest = getFile(folderPath, destFileName);
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(),
dest, SaveAsNewTrackBottomSheetDialogFragment.this, usedOnMap, true);
FragmentManager manager = activity.getSupportFragmentManager();
MoveGpxFileBottomSheet.showInstance(manager, dest, null,
SaveAsNewTrackBottomSheetDialogFragment.this, usedOnMap, true);
}
});
BaseBottomSheetItem selectFolderItem = new BaseBottomSheetItem.Builder()
Expand Down
44 changes: 18 additions & 26 deletions OsmAnd/src/net/osmand/plus/myplaces/tracks/TrackFoldersHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public void showItemOptionsMenu(@NonNull TrackItem trackItem, @NonNull View view
.setIcon(getContentIcon(R.drawable.ic_action_folder_stroke))
.setOnClickListener(v -> {
FragmentManager manager = activity.getSupportFragmentManager();
MoveGpxFileBottomSheet.showInstance(manager, file, fragment, false, false);
MoveGpxFileBottomSheet.showInstance(manager, file, file.getParentFile(), fragment, false, false);
})
.create());

Expand Down Expand Up @@ -222,12 +222,13 @@ public void showItemOptionsMenu(@NonNull TrackItem trackItem, @NonNull View view
PopUpMenu.show(displayData);
}

public void showItemsOptionsMenu(@NonNull Set<TrackItem> trackItems, @NonNull Set<TracksGroup> tracksGroups,
@NonNull View view, @NonNull BaseTrackFolderFragment fragment) {
List<PopUpMenuItem> items = new ArrayList<>();
Set<TrackItem> selectedTrackItems = getSelectedTrackItems(trackItems, tracksGroups);
public void showItemsOptionsMenu(@NonNull View view, @NonNull TrackFolder trackFolder,
@NonNull Set<TrackItem> items, @NonNull Set<TracksGroup> groups,
@NonNull BaseTrackFolderFragment fragment) {
List<PopUpMenuItem> menuItems = new ArrayList<>();
Set<TrackItem> selectedTrackItems = getSelectedTrackItems(items, groups);

items.add(new PopUpMenuItem.Builder(app)
menuItems.add(new PopUpMenuItem.Builder(app)
.setTitleId(R.string.shared_string_show_on_map)
.setIcon(getContentIcon(R.drawable.ic_show_on_map))
.setOnClickListener(v -> {
Expand All @@ -236,7 +237,7 @@ public void showItemsOptionsMenu(@NonNull Set<TrackItem> trackItems, @NonNull Se
})
.create()
);
items.add(new PopUpMenuItem.Builder(app)
menuItems.add(new PopUpMenuItem.Builder(app)
.setTitleId(R.string.shared_string_share)
.setIcon(getContentIcon(R.drawable.ic_action_gshare_dark))
.setOnClickListener(v -> {
Expand All @@ -245,35 +246,26 @@ public void showItemsOptionsMenu(@NonNull Set<TrackItem> trackItems, @NonNull Se
})
.create()
);
PluginsHelper.onOptionsMenuActivity(activity, fragment, selectedTrackItems, items);
PluginsHelper.onOptionsMenuActivity(activity, fragment, selectedTrackItems, menuItems);

String move = app.getString(R.string.shared_string_move);
items.add(new PopUpMenuItem.Builder(app)
menuItems.add(new PopUpMenuItem.Builder(app)
.setTitle(move)
.setIcon(getContentIcon(R.drawable.ic_action_folder_move))
.setOnClickListener(v -> {
if (trackItems.isEmpty() && tracksGroups.isEmpty()) {
if (items.isEmpty() && groups.isEmpty()) {
showEmptyItemsToast(move);
} else {
File srcFile = null;
if (!Algorithms.isEmpty(trackItems)) {
srcFile = trackItems.iterator().next().getFile();
}
if (srcFile == null && !Algorithms.isEmpty(tracksGroups)) {
TracksGroup group = tracksGroups.iterator().next();
if (group instanceof TrackFolder) {
srcFile = ((TrackFolder) group).getDirFile();
}
}
File excludedDir = trackFolder.getDirFile();
FragmentManager manager = activity.getSupportFragmentManager();
MoveGpxFileBottomSheet.showInstance(manager, srcFile, fragment, false, false);
MoveGpxFileBottomSheet.showInstance(manager, null, excludedDir, fragment, false, false);
}
})
.showTopDivider(true)
.create()
);
String changeAppearance = app.getString(R.string.change_appearance);
items.add(new PopUpMenuItem.Builder(app)
menuItems.add(new PopUpMenuItem.Builder(app)
.setTitle(changeAppearance)
.setIcon(getContentIcon(R.drawable.ic_action_appearance))
.setOnClickListener(v -> {
Expand All @@ -286,14 +278,14 @@ public void showItemsOptionsMenu(@NonNull Set<TrackItem> trackItems, @NonNull Se
.create()
);
String delete = app.getString(R.string.shared_string_delete);
items.add(new PopUpMenuItem.Builder(app)
menuItems.add(new PopUpMenuItem.Builder(app)
.setTitle(delete)
.setIcon(getContentIcon(R.drawable.ic_action_delete_outlined))
.setOnClickListener(v -> {
if (trackItems.isEmpty() && tracksGroups.isEmpty()) {
if (items.isEmpty() && groups.isEmpty()) {
showEmptyItemsToast(delete);
} else {
showDeleteConfirmationDialog(trackItems, tracksGroups, fragment);
showDeleteConfirmationDialog(items, groups, fragment);
}
})
.showTopDivider(true)
Expand All @@ -302,7 +294,7 @@ public void showItemsOptionsMenu(@NonNull Set<TrackItem> trackItems, @NonNull Se

PopUpMenuDisplayData displayData = new PopUpMenuDisplayData();
displayData.anchorView = view;
displayData.menuItems = items;
displayData.menuItems = menuItems;
displayData.nightMode = fragment.isNightMode();
PopUpMenu.show(displayData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem

private static final String TAG = MoveGpxFileBottomSheet.class.getSimpleName();
private static final String SRC_FILE_KEY = "file_path_key";
private static final String EXCLUDED_DIR_KEY = "excluded_dir_key";
private static final String SHOW_ALL_FOLDERS_KEY = "show_all_folders_key";

private OsmandApplication app;
@Nullable
private File srcFile;
@Nullable
private File excludedDir;
private boolean showAllFolders;

@Override
Expand All @@ -50,6 +53,9 @@ public void onCreate(Bundle savedInstanceState) {
if (savedInstanceState.containsKey(SRC_FILE_KEY)) {
srcFile = AndroidUtils.getSerializable(savedInstanceState, SRC_FILE_KEY, File.class);
}
if (savedInstanceState.containsKey(EXCLUDED_DIR_KEY)) {
excludedDir = AndroidUtils.getSerializable(savedInstanceState, EXCLUDED_DIR_KEY, File.class);
}
showAllFolders = savedInstanceState.getBoolean(SHOW_ALL_FOLDERS_KEY);
}
}
Expand Down Expand Up @@ -89,7 +95,7 @@ public void createMenuItems(Bundle savedInstanceState) {
File rootDir = app.getAppPath(GPX_INDEX_DIR);
File fileDir = srcFile != null ? srcFile.getParentFile() : null;

collectDirs(rootDir, dirs, showAllFolders ? null : fileDir);
collectDirs(rootDir, dirs, excludedDir);
if (showAllFolders || !Algorithms.objectEquals(fileDir, rootDir)) {
dirs.add(0, rootDir);
}
Expand Down Expand Up @@ -132,6 +138,9 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
if (srcFile != null) {
outState.putSerializable(SRC_FILE_KEY, srcFile);
}
if (excludedDir != null) {
outState.putSerializable(EXCLUDED_DIR_KEY, excludedDir);
}
outState.putBoolean(SHOW_ALL_FOLDERS_KEY, showAllFolders);
}

Expand Down Expand Up @@ -164,10 +173,12 @@ public List<File> collectFiles(File parentDir) {
}

public static void showInstance(@NonNull FragmentManager manager, @Nullable File srcFile,
@Nullable Fragment target, boolean usedOnMap, boolean showAllFolders) {
@Nullable File excludedDir, @Nullable Fragment target,
boolean usedOnMap, boolean showAllFolders) {
if (AndroidUtils.isFragmentCanBeAdded(manager, TAG)) {
MoveGpxFileBottomSheet fragment = new MoveGpxFileBottomSheet();
fragment.srcFile = srcFile;
fragment.excludedDir = excludedDir;
fragment.showAllFolders = showAllFolders;
fragment.setUsedOnMap(usedOnMap);
fragment.setTargetFragment(target, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private void setupMenuButton(@NonNull LayoutInflater inflater, @NonNull ViewGrou
if (foldersHelper != null) {
Set<TrackItem> trackItems = itemsSelectionHelper.getSelectedItems();
Set<TracksGroup> tracksGroups = groupsSelectionHelper.getSelectedItems();
foldersHelper.showItemsOptionsMenu(trackItems, tracksGroups, v, this);
foldersHelper.showItemsOptionsMenu(v, rootFolder, trackItems, tracksGroups, this);
}
});
button.setContentDescription(getString(R.string.shared_string_more));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,8 @@ public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
} else if (buttonIndex == RENAME_BUTTON_INDEX) {
FileUtils.renameFile(mapActivity, new File(gpxFile.path), this, true);
} else if (buttonIndex == CHANGE_FOLDER_BUTTON_INDEX) {
MoveGpxFileBottomSheet.showInstance(fragmentManager, new File(gpxFile.path), this, true, false);
File file = new File(gpxFile.path);
MoveGpxFileBottomSheet.showInstance(fragmentManager, file, file.getParentFile(), this, true, false);
} else if (buttonIndex == GPS_FILTER_BUTTON_INDEX) {
GpsFilterFragment.showInstance(fragmentManager, selectedGpxFile, this);
} else if (buttonIndex == ALTITUDE_CORRECTION_BUTTON_INDEX) {
Expand Down

0 comments on commit b223e99

Please sign in to comment.