Fix #10068
This commit is contained in:
parent
c1dcd503c8
commit
7a1517fc3d
5 changed files with 336 additions and 132 deletions
|
@ -12,6 +12,9 @@
|
||||||
|
|
||||||
-->
|
-->
|
||||||
|
|
||||||
|
<string name="select_folder_descr">Select folder or add new one</string>
|
||||||
|
<string name="select_folder">Select folder</string>
|
||||||
|
<string name="shared_string_folders">Folders</string>
|
||||||
<string name="online_routing_engines">Online routing engines</string>
|
<string name="online_routing_engines">Online routing engines</string>
|
||||||
<string name="online_routing_engine">Online routing engine</string>
|
<string name="online_routing_engine">Online routing engine</string>
|
||||||
<string name="copy_address">Copy address</string>
|
<string name="copy_address">Copy address</string>
|
||||||
|
|
|
@ -0,0 +1,158 @@
|
||||||
|
package net.osmand.plus.myplaces;
|
||||||
|
|
||||||
|
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.FragmentManager;
|
||||||
|
|
||||||
|
import com.google.android.material.textfield.TextInputEditText;
|
||||||
|
import com.google.android.material.textfield.TextInputLayout;
|
||||||
|
|
||||||
|
import net.osmand.AndroidUtils;
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
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_PATH_NAME_CHARACTERS;
|
||||||
|
|
||||||
|
public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
|
|
||||||
|
public static final String TAG = AddNewTrackFolderBottomSheet.class.getName();
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(AddNewTrackFolderBottomSheet.class);
|
||||||
|
private static final String FOLDER_NAME_KEY = "folder_name_key";
|
||||||
|
|
||||||
|
private OsmandApplication app;
|
||||||
|
|
||||||
|
private TextInputEditText editText;
|
||||||
|
private TextInputLayout nameTextBox;
|
||||||
|
|
||||||
|
private String folderName;
|
||||||
|
private boolean rightButtonEnabled = true;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
app = requiredMyApplication();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
|
||||||
|
} else if (Algorithms.isEmpty(folderName)) {
|
||||||
|
folderName = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getName();
|
||||||
|
}
|
||||||
|
items.add(new TitleItem(getString(R.string.add_new_folder)));
|
||||||
|
|
||||||
|
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);
|
||||||
|
TextInputEditText nameText = view.findViewById(R.id.name_edit_text);
|
||||||
|
nameText.setText(folderName);
|
||||||
|
nameText.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) {
|
||||||
|
updateFileNameFromEditText(s.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
BaseBottomSheetItem editFolderName = new BaseBottomSheetItem.Builder()
|
||||||
|
.setCustomView(view)
|
||||||
|
.create();
|
||||||
|
items.add(editFolderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean isRightBottomButtonEnabled() {
|
||||||
|
return rightButtonEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateFileNameFromEditText(String name) {
|
||||||
|
rightButtonEnabled = false;
|
||||||
|
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(name).find()) {
|
||||||
|
nameTextBox.setError(getString(R.string.file_name_containes_illegal_char));
|
||||||
|
} else if (Algorithms.isEmpty(name.trim())) {
|
||||||
|
nameTextBox.setError(getString(R.string.empty_filename));
|
||||||
|
} else {
|
||||||
|
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), name);
|
||||||
|
if (destFolder.exists()) {
|
||||||
|
nameTextBox.setError(getString(R.string.file_with_name_already_exist));
|
||||||
|
} else {
|
||||||
|
nameTextBox.setError(null);
|
||||||
|
folderName = name;
|
||||||
|
rightButtonEnabled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
updateBottomButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
outState.putString(FOLDER_NAME_KEY, folderName);
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onRightBottomButtonClick() {
|
||||||
|
AndroidUtils.hideSoftKeyboard(requireActivity(), editText);
|
||||||
|
Fragment fragment = getTargetFragment();
|
||||||
|
if (fragment instanceof OnTrackFolderAddListener) {
|
||||||
|
OnTrackFolderAddListener listener = (OnTrackFolderAddListener) fragment;
|
||||||
|
listener.onTrackFolderAdd(folderName);
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getDismissButtonTextId() {
|
||||||
|
return R.string.shared_string_cancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getRightBottomButtonTextId() {
|
||||||
|
return R.string.shared_string_add;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnTrackFolderAddListener {
|
||||||
|
|
||||||
|
void onTrackFolderAdd(String folderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
|
||||||
|
@NonNull String folderName, boolean usedOnMap) {
|
||||||
|
try {
|
||||||
|
if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(AddNewTrackFolderBottomSheet.TAG) == null) {
|
||||||
|
AddNewTrackFolderBottomSheet fragment = new AddNewTrackFolderBottomSheet();
|
||||||
|
fragment.folderName = folderName;
|
||||||
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
|
fragment.setTargetFragment(target, 0);
|
||||||
|
fragment.show(fragmentManager, AddNewTrackFolderBottomSheet.TAG);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
LOG.error("showInstance", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,8 +13,6 @@ import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
@ -27,7 +25,6 @@ import android.widget.ArrayAdapter;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.CheckBox;
|
import android.widget.CheckBox;
|
||||||
import android.widget.CompoundButton;
|
import android.widget.CompoundButton;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.ExpandableListView;
|
import android.widget.ExpandableListView;
|
||||||
import android.widget.Filter;
|
import android.widget.Filter;
|
||||||
import android.widget.Filterable;
|
import android.widget.Filterable;
|
||||||
|
@ -42,6 +39,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;
|
||||||
|
@ -81,11 +79,12 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
|
||||||
import net.osmand.plus.helpers.enums.TracksSortByMode;
|
import net.osmand.plus.helpers.enums.TracksSortByMode;
|
||||||
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment;
|
||||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||||
|
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet.OnTrackFileMoveListener;
|
||||||
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;
|
||||||
|
@ -101,21 +100,18 @@ import java.util.LinkedHashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
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.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.formatDuration;
|
import static net.osmand.util.Algorithms.formatDuration;
|
||||||
import static net.osmand.util.Algorithms.objectEquals;
|
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, OnTrackFileMoveListener {
|
||||||
|
|
||||||
public static final Pattern ILLEGAL_PATH_NAME_CHARACTERS = Pattern.compile("[?:\"*|<>]");
|
|
||||||
public static final int SEARCH_ID = -1;
|
public static final int SEARCH_ID = -1;
|
||||||
// public static final int ACTION_ID = 0;
|
// public static final int ACTION_ID = 0;
|
||||||
// protected static final int DELETE_ACTION_ID = 1;
|
// protected static final int DELETE_ACTION_ID = 1;
|
||||||
|
@ -790,129 +786,10 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
}
|
}
|
||||||
|
|
||||||
private void moveGpx(final GpxInfo info) {
|
private void moveGpx(final GpxInfo info) {
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
final ContextMenuAdapter menuAdapter = new ContextMenuAdapter(app);
|
if (activity != null) {
|
||||||
ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder();
|
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(), this, info.file.getAbsolutePath(), false);
|
||||||
|
|
||||||
final List<File> dirs = new ArrayList<>();
|
|
||||||
collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, info.file.getParentFile());
|
|
||||||
if (!info.file.getParentFile().equals(app.getAppPath(IndexConstants.GPX_INDEX_DIR))) {
|
|
||||||
dirs.add(0, app.getAppPath(IndexConstants.GPX_INDEX_DIR));
|
|
||||||
}
|
}
|
||||||
String gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getPath();
|
|
||||||
int i = 0;
|
|
||||||
for (File dir : dirs) {
|
|
||||||
String dirName = dir.getPath();
|
|
||||||
if (dirName.startsWith(gpxDir)) {
|
|
||||||
if (dirName.length() == gpxDir.length()) {
|
|
||||||
dirName = dir.getName();
|
|
||||||
} else {
|
|
||||||
dirName = dirName.substring(gpxDir.length() + 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
menuAdapter.addItem(itemBuilder.setTitle(capitalizeFirstLetter(dirName))
|
|
||||||
.setIcon(R.drawable.ic_action_folder_stroke).setTag(i).createItem());
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
menuAdapter.addItem(itemBuilder.setTitleId(R.string.add_new_folder, app)
|
|
||||||
.setIcon(R.drawable.ic_zoom_in).setTag(-1).createItem());
|
|
||||||
final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
|
|
||||||
final ArrayAdapter<ContextMenuItem> listAdapter =
|
|
||||||
menuAdapter.createListAdapter(getActivity(), app.getSettings().isLightContent());
|
|
||||||
builder.setTitle(R.string.select_gpx_folder);
|
|
||||||
builder.setAdapter(listAdapter, new DialogInterface.OnClickListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
ContextMenuItem item = menuAdapter.getItem(which);
|
|
||||||
int index = item.getTag();
|
|
||||||
if (index == -1) {
|
|
||||||
Activity a = getActivity();
|
|
||||||
AlertDialog.Builder b = new AlertDialog.Builder(a);
|
|
||||||
b.setTitle(R.string.add_new_folder);
|
|
||||||
final EditText editText = new EditText(a);
|
|
||||||
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) {
|
|
||||||
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(text).find()) {
|
|
||||||
editText.setError(app.getString(R.string.file_name_containes_illegal_char));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
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_ok, 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) {
|
|
||||||
String newName = editText.getText().toString();
|
|
||||||
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(newName).find()) {
|
|
||||||
Toast.makeText(app, R.string.file_name_containes_illegal_char,
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), newName);
|
|
||||||
if (destFolder.exists()) {
|
|
||||||
Toast.makeText(app, R.string.file_with_name_already_exists,
|
|
||||||
Toast.LENGTH_LONG).show();
|
|
||||||
return;
|
|
||||||
} else if (destFolder.mkdirs()) {
|
|
||||||
File dest = new File(destFolder, info.fileName);
|
|
||||||
if (info.file.renameTo(dest)) {
|
|
||||||
app.getGpxDbHelper().rename(info.file, dest);
|
|
||||||
asyncLoader = new LoadGpxTask();
|
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
||||||
} else {
|
|
||||||
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
alertDialog.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
alertDialog.show();
|
|
||||||
} else {
|
|
||||||
File dir = dirs.get(index);
|
|
||||||
File dest = new File(dir, info.file.getName());
|
|
||||||
if (dest.exists()) {
|
|
||||||
Toast.makeText(app, R.string.file_with_name_already_exists, Toast.LENGTH_LONG).show();
|
|
||||||
} else {
|
|
||||||
if (info.file.renameTo(dest)) {
|
|
||||||
app.getGpxDbHelper().rename(info.file, dest);
|
|
||||||
asyncLoader = new LoadGpxTask();
|
|
||||||
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
|
||||||
} else {
|
|
||||||
Toast.makeText(app, R.string.file_can_not_be_moved, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
builder.setNegativeButton(R.string.shared_string_cancel, null);
|
|
||||||
builder.create().show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -938,6 +815,22 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
||||||
app.startActivity(intent);
|
app.startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFileMove(@NonNull File src, @NonNull File dest) {
|
||||||
|
File destFolder = dest.getParentFile();
|
||||||
|
if (destFolder != null && !destFolder.exists() && !destFolder.mkdirs()) {
|
||||||
|
app.showToastMessage(R.string.file_can_not_be_moved);
|
||||||
|
} else if (dest.exists()) {
|
||||||
|
app.showToastMessage(R.string.file_with_name_already_exists);
|
||||||
|
} else if (src.renameTo(dest)) {
|
||||||
|
app.getGpxDbHelper().rename(src, dest);
|
||||||
|
asyncLoader = new LoadGpxTask();
|
||||||
|
asyncLoader.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, getActivity());
|
||||||
|
} else {
|
||||||
|
app.showToastMessage(R.string.file_can_not_be_moved);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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;
|
||||||
|
|
151
OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java
Normal file
151
OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java
Normal file
|
@ -0,0 +1,151 @@
|
||||||
|
package net.osmand.plus.myplaces;
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.View.OnClickListener;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
import androidx.fragment.app.FragmentActivity;
|
||||||
|
import androidx.fragment.app.FragmentManager;
|
||||||
|
|
||||||
|
import net.osmand.IndexConstants;
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
import net.osmand.plus.R;
|
||||||
|
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.SubtitleItem;
|
||||||
|
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||||
|
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet.OnTrackFolderAddListener;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static net.osmand.util.Algorithms.capitalizeFirstLetter;
|
||||||
|
import static net.osmand.util.Algorithms.collectDirs;
|
||||||
|
|
||||||
|
public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implements OnTrackFolderAddListener {
|
||||||
|
|
||||||
|
public static final String TAG = MoveGpxFileBottomSheet.class.getSimpleName();
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(MoveGpxFileBottomSheet.class);
|
||||||
|
private static final String FILE_PATH_KEY = "file_path_key";
|
||||||
|
|
||||||
|
private OsmandApplication app;
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createMenuItems(Bundle savedInstanceState) {
|
||||||
|
app = requiredMyApplication();
|
||||||
|
if (savedInstanceState != null) {
|
||||||
|
filePath = savedInstanceState.getString(FILE_PATH_KEY);
|
||||||
|
}
|
||||||
|
if (filePath == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final File file = new File(filePath);
|
||||||
|
final File fileDir = file.getParentFile();
|
||||||
|
|
||||||
|
items.add(new TitleItem(getString(R.string.shared_string_folders)));
|
||||||
|
items.add(new SubtitleItem(getString(R.string.select_folder_descr)));
|
||||||
|
|
||||||
|
BaseBottomSheetItem addNewFolderItem = new SimpleBottomSheetItem.Builder()
|
||||||
|
.setTitle(getString(R.string.add_new_folder))
|
||||||
|
.setIcon(getActiveIcon(R.drawable.ic_action_folder_add))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
|
.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
FragmentActivity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
|
||||||
|
MoveGpxFileBottomSheet.this, fileDir.getName(), usedOnMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.create();
|
||||||
|
items.add(addNewFolderItem);
|
||||||
|
items.add(new DividerItem(app));
|
||||||
|
|
||||||
|
final List<File> dirs = new ArrayList<>();
|
||||||
|
collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, fileDir);
|
||||||
|
if (!Algorithms.objectEquals(fileDir, app.getAppPath(IndexConstants.GPX_INDEX_DIR))) {
|
||||||
|
dirs.add(0, app.getAppPath(IndexConstants.GPX_INDEX_DIR));
|
||||||
|
}
|
||||||
|
String gpxDir = app.getAppPath(IndexConstants.GPX_INDEX_DIR).getPath();
|
||||||
|
for (final File dir : dirs) {
|
||||||
|
String dirName = dir.getPath();
|
||||||
|
if (dirName.startsWith(gpxDir)) {
|
||||||
|
if (dirName.length() == gpxDir.length()) {
|
||||||
|
dirName = dir.getName();
|
||||||
|
} else {
|
||||||
|
dirName = dirName.substring(gpxDir.length() + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final BaseBottomSheetItem[] folderItem = new BaseBottomSheetItem[1];
|
||||||
|
folderItem[0] = new SimpleBottomSheetItem.Builder()
|
||||||
|
.setTitle(capitalizeFirstLetter(dirName))
|
||||||
|
.setIcon(getActiveIcon(R.drawable.ic_action_folder))
|
||||||
|
.setLayoutId(R.layout.bottom_sheet_item_simple)
|
||||||
|
.setOnClickListener(new OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(View v) {
|
||||||
|
Fragment fragment = getTargetFragment();
|
||||||
|
if (fragment instanceof OnTrackFileMoveListener) {
|
||||||
|
OnTrackFileMoveListener listener = (OnTrackFileMoveListener) fragment;
|
||||||
|
listener.onFileMove(file, new File(dir, file.getName()));
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setTag(dir)
|
||||||
|
.create();
|
||||||
|
items.add(folderItem[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSaveInstanceState(Bundle outState) {
|
||||||
|
super.onSaveInstanceState(outState);
|
||||||
|
outState.putString(FILE_PATH_KEY, filePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onTrackFolderAdd(String folderName) {
|
||||||
|
Fragment fragment = getTargetFragment();
|
||||||
|
if (fragment instanceof OnTrackFileMoveListener) {
|
||||||
|
File file = new File(filePath);
|
||||||
|
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), folderName);
|
||||||
|
OnTrackFileMoveListener listener = (OnTrackFileMoveListener) fragment;
|
||||||
|
listener.onFileMove(file, new File(destFolder, file.getName()));
|
||||||
|
}
|
||||||
|
dismiss();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
|
||||||
|
@NonNull String filePath, boolean usedOnMap) {
|
||||||
|
try {
|
||||||
|
if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(MoveGpxFileBottomSheet.TAG) == null) {
|
||||||
|
MoveGpxFileBottomSheet fragment = new MoveGpxFileBottomSheet();
|
||||||
|
fragment.filePath = filePath;
|
||||||
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
|
fragment.setTargetFragment(target, 0);
|
||||||
|
fragment.show(fragmentManager, MoveGpxFileBottomSheet.TAG);
|
||||||
|
}
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
LOG.error("showInstance", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnTrackFileMoveListener {
|
||||||
|
void onFileMove(@NonNull File src, @NonNull File dest);
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.settings.bottomsheets;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
@ -255,7 +254,7 @@ public class ElevationDateBottomSheet extends MenuBottomSheetDialogFragment {
|
||||||
fragment.appMode = appMode;
|
fragment.appMode = appMode;
|
||||||
fragment.setUsedOnMap(usedOnMap);
|
fragment.setUsedOnMap(usedOnMap);
|
||||||
fragment.setTargetFragment(target, 0);
|
fragment.setTargetFragment(target, 0);
|
||||||
fragment.show(fm, ScreenTimeoutBottomSheet.TAG);
|
fragment.show(fm, ElevationDateBottomSheet.TAG);
|
||||||
}
|
}
|
||||||
} catch (RuntimeException e) {
|
} catch (RuntimeException e) {
|
||||||
LOG.error("showInstance", e);
|
LOG.error("showInstance", e);
|
||||||
|
|
Loading…
Reference in a new issue