commit
019dffac0e
7 changed files with 332 additions and 124 deletions
|
@ -1,27 +1,24 @@
|
||||||
package net.osmand;
|
package net.osmand;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.appcompat.app.AlertDialog;
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
|
import net.osmand.GPXUtilities.Metadata;
|
||||||
import net.osmand.plus.GpxSelectionHelper;
|
import net.osmand.plus.GpxSelectionHelper;
|
||||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.SQLiteTileSource;
|
import net.osmand.plus.dialogs.RenameFileBottomSheet;
|
||||||
import net.osmand.util.Algorithms;
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.ref.WeakReference;
|
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class FileUtils {
|
public class FileUtils {
|
||||||
|
@ -29,70 +26,11 @@ public class FileUtils {
|
||||||
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("[?:\"*|<>]");
|
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
|
||||||
|
|
||||||
public static void renameFile(Activity a, final File f, final RenameCallback callback) {
|
public static void renameFile(@NonNull FragmentActivity activity, @NonNull File file,
|
||||||
final WeakReference<Activity> weakActivity = new WeakReference<>(a);
|
@Nullable Fragment target, boolean usedOnMap) {
|
||||||
AlertDialog.Builder b = new AlertDialog.Builder(a);
|
if (file.exists()) {
|
||||||
if (f.exists()) {
|
FragmentManager fragmentManager = activity.getSupportFragmentManager();
|
||||||
int xt = f.getName().lastIndexOf('.');
|
RenameFileBottomSheet.showInstance(fragmentManager, target, file, usedOnMap);
|
||||||
final String ext = xt == -1 ? "" : f.getName().substring(xt);
|
|
||||||
final String originalName = xt == -1 ? f.getName() : f.getName().substring(0, xt);
|
|
||||||
final EditText editText = new EditText(a);
|
|
||||||
editText.setText(originalName);
|
|
||||||
editText.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s) {
|
|
||||||
Editable text = editText.getText();
|
|
||||||
if (text.length() >= 1) {
|
|
||||||
Activity activity = weakActivity.get();
|
|
||||||
if (ILLEGAL_FILE_NAME_CHARACTERS.matcher(text).find() && activity != null) {
|
|
||||||
editText.setError(activity.getString(R.string.file_name_containes_illegal_char));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
b.setTitle(R.string.shared_string_rename);
|
|
||||||
int leftPadding = AndroidUtils.dpToPx(a, 24f);
|
|
||||||
int topPadding = AndroidUtils.dpToPx(a, 4f);
|
|
||||||
b.setView(editText, leftPadding, topPadding, leftPadding, topPadding);
|
|
||||||
// Behaviour will be overwritten later;
|
|
||||||
b.setPositiveButton(R.string.shared_string_save, null);
|
|
||||||
b.setNegativeButton(R.string.shared_string_cancel, null);
|
|
||||||
final AlertDialog alertDialog = b.create();
|
|
||||||
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
|
||||||
@Override
|
|
||||||
public void onShow(DialogInterface dialog) {
|
|
||||||
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(
|
|
||||||
new View.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
Activity activity = weakActivity.get();
|
|
||||||
if (activity != null) {
|
|
||||||
OsmandApplication app = (OsmandApplication) activity.getApplication();
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alertDialog.show();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -106,7 +44,7 @@ public class FileUtils {
|
||||||
dest.getParentFile().mkdirs();
|
dest.getParentFile().mkdirs();
|
||||||
}
|
}
|
||||||
if (source.renameTo(dest)) {
|
if (source.renameTo(dest)) {
|
||||||
final String[] suffixes = new String[]{"-journal", "-wal", "-shm"};
|
final String[] suffixes = new String[] {"-journal", "-wal", "-shm"};
|
||||||
for (String s : suffixes) {
|
for (String s : suffixes) {
|
||||||
File file = new File(ctx.getDatabasePath(source + s).toString());
|
File file = new File(ctx.getDatabasePath(source + s).toString());
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
|
@ -140,6 +78,26 @@ public class FileUtils {
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static File renameFile(@NonNull OsmandApplication app, @NonNull File source,
|
||||||
|
@NonNull String newName, boolean dirAllowed, RenameCallback callback) {
|
||||||
|
File dest = checkRenamePossibility(app, source, newName, dirAllowed);
|
||||||
|
if (dest == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!dest.getParentFile().exists()) {
|
||||||
|
dest.getParentFile().mkdirs();
|
||||||
|
}
|
||||||
|
File res = source.renameTo(dest) ? dest : null;
|
||||||
|
if (res != null) {
|
||||||
|
if (callback != null) {
|
||||||
|
callback.renamedTo(res);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Toast.makeText(app, R.string.file_can_not_be_renamed, Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
public static File renameGpxFile(@NonNull OsmandApplication app, @NonNull File src, @NonNull File dest) {
|
public static File renameGpxFile(@NonNull OsmandApplication app, @NonNull File src, @NonNull File dest) {
|
||||||
if (!dest.getParentFile().exists()) {
|
if (!dest.getParentFile().exists()) {
|
||||||
dest.getParentFile().mkdirs();
|
dest.getParentFile().mkdirs();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.PersistableBundle;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
@ -45,6 +46,7 @@ import net.osmand.plus.settings.backend.OsmAndAppCustomization;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.track.TrackDisplayHelper;
|
import net.osmand.plus.track.TrackDisplayHelper;
|
||||||
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
|
@ -83,10 +85,35 @@ public class TrackActivity extends TabActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
displayHelper = new TrackDisplayHelper(app);
|
displayHelper = new TrackDisplayHelper(app);
|
||||||
if (intent.hasExtra(TRACK_FILE_NAME)) {
|
if (savedInstanceState != null) {
|
||||||
|
String path = savedInstanceState.getString(TRACK_FILE_NAME);
|
||||||
|
if (!Algorithms.isEmpty(path)) {
|
||||||
|
displayHelper.setFile(new File(path));
|
||||||
|
}
|
||||||
|
} else if (intent.hasExtra(TRACK_FILE_NAME)) {
|
||||||
displayHelper.setFile(new File(intent.getStringExtra(TRACK_FILE_NAME)));
|
displayHelper.setFile(new File(intent.getStringExtra(TRACK_FILE_NAME)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setupActionBar();
|
||||||
|
if (intent.hasExtra(OPEN_POINTS_TAB)
|
||||||
|
|| (savedInstanceState != null && savedInstanceState.getBoolean(OPEN_POINTS_TAB, false))) {
|
||||||
|
openPointsTab = true;
|
||||||
|
}
|
||||||
|
if (intent.hasExtra(OPEN_TRACKS_LIST)) {
|
||||||
|
openTracksList = true;
|
||||||
|
}
|
||||||
|
setContentView(R.layout.track_content);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(@NonNull Bundle outState, @NonNull PersistableBundle outPersistentState) {
|
||||||
|
File file = getFile();
|
||||||
|
outState.putString(TRACK_FILE_NAME, file != null ? file.getAbsolutePath() : null);
|
||||||
|
outState.putBoolean(CURRENT_RECORDING, file == null);
|
||||||
|
super.onSaveInstanceState(outState, outPersistentState);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setupActionBar() {
|
||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
if (getFile() != null) {
|
if (getFile() != null) {
|
||||||
|
@ -97,14 +124,6 @@ public class TrackActivity extends TabActivity {
|
||||||
}
|
}
|
||||||
actionBar.setElevation(AndroidUtils.dpToPx(app, 4f));
|
actionBar.setElevation(AndroidUtils.dpToPx(app, 4f));
|
||||||
}
|
}
|
||||||
if (intent.hasExtra(OPEN_POINTS_TAB)
|
|
||||||
|| (savedInstanceState != null && savedInstanceState.getBoolean(OPEN_POINTS_TAB, false))) {
|
|
||||||
openPointsTab = true;
|
|
||||||
}
|
|
||||||
if (intent.hasExtra(OPEN_TRACKS_LIST)) {
|
|
||||||
openTracksList = true;
|
|
||||||
}
|
|
||||||
setContentView(R.layout.track_content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public TrackDisplayHelper getDisplayHelper() {
|
public TrackDisplayHelper getDisplayHelper() {
|
||||||
|
|
168
OsmAnd/src/net/osmand/plus/dialogs/RenameFileBottomSheet.java
Normal file
168
OsmAnd/src/net/osmand/plus/dialogs/RenameFileBottomSheet.java
Normal file
|
@ -0,0 +1,168 @@
|
||||||
|
package net.osmand.plus.dialogs;
|
||||||
|
|
||||||
|
import android.content.res.ColorStateList;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.Editable;
|
||||||
|
import android.text.TextWatcher;
|
||||||
|
import android.view.View;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.FileUtils.RenameCallback;
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.SQLiteTileSource;
|
||||||
|
import net.osmand.plus.UiUtilities;
|
||||||
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import static net.osmand.FileUtils.ILLEGAL_FILE_NAME_CHARACTERS;
|
||||||
|
import static net.osmand.FileUtils.renameFile;
|
||||||
|
import static net.osmand.FileUtils.renameGpxFile;
|
||||||
|
import static net.osmand.FileUtils.renameSQLiteFile;
|
||||||
|
|
||||||
|
public class RenameFileBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(RenameFileBottomSheet.class);
|
||||||
|
private static final String TAG = RenameFileBottomSheet.class.getName();
|
||||||
|
private static final String SOURCE_FILE_NAME_KEY = "source_file_name_key";
|
||||||
|
private static final String SELECTED_FILE_NAME_KEY = "selected_file_name_key";
|
||||||
|
|
||||||
|
private OsmandApplication app;
|
||||||
|
|
||||||
|
private TextInputEditText editText;
|
||||||
|
private TextInputLayout nameTextBox;
|
||||||
|
|
||||||
|
private File file;
|
||||||
|
private String selectedFileName;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
app = requiredMyApplication();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
String path = savedInstanceState.getString(SOURCE_FILE_NAME_KEY);
|
||||||
|
if (!Algorithms.isEmpty(path)) {
|
||||||
|
file = new File(path);
|
||||||
|
}
|
||||||
|
selectedFileName = savedInstanceState.getString(SELECTED_FILE_NAME_KEY);
|
||||||
|
}
|
||||||
|
items.add(new TitleItem(getString(R.string.shared_string_rename)));
|
||||||
|
|
||||||
|
View view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.track_name_edit_text, null);
|
||||||
|
nameTextBox = view.findViewById(R.id.name_text_box);
|
||||||
|
nameTextBox.setBoxBackgroundColorResource(nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light);
|
||||||
|
nameTextBox.setHint(AndroidUtils.addColon(app, R.string.shared_string_name));
|
||||||
|
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
|
||||||
|
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
|
||||||
|
nameTextBox.setDefaultHintTextColor(colorStateList);
|
||||||
|
|
||||||
|
editText = view.findViewById(R.id.name_edit_text);
|
||||||
|
editText.setText(selectedFileName != null ? selectedFileName : Algorithms.getFileNameWithoutExtension(file));
|
||||||
|
editText.addTextChangedListener(new TextWatcher() {
|
||||||
|
@Override
|
||||||
|
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s) {
|
||||||
|
updateFileName(s.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
BaseBottomSheetItem editFolderName = new BaseBottomSheetItem.Builder()
|
||||||
|
.setCustomView(view)
|
||||||
|
.create();
|
||||||
|
items.add(editFolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFileName(String name) {
|
||||||
|
if (!Algorithms.isEmpty(name) && ILLEGAL_FILE_NAME_CHARACTERS.matcher(name).find()) {
|
||||||
|
nameTextBox.setError(getString(R.string.file_name_containes_illegal_char));
|
||||||
|
} else {
|
||||||
|
selectedFileName = name;
|
||||||
|
nameTextBox.setError(null);
|
||||||
|
}
|
||||||
|
updateBottomButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isRightBottomButtonEnabled() {
|
||||||
|
return nameTextBox.getError() == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putString(SOURCE_FILE_NAME_KEY, file.getAbsolutePath());
|
||||||
|
outState.putString(SELECTED_FILE_NAME_KEY, selectedFileName);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRightBottomButtonClick() {
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
AndroidUtils.hideSoftKeyboard(activity, editText);
|
||||||
|
}
|
||||||
|
File dest;
|
||||||
|
int index = file.getName().lastIndexOf('.');
|
||||||
|
String ext = index == -1 ? "" : file.getName().substring(index);
|
||||||
|
if (SQLiteTileSource.EXT.equals(ext)) {
|
||||||
|
dest = renameSQLiteFile(app, file, selectedFileName + ext, null);
|
||||||
|
} else if (IndexConstants.GPX_FILE_EXT.equals(ext)) {
|
||||||
|
dest = renameGpxFile(app, file, selectedFileName + ext, false, null);
|
||||||
|
} else {
|
||||||
|
dest = renameFile(app, file, selectedFileName + ext, false, null);
|
||||||
|
}
|
||||||
|
if (dest != null) {
|
||||||
|
Fragment fragment = getTargetFragment();
|
||||||
|
if (fragment instanceof RenameCallback) {
|
||||||
|
RenameCallback listener = (RenameCallback) fragment;
|
||||||
|
listener.renamedTo(dest);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDismissButtonTextId() {
|
||||||
|
return R.string.shared_string_cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getRightBottomButtonTextId() {
|
||||||
|
return R.string.shared_string_save;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
|
||||||
|
@NonNull File file, boolean usedOnMap) {
|
||||||
|
if (file.exists() && !fragmentManager.isStateSaved()
|
||||||
|
&& fragmentManager.findFragmentByTag(RenameFileBottomSheet.TAG) == null) {
|
||||||
|
RenameFileBottomSheet fragment = new RenameFileBottomSheet();
|
||||||
|
fragment.file = file;
|
||||||
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
|
fragment.setTargetFragment(target, 0);
|
||||||
|
fragment.show(fragmentManager, RenameFileBottomSheet.TAG);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,7 @@ import androidx.appcompat.view.ActionMode;
|
||||||
import androidx.appcompat.widget.PopupMenu;
|
import androidx.appcompat.widget.PopupMenu;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.core.view.MenuItemCompat;
|
import androidx.core.view.MenuItemCompat;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
|
@ -74,7 +75,7 @@ import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents,
|
public class LocalIndexesFragment extends OsmandExpandableListFragment implements DownloadEvents,
|
||||||
OnMapSourceUpdateListener {
|
OnMapSourceUpdateListener, RenameCallback {
|
||||||
private LoadLocalIndexTask asyncLoader;
|
private LoadLocalIndexTask asyncLoader;
|
||||||
private Map<String, IndexItem> filesToUpdate = new HashMap<>();
|
private Map<String, IndexItem> filesToUpdate = new HashMap<>();
|
||||||
private LocalIndexesAdapter listAdapter;
|
private LocalIndexesAdapter listAdapter;
|
||||||
|
@ -141,13 +142,11 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
|
|
||||||
private boolean performBasicOperation(int resId, final LocalIndexInfo info) {
|
private boolean performBasicOperation(int resId, final LocalIndexInfo info) {
|
||||||
if (resId == R.string.shared_string_rename) {
|
if (resId == R.string.shared_string_rename) {
|
||||||
FileUtils.renameFile(getActivity(), new File(info.getPathToData()), new RenameCallback() {
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
@Override
|
File file = new File(info.getPathToData());
|
||||||
public void renamedTo(File file) {
|
FileUtils.renameFile(activity, file, this, false);
|
||||||
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());
|
AlertDialog.Builder confirm = new AlertDialog.Builder(getActivity());
|
||||||
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
confirm.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() {
|
||||||
|
@ -188,7 +187,19 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMapSourceUpdated() {
|
public void onMapSourceUpdated() {
|
||||||
getDownloadActivity().reloadLocalIndexes();
|
reloadLocalIndexes();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renamedTo(File file) {
|
||||||
|
reloadLocalIndexes();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void reloadLocalIndexes() {
|
||||||
|
DownloadActivity activity = getDownloadActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
activity.reloadLocalIndexes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LoadLocalIndexTask extends AsyncTask<Void, LocalIndexInfo, List<LocalIndexInfo>>
|
public class LoadLocalIndexTask extends AsyncTask<Void, LocalIndexInfo, List<LocalIndexInfo>>
|
||||||
|
@ -666,7 +677,7 @@ public class LocalIndexesFragment extends OsmandExpandableListFragment implement
|
||||||
|
|
||||||
public void localOptionsMenu(final int itemId) {
|
public void localOptionsMenu(final int itemId) {
|
||||||
if (itemId == R.string.shared_string_refresh) {
|
if (itemId == R.string.shared_string_refresh) {
|
||||||
getDownloadActivity().reloadLocalIndexes();
|
reloadLocalIndexes();
|
||||||
} else if (itemId == R.string.shared_string_delete) {
|
} else if (itemId == R.string.shared_string_delete) {
|
||||||
openSelectionMode(itemId, R.drawable.ic_action_delete_dark,
|
openSelectionMode(itemId, R.drawable.ic_action_delete_dark,
|
||||||
new DialogInterface.OnClickListener() {
|
new DialogInterface.OnClickListener() {
|
||||||
|
|
|
@ -42,6 +42,7 @@ import androidx.appcompat.app.AlertDialog;
|
||||||
import androidx.appcompat.view.ActionMode;
|
import androidx.appcompat.view.ActionMode;
|
||||||
import androidx.appcompat.widget.SearchView;
|
import androidx.appcompat.widget.SearchView;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
import net.osmand.Collator;
|
import net.osmand.Collator;
|
||||||
|
@ -84,8 +85,8 @@ import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||||
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
|
||||||
import net.osmand.plus.settings.backend.OsmandSettings;
|
import net.osmand.plus.settings.backend.OsmandSettings;
|
||||||
import net.osmand.plus.widgets.popup.PopUpMenuItem;
|
|
||||||
import net.osmand.plus.widgets.popup.PopUpMenuHelper;
|
import net.osmand.plus.widgets.popup.PopUpMenuHelper;
|
||||||
|
import net.osmand.plus.widgets.popup.PopUpMenuItem;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
|
@ -105,6 +106,7 @@ import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static net.osmand.plus.GpxSelectionHelper.CURRENT_TRACK;
|
import static net.osmand.plus.GpxSelectionHelper.CURRENT_TRACK;
|
||||||
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
|
import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB;
|
||||||
|
import static net.osmand.plus.myplaces.FavoritesActivity.OPEN_GPX_REQUEST;
|
||||||
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
|
||||||
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
||||||
import static net.osmand.util.Algorithms.collectDirs;
|
import static net.osmand.util.Algorithms.collectDirs;
|
||||||
|
@ -113,7 +115,7 @@ import static net.osmand.util.Algorithms.objectEquals;
|
||||||
import static net.osmand.util.Algorithms.removeAllFiles;
|
import static net.osmand.util.Algorithms.removeAllFiles;
|
||||||
|
|
||||||
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
|
public class AvailableGPXFragment extends OsmandExpandableListFragment implements
|
||||||
FavoritesFragmentStateHolder, OsmAuthorizationListener {
|
FavoritesFragmentStateHolder, OsmAuthorizationListener, RenameCallback {
|
||||||
|
|
||||||
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
|
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
|
||||||
public static final int SEARCH_ID = -1;
|
public static final int SEARCH_ID = -1;
|
||||||
|
@ -426,7 +428,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, f.getAbsolutePath());
|
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, f.getAbsolutePath());
|
||||||
}
|
}
|
||||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
a.startActivity(newIntent);
|
a.startActivityForResult(newIntent, OPEN_GPX_REQUEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadTracks() {
|
public void reloadTracks() {
|
||||||
|
@ -434,6 +436,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetTracksLoader() {
|
||||||
|
asyncLoader = null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
|
public void onCreateOptionsMenu(Menu menu, @NonNull MenuInflater inflater) {
|
||||||
menu.clear();
|
menu.clear();
|
||||||
|
@ -879,8 +885,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
File dest = new File(destFolder, info.fileName);
|
File dest = new File(destFolder, info.fileName);
|
||||||
if (info.file.renameTo(dest)) {
|
if (info.file.renameTo(dest)) {
|
||||||
app.getGpxDbHelper().rename(info.file, dest);
|
app.getGpxDbHelper().rename(info.file, dest);
|
||||||
asyncLoader = new LoadGpxTask();
|
reloadTracks();
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
@ -902,8 +907,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
} else {
|
} else {
|
||||||
if (info.file.renameTo(dest)) {
|
if (info.file.renameTo(dest)) {
|
||||||
app.getGpxDbHelper().rename(info.file, dest);
|
app.getGpxDbHelper().rename(info.file, dest);
|
||||||
asyncLoader = new LoadGpxTask();
|
reloadTracks();
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
||||||
} else {
|
} else {
|
||||||
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
||||||
}
|
}
|
||||||
|
@ -938,6 +942,11 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
app.startActivity(intent);
|
app.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renamedTo(File file) {
|
||||||
|
reloadTracks();
|
||||||
|
}
|
||||||
|
|
||||||
public class LoadGpxTask extends AsyncTask<Activity, GpxInfo, List<GpxInfo>> {
|
public class LoadGpxTask extends AsyncTask<Activity, GpxInfo, List<GpxInfo>> {
|
||||||
|
|
||||||
private List<GpxInfo> result;
|
private List<GpxInfo> result;
|
||||||
|
@ -1543,13 +1552,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
.setOnClickListener(new View.OnClickListener() {
|
.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
FileUtils.renameFile(getActivity(), gpxInfo.file, new RenameCallback() {
|
FragmentActivity activity = getActivity();
|
||||||
@Override
|
if (activity != null) {
|
||||||
public void renamedTo(File file) {
|
FileUtils.renameFile(activity, gpxInfo.file, AvailableGPXFragment.this, false);
|
||||||
asyncLoader = new LoadGpxTask();
|
}
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create()
|
.create()
|
||||||
|
@ -1711,20 +1717,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
GpxInfo item = allGpxAdapter.getChild(groupPosition, childPosition);
|
GpxInfo item = allGpxAdapter.getChild(groupPosition, childPosition);
|
||||||
|
|
||||||
if (!selectionMode) {
|
if (!selectionMode) {
|
||||||
Intent newIntent = new Intent(getActivity(), getMyApplication().getAppCustomization().getTrackActivity());
|
openTrack(getActivity(), item.file);
|
||||||
// causes wrong position caching: newIntent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
|
||||||
if (item.currentlyRecordingTrack) {
|
|
||||||
newIntent.putExtra(TrackActivity.CURRENT_RECORDING, true);
|
|
||||||
} else {
|
|
||||||
newIntent.putExtra(TrackActivity.TRACK_FILE_NAME, item.file.getAbsolutePath());
|
|
||||||
}
|
|
||||||
newIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
startActivity(newIntent);
|
|
||||||
// item.setExpanded(!item.isExpanded());
|
|
||||||
// if (item.isExpanded()) {
|
|
||||||
// descriptionLoader = new LoadLocalIndexDescriptionTask();
|
|
||||||
// descriptionLoader.execute(item);
|
|
||||||
// }
|
|
||||||
} else {
|
} else {
|
||||||
if (!selectedItems.contains(item)) {
|
if (!selectedItems.contains(item)) {
|
||||||
selectedItems.add(item);
|
selectedItems.add(item);
|
||||||
|
|
|
@ -42,6 +42,8 @@ import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.plus.myplaces.TrackSegmentFragment.TRACK_DELETED_KEY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
@ -50,6 +52,7 @@ public class FavoritesActivity extends TabActivity {
|
||||||
|
|
||||||
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006;
|
private static final int OPEN_GPX_DOCUMENT_REQUEST = 1006;
|
||||||
private static final int IMPORT_FAVOURITES_REQUEST = 1007;
|
private static final int IMPORT_FAVOURITES_REQUEST = 1007;
|
||||||
|
protected static final int OPEN_GPX_REQUEST = 1008;
|
||||||
|
|
||||||
public static final String TAB_ID = "selected_tab_id";
|
public static final String TAB_ID = "selected_tab_id";
|
||||||
|
|
||||||
|
@ -152,6 +155,13 @@ public class FavoritesActivity extends TabActivity {
|
||||||
if (data != null && data.getData() != null) {
|
if (data != null && data.getData() != null) {
|
||||||
importHelper.handleGpxOrFavouritesImport(data.getData());
|
importHelper.handleGpxOrFavouritesImport(data.getData());
|
||||||
}
|
}
|
||||||
|
} else if (requestCode == OPEN_GPX_REQUEST && resultCode == Activity.RESULT_OK) {
|
||||||
|
if (data != null && data.getBooleanExtra(TRACK_DELETED_KEY, false)) {
|
||||||
|
AvailableGPXFragment gpxFragment = getGpxFragment();
|
||||||
|
if (gpxFragment != null) {
|
||||||
|
gpxFragment.resetTracksLoader();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
package net.osmand.plus.myplaces;
|
package net.osmand.plus.myplaces;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
|
import android.content.Intent;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
@ -23,6 +25,8 @@ import androidx.fragment.app.FragmentManager;
|
||||||
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;
|
||||||
|
|
||||||
import net.osmand.AndroidUtils;
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.FileUtils;
|
||||||
|
import net.osmand.FileUtils.RenameCallback;
|
||||||
import net.osmand.GPXUtilities.GPXFile;
|
import net.osmand.GPXUtilities.GPXFile;
|
||||||
import net.osmand.GPXUtilities.Track;
|
import net.osmand.GPXUtilities.Track;
|
||||||
import net.osmand.GPXUtilities.TrkSegment;
|
import net.osmand.GPXUtilities.TrkSegment;
|
||||||
|
@ -53,7 +57,10 @@ import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class TrackSegmentFragment extends OsmAndListFragment implements TrackBitmapDrawerListener, SegmentActionsListener {
|
public class TrackSegmentFragment extends OsmAndListFragment implements TrackBitmapDrawerListener,
|
||||||
|
SegmentActionsListener, RenameCallback {
|
||||||
|
|
||||||
|
public static final String TRACK_DELETED_KEY = "track_deleted_key";
|
||||||
|
|
||||||
private OsmandApplication app;
|
private OsmandApplication app;
|
||||||
private TrackDisplayHelper displayHelper;
|
private TrackDisplayHelper displayHelper;
|
||||||
|
@ -134,8 +141,40 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
|
||||||
}
|
MenuItem renameItem = menu.add(R.string.shared_string_rename)
|
||||||
if (gpxFile.showCurrentTrack) {
|
.setIcon(app.getUIUtilities().getIcon((R.drawable.ic_action_edit_dark)))
|
||||||
|
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
GPXFile gpx = displayHelper.getGpx();
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null && gpx != null) {
|
||||||
|
FileUtils.renameFile(activity, new File(gpx.path), TrackSegmentFragment.this, false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
renameItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
|
MenuItem deleteItem = menu.add(R.string.shared_string_delete)
|
||||||
|
.setIcon(app.getUIUtilities().getIcon((R.drawable.ic_action_delete_dark)))
|
||||||
|
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
GPXFile gpx = displayHelper.getGpx();
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null && gpx != null) {
|
||||||
|
if (FileUtils.removeGpxFile(app, new File((gpx.path)))) {
|
||||||
|
Intent intent = new Intent();
|
||||||
|
intent.putExtra(TRACK_DELETED_KEY, true);
|
||||||
|
activity.setResult(Activity.RESULT_OK, intent);
|
||||||
|
activity.onBackPressed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deleteItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
|
||||||
|
} else if (gpxFile.showCurrentTrack) {
|
||||||
MenuItem item = menu.add(R.string.shared_string_refresh).setIcon(R.drawable.ic_action_refresh_dark)
|
MenuItem item = menu.add(R.string.shared_string_refresh).setIcon(R.drawable.ic_action_refresh_dark)
|
||||||
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -415,4 +454,14 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
||||||
}
|
}
|
||||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void renamedTo(File file) {
|
||||||
|
displayHelper.setFile(file);
|
||||||
|
TrackActivity activity = getTrackActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
activity.setupActionBar();
|
||||||
|
activity.loadGpx();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue