This commit is contained in:
max-klaus 2019-11-26 17:57:54 +03:00
parent f275536131
commit 13f1924027
2 changed files with 13 additions and 8 deletions

View file

@ -77,7 +77,8 @@ import android.widget.Toast;
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents { public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents {
public static final Pattern ILLEGAL_FILE_NAME_CHARACTERS = Pattern.compile("[?:\"*|/\\<>]"); public static final Pattern ILLEGAL_FILE_NAME_CHARACTERS = Pattern.compile("[?:\"*|/<>]");
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
private LoadLocalIndexTask asyncLoader; private LoadLocalIndexTask asyncLoader;
private Map<String, IndexItem> filesToUpdate = new HashMap<>(); private Map<String, IndexItem> filesToUpdate = new HashMap<>();
@ -301,7 +302,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
@Override @Override
public void onClick(View v) { public void onClick(View v) {
OsmandApplication app = (OsmandApplication) a.getApplication(); OsmandApplication app = (OsmandApplication) a.getApplication();
if (renameGpxFile(app, f, editText.getText().toString() + ext, callback) != null) { if (renameGpxFile(app, f, editText.getText().toString() + ext, false, callback) != null) {
alertDialog.dismiss(); alertDialog.dismiss();
} }
} }
@ -312,12 +313,13 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
} }
} }
public static File renameGpxFile(OsmandApplication ctx, File source, String newName, RenameCallback callback) { public static File renameGpxFile(OsmandApplication ctx, File source, String newName, boolean dirAllowed, RenameCallback callback) {
if (Algorithms.isEmpty(newName)) { if (Algorithms.isEmpty(newName)) {
Toast.makeText(ctx, R.string.empty_filename, Toast.LENGTH_LONG).show(); Toast.makeText(ctx, R.string.empty_filename, Toast.LENGTH_LONG).show();
return null; return null;
} }
if (ILLEGAL_FILE_NAME_CHARACTERS.matcher(newName).find()) { Pattern illegalCharactersPattern = dirAllowed ? ILLEGAL_PATH_NAME_CHARACTERS : ILLEGAL_FILE_NAME_CHARACTERS;
if (illegalCharactersPattern.matcher(newName).find()) {
Toast.makeText(ctx, R.string.file_name_containes_illegal_char, Toast.LENGTH_LONG).show(); Toast.makeText(ctx, R.string.file_name_containes_illegal_char, Toast.LENGTH_LONG).show();
return null; return null;
} }

View file

@ -52,6 +52,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
private boolean showOnMap = true; private boolean showOnMap = true;
private boolean openTrack = false; private boolean openTrack = false;
private File file; private File file;
private String savedGpxDir = "";
private String savedGpxName = ""; private String savedGpxName = "";
private String newGpxName = ""; private String newGpxName = "";
@ -63,8 +64,10 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
if (args != null && args.containsKey(SAVED_TRACKS_KEY)) { if (args != null && args.containsKey(SAVED_TRACKS_KEY)) {
ArrayList<String> savedGpxNames = args.getStringArrayList(SAVED_TRACKS_KEY); ArrayList<String> savedGpxNames = args.getStringArrayList(SAVED_TRACKS_KEY);
if (savedGpxNames != null && savedGpxNames.size() > 0) { if (savedGpxNames != null && savedGpxNames.size() > 0) {
savedGpxName = savedGpxNames.get(savedGpxNames.size() - 1); String fileName = savedGpxNames.get(savedGpxNames.size() - 1);
newGpxName = savedGpxName; savedGpxDir = new File(fileName).getParent();
savedGpxName = new File(fileName).getName();
newGpxName = this.savedGpxName;
} }
} else { } else {
dismiss(); dismiss();
@ -168,7 +171,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
private File renameGpxFile() { private File renameGpxFile() {
OsmandApplication app = requiredMyApplication(); OsmandApplication app = requiredMyApplication();
File savedFile = new File(app.getAppCustomization().getTracksDir(), savedGpxName + ".gpx"); File savedFile = new File(app.getAppCustomization().getTracksDir(), new File(savedGpxDir, savedGpxName + ".gpx").getPath());
if (savedGpxName.equalsIgnoreCase(newGpxName)) { if (savedGpxName.equalsIgnoreCase(newGpxName)) {
return savedFile; return savedFile;
} }
@ -176,7 +179,7 @@ public class OnSaveCurrentTrackFragment extends BottomSheetDialogFragment {
Toast.makeText(app, R.string.empty_filename, Toast.LENGTH_LONG).show(); Toast.makeText(app, R.string.empty_filename, Toast.LENGTH_LONG).show();
return null; return null;
} }
return LocalIndexesFragment.renameGpxFile(app, savedFile, newGpxName + ".gpx", null); return LocalIndexesFragment.renameGpxFile(app, savedFile, newGpxName + ".gpx", true, null);
} }
private void showOnMap(File f, boolean animated) { private void showOnMap(File f, boolean animated) {