Fix doesn't edits sqlitedb sources after rename, disable rename in edit dialog.

This commit is contained in:
Dima-1 2020-02-13 13:16:37 +02:00
parent 71b3661bd3
commit 47cb54de41
2 changed files with 64 additions and 20 deletions

View file

@ -181,7 +181,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
builder.show();
}
private void basicFileOperation(final LocalIndexInfo info, ContextMenuAdapter adapter) {
ItemClickListener listener = new ItemClickListener() {
@Override
@ -226,7 +225,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
getDownloadActivity().reloadLocalIndexes();
}
});
} else if (resId == R.string.clear_tile_data) {
} else if (resId == R.string.clear_tile_data) {
AlertDialog.Builder confirm = new AlertDialog.Builder(getActivity());
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
@Override
@ -319,8 +318,16 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
@Override
public void onClick(View v) {
OsmandApplication app = (OsmandApplication) a.getApplication();
if (renameGpxFile(app, f, editText.getText().toString() + ext, false, callback) != null) {
alertDialog.dismiss();
if (ext.equals(SQLiteTileSource.EXT)) {
if (renameSQLiteFile(app, f, editText.getText().toString() + ext,
callback) != null) {
alertDialog.dismiss();
}
} else {
if (renameGpxFile(app, f, editText.getText().toString() + ext,
false, callback) != null) {
alertDialog.dismiss();
}
}
}
});
@ -330,7 +337,55 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
}
public static File renameGpxFile(OsmandApplication ctx, File source, String newName, boolean dirAllowed, RenameCallback callback) {
private static File renameSQLiteFile(OsmandApplication ctx, File source, String newName,
RenameCallback callback) {
File dest = checkRenamePossibility(ctx, source, newName, false);
if (dest == null) {
return null;
}
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
if (source.renameTo(dest)) {
final String[] suffixes = new String[]{"-journal", "-wal", "-shm"};
for (String s : suffixes) {
File file = new File(ctx.getDatabasePath(source + s).toString());
if (file.exists()) {
file.renameTo(ctx.getDatabasePath(dest + s));
}
}
if (callback != null) {
callback.renamedTo(dest);
}
return dest;
} else {
Toast.makeText(ctx, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
}
return null;
}
public static File renameGpxFile(OsmandApplication ctx, File source, String newName, boolean dirAllowed,
RenameCallback callback) {
File dest = checkRenamePossibility(ctx, source, newName, dirAllowed);
if (dest == null) {
return null;
}
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
if (source.renameTo(dest)) {
ctx.getGpxDbHelper().rename(source, dest);
if (callback != null) {
callback.renamedTo(dest);
}
return dest;
} else {
Toast.makeText(ctx, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
}
return null;
}
public static File checkRenamePossibility(OsmandApplication ctx, File source, String newName, boolean dirAllowed) {
if (Algorithms.isEmpty(newName)) {
Toast.makeText(ctx, R.string.empty_filename, Toast.LENGTH_LONG).show();
return null;
@ -343,21 +398,9 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
File dest = new File(source.getParentFile(), newName);
if (dest.exists()) {
Toast.makeText(ctx, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
} else {
if (!dest.getParentFile().exists()) {
dest.getParentFile().mkdirs();
}
if (source.renameTo(dest)) {
ctx.getGpxDbHelper().rename(source, dest);
if (callback != null) {
callback.renamedTo(dest);
}
return dest;
} else {
Toast.makeText(ctx, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
}
return null;
}
return null;
return dest;
}
@ -1227,7 +1270,6 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
}
});
}
item = optionsMenu.getMenu().add(R.string.shared_string_rename)
.setIcon(iconsCache.getThemedIcon(R.drawable.ic_action_edit_dark));
item.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {

View file

@ -493,6 +493,8 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
AlertDialog.Builder bld = new AlertDialog.Builder(new ContextThemeWrapper(activity, getThemeRes(activity, app)));
View view = UiUtilities.getInflater(activity, isNightMode(activity, app)).inflate(R.layout.editing_tile_source, null);
final EditText name = (EditText) view.findViewById(R.id.Name);
name.setFocusable(false);
name.setFocusableInTouchMode(false);
final Spinner existing = (Spinner) view.findViewById(R.id.TileSourceSpinner);
final TextView existingHint = (TextView) view.findViewById(R.id.TileSourceHint);
final EditText urlToLoad = (EditText) view.findViewById(R.id.URLToLoad);