Merge pull request #10941 from osmandapp/fix_custom_track_folders
Fix custom track folders
This commit is contained in:
commit
d6dc10e5cf
7 changed files with 133 additions and 65 deletions
|
@ -24,6 +24,7 @@
|
|||
android:id="@+id/name_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:inputType="textCapSentences"
|
||||
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" />
|
||||
|
||||
</com.google.android.material.textfield.TextInputLayout>
|
||||
|
|
|
@ -39,6 +39,8 @@ import net.osmand.plus.base.bottomsheetmenu.HorizontalRecyclerBottomSheetItem;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.measurementtool.adapter.FolderListAdapter;
|
||||
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet;
|
||||
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet.OnTrackFolderAddListener;
|
||||
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet;
|
||||
import net.osmand.plus.myplaces.MoveGpxFileBottomSheet.OnTrackFileMoveListener;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -49,7 +51,8 @@ import java.io.File;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment implements OnTrackFileMoveListener {
|
||||
public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment
|
||||
implements OnTrackFileMoveListener, OnTrackFolderAddListener {
|
||||
|
||||
public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class);
|
||||
|
@ -127,6 +130,8 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
.create();
|
||||
this.items.add(editFileName);
|
||||
|
||||
updateFileNameFromEditText(fileName);
|
||||
|
||||
int contentPaddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
|
||||
int contentPaddingHalf = app.getResources().getDimensionPixelSize(R.dimen.content_padding_half);
|
||||
|
||||
|
@ -140,7 +145,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
if (activity != null) {
|
||||
File dest = getFile(app, folderName, fileName);
|
||||
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(),
|
||||
SaveAsNewTrackBottomSheetDialogFragment.this, dest.getAbsolutePath(), usedOnMap);
|
||||
SaveAsNewTrackBottomSheetDialogFragment.this, dest.getAbsolutePath(), usedOnMap, true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -250,6 +255,15 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
updateFileNameFromEditText(editText.getText().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAddNewItemSelected() {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
|
||||
SaveAsNewTrackBottomSheetDialogFragment.this, usedOnMap);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -348,9 +362,10 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
nameTextBox.setError(getString(R.string.file_with_name_already_exist));
|
||||
} else {
|
||||
nameTextBox.setError(null);
|
||||
fileName = text;
|
||||
nameTextBox.setErrorEnabled(false);
|
||||
rightButtonEnabled = true;
|
||||
}
|
||||
fileName = text;
|
||||
updateBottomButtons();
|
||||
}
|
||||
|
||||
|
@ -392,6 +407,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
if (position != -1) {
|
||||
recyclerView.scrollToPosition(position);
|
||||
}
|
||||
updateFileNameFromEditText(Algorithms.getFileNameWithoutExtension(dest.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -400,6 +416,13 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial
|
|||
return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTrackFolderAdd(String folderName) {
|
||||
File file = getFile(app, this.folderName, fileName);
|
||||
File destFolder = new File(app.getAppPath(IndexConstants.GPX_INDEX_DIR), folderName);
|
||||
this.onFileMove(file, new File(destFolder, file.getName()));
|
||||
}
|
||||
|
||||
public interface SaveAsNewTrackFragmentListener {
|
||||
|
||||
void onSaveAsNewTrack(String folderName, String fileName, boolean showOnMap, boolean simplifiedTrack);
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package net.osmand.plus.measurementtool.adapter;
|
||||
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Build;
|
||||
import android.text.TextUtils;
|
||||
|
@ -24,12 +25,14 @@ import java.util.List;
|
|||
|
||||
public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.GroupsViewHolder> {
|
||||
|
||||
List<String> items = new ArrayList<>();
|
||||
private static final int VIEW_TYPE_FOOTER = 1;
|
||||
private static final int VIEW_TYPE_CELL = 0;
|
||||
private final List<String> items = new ArrayList<>();
|
||||
|
||||
String selectedItemName;
|
||||
OsmandApplication app;
|
||||
boolean nightMode;
|
||||
FolderListAdapterListener listener;
|
||||
private String selectedItemName;
|
||||
private final OsmandApplication app;
|
||||
private final boolean nightMode;
|
||||
private FolderListAdapterListener listener;
|
||||
|
||||
public FolderListAdapter(OsmandApplication app, boolean nightMode, String folderName) {
|
||||
this.app = app;
|
||||
|
@ -59,55 +62,86 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
|
|||
groupName.setMaxLines(1);
|
||||
groupName.setEllipsize(TextUtils.TruncateAt.END);
|
||||
groupName.setTextColor(ContextCompat.getColor(app, activeColorRes));
|
||||
if (viewType != VIEW_TYPE_CELL) {
|
||||
groupName.setText(R.string.add_new_folder);
|
||||
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||
Drawable iconAdd = app.getUIUtilities().getIcon(R.drawable.ic_action_add, activeColorResId);
|
||||
ImageView groupIcon = view.findViewById(R.id.groupIcon);
|
||||
groupIcon.setImageDrawable(iconAdd);
|
||||
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
|
||||
R.drawable.bg_select_group_button_outline);
|
||||
if (rectContourDrawable != null) {
|
||||
int strokeColor = ContextCompat.getColor(app, nightMode ? R.color.stroked_buttons_and_links_outline_dark
|
||||
: R.color.stroked_buttons_and_links_outline_light);
|
||||
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, 1), strokeColor);
|
||||
((ImageView) view.findViewById(R.id.outlineRect)).setImageDrawable(rectContourDrawable);
|
||||
}
|
||||
((TextView) view.findViewById(R.id.groupName)).setTextColor(app.getResources().getColor(activeColorResId));
|
||||
}
|
||||
return new FolderListAdapter.GroupsViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final GroupsViewHolder holder, int position) {
|
||||
|
||||
holder.groupButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int previousSelectedPosition = getItemPosition(selectedItemName);
|
||||
selectedItemName = items.get(holder.getAdapterPosition());
|
||||
notifyItemChanged(holder.getAdapterPosition());
|
||||
notifyItemChanged(previousSelectedPosition);
|
||||
if (listener != null) {
|
||||
listener.onItemSelected(selectedItemName);
|
||||
if (position == items.size()) {
|
||||
holder.groupButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.onAddNewItemSelected();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
|
||||
holder.groupName.setText(group);
|
||||
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||
int strokeColor;
|
||||
int strokeWidth;
|
||||
if (selectedItemName != null && selectedItemName.equals(items.get(position))) {
|
||||
strokeColor = activeColorRes;
|
||||
strokeWidth = 2;
|
||||
});
|
||||
} else {
|
||||
strokeColor = nightMode ? R.color.stroked_buttons_and_links_outline_dark
|
||||
: R.color.stroked_buttons_and_links_outline_light;
|
||||
strokeWidth = 1;
|
||||
holder.groupButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
int previousSelectedPosition = getItemPosition(selectedItemName);
|
||||
selectedItemName = items.get(holder.getAdapterPosition());
|
||||
notifyItemChanged(holder.getAdapterPosition());
|
||||
notifyItemChanged(previousSelectedPosition);
|
||||
if (listener != null) {
|
||||
listener.onItemSelected(selectedItemName);
|
||||
}
|
||||
}
|
||||
});
|
||||
final String group = Algorithms.capitalizeFirstLetter(items.get(position));
|
||||
holder.groupName.setText(group);
|
||||
int activeColorRes = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
|
||||
int strokeColor;
|
||||
int strokeWidth;
|
||||
if (selectedItemName != null && selectedItemName.equals(items.get(position))) {
|
||||
strokeColor = activeColorRes;
|
||||
strokeWidth = 2;
|
||||
} else {
|
||||
strokeColor = nightMode ? R.color.stroked_buttons_and_links_outline_dark
|
||||
: R.color.stroked_buttons_and_links_outline_light;
|
||||
strokeWidth = 1;
|
||||
}
|
||||
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
|
||||
R.drawable.bg_select_group_button_outline);
|
||||
if (rectContourDrawable != null) {
|
||||
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), ContextCompat.getColor(app, strokeColor));
|
||||
holder.groupButton.setImageDrawable(rectContourDrawable);
|
||||
}
|
||||
int iconID;
|
||||
iconID = R.drawable.ic_action_folder;
|
||||
holder.groupIcon.setImageDrawable(app.getUIUtilities().getIcon(iconID, activeColorRes));
|
||||
}
|
||||
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app,
|
||||
R.drawable.bg_select_group_button_outline);
|
||||
if (rectContourDrawable != null) {
|
||||
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), ContextCompat.getColor(app, strokeColor));
|
||||
holder.groupButton.setImageDrawable(rectContourDrawable);
|
||||
}
|
||||
int iconID;
|
||||
iconID = R.drawable.ic_action_folder;
|
||||
holder.groupIcon.setImageDrawable(app.getUIUtilities().getIcon(iconID, activeColorRes));
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
AndroidUtils.setBackground(app, holder.groupButton, nightMode, R.drawable.ripple_solid_light_6dp,
|
||||
R.drawable.ripple_solid_dark_6dp);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
return (position == items.size()) ? VIEW_TYPE_FOOTER : VIEW_TYPE_CELL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items == null ? 0 : items.size();
|
||||
return items == null ? 0 : items.size() + 1;
|
||||
}
|
||||
|
||||
int getItemPosition(String name) {
|
||||
|
@ -135,5 +169,7 @@ public class FolderListAdapter extends RecyclerView.Adapter<FolderListAdapter.Gr
|
|||
public interface FolderListAdapterListener {
|
||||
|
||||
void onItemSelected(String item);
|
||||
|
||||
void onAddNewItemSelected();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,8 +51,6 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
|
|||
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)));
|
||||
|
||||
|
@ -92,20 +90,23 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
|
|||
|
||||
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())) {
|
||||
if (Algorithms.isBlank(name)) {
|
||||
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));
|
||||
if (ILLEGAL_PATH_NAME_CHARACTERS.matcher(name).find()) {
|
||||
nameTextBox.setError(getString(R.string.file_name_containes_illegal_char));
|
||||
} else {
|
||||
nameTextBox.setError(null);
|
||||
folderName = name;
|
||||
rightButtonEnabled = true;
|
||||
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);
|
||||
nameTextBox.setErrorEnabled(false);
|
||||
rightButtonEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
folderName = name;
|
||||
updateBottomButtons();
|
||||
}
|
||||
|
||||
|
@ -119,11 +120,15 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
|
|||
protected void onRightBottomButtonClick() {
|
||||
AndroidUtils.hideSoftKeyboard(requireActivity(), editText);
|
||||
Fragment fragment = getTargetFragment();
|
||||
if (fragment instanceof OnTrackFolderAddListener) {
|
||||
OnTrackFolderAddListener listener = (OnTrackFolderAddListener) fragment;
|
||||
listener.onTrackFolderAdd(folderName);
|
||||
if (!Algorithms.isBlank(folderName)) {
|
||||
if (fragment instanceof OnTrackFolderAddListener) {
|
||||
OnTrackFolderAddListener listener = (OnTrackFolderAddListener) fragment;
|
||||
listener.onTrackFolderAdd(folderName);
|
||||
}
|
||||
dismiss();
|
||||
} else {
|
||||
updateFileNameFromEditText(folderName);
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -141,12 +146,10 @@ public class AddNewTrackFolderBottomSheet extends MenuBottomSheetDialogFragment
|
|||
void onTrackFolderAdd(String folderName);
|
||||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
|
||||
@NonNull String folderName, boolean usedOnMap) {
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target, 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);
|
||||
|
|
|
@ -780,7 +780,7 @@ public class AvailableGPXFragment extends OsmandExpandableListFragment implement
|
|||
private void moveGpx(final GpxInfo info) {
|
||||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(), this, info.file.getAbsolutePath(), false);
|
||||
MoveGpxFileBottomSheet.showInstance(activity.getSupportFragmentManager(), this, info.file.getAbsolutePath(), false, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -38,15 +38,18 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
|
|||
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 static final String SHOW_ALL_FOLDERS_KEY = "show_all_folders_key";
|
||||
|
||||
private OsmandApplication app;
|
||||
private String filePath;
|
||||
private boolean showAllFolders = false;
|
||||
|
||||
@Override
|
||||
public void createMenuItems(Bundle savedInstanceState) {
|
||||
app = requiredMyApplication();
|
||||
if (savedInstanceState != null) {
|
||||
filePath = savedInstanceState.getString(FILE_PATH_KEY);
|
||||
showAllFolders = savedInstanceState.getBoolean(SHOW_ALL_FOLDERS_KEY);
|
||||
}
|
||||
if (filePath == null) {
|
||||
return;
|
||||
|
@ -74,7 +77,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
|
|||
FragmentActivity activity = getActivity();
|
||||
if (activity != null) {
|
||||
AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(),
|
||||
MoveGpxFileBottomSheet.this, fileDir.getName(), usedOnMap);
|
||||
MoveGpxFileBottomSheet.this, usedOnMap);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -87,8 +90,8 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
|
|||
items.add(dividerItem);
|
||||
|
||||
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))) {
|
||||
collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, showAllFolders ? null : fileDir);
|
||||
if (showAllFolders || !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();
|
||||
|
@ -135,6 +138,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
|
|||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putString(FILE_PATH_KEY, filePath);
|
||||
outState.putBoolean(SHOW_ALL_FOLDERS_KEY, showAllFolders);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,12 +167,13 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem
|
|||
}
|
||||
|
||||
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target,
|
||||
@NonNull String filePath, boolean usedOnMap) {
|
||||
@NonNull String filePath, boolean usedOnMap, boolean showAllFolders) {
|
||||
try {
|
||||
if (!fragmentManager.isStateSaved() && fragmentManager.findFragmentByTag(MoveGpxFileBottomSheet.TAG) == null) {
|
||||
MoveGpxFileBottomSheet fragment = new MoveGpxFileBottomSheet();
|
||||
fragment.filePath = filePath;
|
||||
fragment.setUsedOnMap(usedOnMap);
|
||||
fragment.showAllFolders = showAllFolders;
|
||||
fragment.setTargetFragment(target, 0);
|
||||
fragment.show(fragmentManager, MoveGpxFileBottomSheet.TAG);
|
||||
}
|
||||
|
|
|
@ -846,7 +846,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
|
|||
FileUtils.renameFile(mapActivity, new File(gpxFile.path), this, true);
|
||||
} else if (buttonIndex == CHANGE_FOLDER_BUTTON_INDEX) {
|
||||
FragmentManager fragmentManager = mapActivity.getSupportFragmentManager();
|
||||
MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true);
|
||||
MoveGpxFileBottomSheet.showInstance(fragmentManager, this, gpxFile.path, true, false);
|
||||
} else if (buttonIndex == DELETE_BUTTON_INDEX) {
|
||||
String fileName = Algorithms.getFileWithoutDirs(gpxFile.path);
|
||||
|
||||
|
|
Loading…
Reference in a new issue