From 90c29ef6fe347918d88289ae1a6baa3f26bc05ae Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 18 Feb 2021 18:40:06 +0200 Subject: [PATCH 1/9] add new button "Add new folder" in "Save as new track" dialog; fix show edit text with an empty name in "Add new folder" dialog; fix start typing a name with a capital letter --- OsmAnd/res/layout/track_name_edit_text.xml | 1 + ...veAsNewTrackBottomSheetDialogFragment.java | 20 +++- .../adapter/FolderListAdapter.java | 102 ++++++++++++------ .../AddNewTrackFolderBottomSheet.java | 6 +- .../plus/myplaces/MoveGpxFileBottomSheet.java | 2 +- 5 files changed, 91 insertions(+), 40 deletions(-) diff --git a/OsmAnd/res/layout/track_name_edit_text.xml b/OsmAnd/res/layout/track_name_edit_text.xml index 6ab03cd632..d05434fc3c 100644 --- a/OsmAnd/res/layout/track_name_edit_text.xml +++ b/OsmAnd/res/layout/track_name_edit_text.xml @@ -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" /> diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 90cbd1446e..d214560f16 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -39,6 +39,7 @@ 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.MoveGpxFileBottomSheet; import net.osmand.plus.myplaces.MoveGpxFileBottomSheet.OnTrackFileMoveListener; import net.osmand.util.Algorithms; @@ -49,7 +50,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, AddNewTrackFolderBottomSheet.OnTrackFolderAddListener { public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class); @@ -250,6 +252,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); + } + } }; } @@ -400,6 +411,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); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java index 30b85910ad..fd95dc9ef6 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java @@ -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,6 +25,8 @@ import java.util.List; public class FolderListAdapter extends RecyclerView.Adapter { + private static final int VIEW_TYPE_FOOTER = 1; + private static final int VIEW_TYPE_CELL = 0; List items = new ArrayList<>(); String selectedItemName; @@ -59,55 +62,86 @@ public class FolderListAdapter extends RecyclerView.Adapter= 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 Date: Fri, 19 Feb 2021 04:41:46 +0200 Subject: [PATCH 2/9] fix "Tracks" folder display in all folders list; fix recently added folder display in all folders list --- .../SaveAsNewTrackBottomSheetDialogFragment.java | 1 + .../net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index d214560f16..224594f9bd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -359,6 +359,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial nameTextBox.setError(getString(R.string.file_with_name_already_exist)); } else { nameTextBox.setError(null); + nameTextBox.setErrorEnabled(false); fileName = text; rightButtonEnabled = true; } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java index e2fa32671d..4121cebbb7 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java @@ -21,6 +21,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment; import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet.OnTrackFolderAddListener; import net.osmand.util.Algorithms; @@ -74,7 +75,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem FragmentActivity activity = getActivity(); if (activity != null) { AddNewTrackFolderBottomSheet.showInstance(activity.getSupportFragmentManager(), - MoveGpxFileBottomSheet.this, usedOnMap); + MoveGpxFileBottomSheet.this, usedOnMap); } } }) @@ -86,9 +87,10 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem dividerItem.setMargins(0, 0, 0, 0); items.add(dividerItem); + boolean isSaveAsNewFragment = getTargetFragment() instanceof SaveAsNewTrackBottomSheetDialogFragment; final List 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, isSaveAsNewFragment ? null : fileDir); + if (isSaveAsNewFragment || !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(); From c445e45b60246736875c4a998ffa46572766b046 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 19 Feb 2021 05:35:29 +0200 Subject: [PATCH 3/9] fix incorrect error display and file name change; --- .../SaveAsNewTrackBottomSheetDialogFragment.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 224594f9bd..2aef0c64cf 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -129,6 +129,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); @@ -360,9 +362,9 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial } else { nameTextBox.setError(null); nameTextBox.setErrorEnabled(false); - fileName = text; rightButtonEnabled = true; } + fileName = text; updateBottomButtons(); } @@ -404,6 +406,7 @@ public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDial if (position != -1) { recyclerView.scrollToPosition(position); } + updateFileNameFromEditText(Algorithms.getFileNameWithoutExtension(dest.getName())); } } From c92cb7aae760ce4df2702283240f054800c8e65a Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 19 Feb 2021 11:37:27 +0200 Subject: [PATCH 4/9] small fix for folder list adapter --- .../measurementtool/adapter/FolderListAdapter.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java index fd95dc9ef6..ed3d8fb09f 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java @@ -27,12 +27,12 @@ public class FolderListAdapter extends RecyclerView.Adapter items = new ArrayList<>(); + private final List 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; From 7373a2c8c23ad05b44e9d031dfc9b80348e89362 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 19 Feb 2021 11:41:11 +0200 Subject: [PATCH 5/9] small fix --- .../SaveAsNewTrackBottomSheetDialogFragment.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 2aef0c64cf..30f863f5dd 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -40,6 +40,7 @@ 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; @@ -51,7 +52,7 @@ import java.util.ArrayList; import java.util.List; public class SaveAsNewTrackBottomSheetDialogFragment extends MenuBottomSheetDialogFragment - implements OnTrackFileMoveListener, AddNewTrackFolderBottomSheet.OnTrackFolderAddListener { + implements OnTrackFileMoveListener, OnTrackFolderAddListener { public static final String TAG = SaveAsNewTrackBottomSheetDialogFragment.class.getSimpleName(); private static final Log LOG = PlatformUtil.getLog(SaveAsNewTrackBottomSheetDialogFragment.class); From f12cbd0aea60b66c25634087842d5817131402fc Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 19 Feb 2021 16:36:01 +0200 Subject: [PATCH 6/9] fix crash when trying to create folder with empty name --- .../AddNewTrackFolderBottomSheet.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AddNewTrackFolderBottomSheet.java b/OsmAnd/src/net/osmand/plus/myplaces/AddNewTrackFolderBottomSheet.java index cbd7c6f026..d186fef1f6 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AddNewTrackFolderBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AddNewTrackFolderBottomSheet.java @@ -90,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(); } @@ -117,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 From f981d4a4bb2db5be0ee8f6fd26f464522c024181 Mon Sep 17 00:00:00 2001 From: Skalii Date: Mon, 22 Feb 2021 13:43:53 +0200 Subject: [PATCH 7/9] small fix --- .../SaveAsNewTrackBottomSheetDialogFragment.java | 2 +- .../net/osmand/plus/myplaces/AvailableGPXFragment.java | 2 +- .../osmand/plus/myplaces/MoveGpxFileBottomSheet.java | 10 +++++----- .../src/net/osmand/plus/track/TrackMenuFragment.java | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java index 30f863f5dd..8ab6619762 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -145,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); } } }); diff --git a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java index 86f9654b73..22615a2f76 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/AvailableGPXFragment.java @@ -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); } } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java index 4121cebbb7..133a2d9552 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java @@ -21,7 +21,6 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription; import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem; import net.osmand.plus.helpers.AndroidUiHelper; -import net.osmand.plus.measurementtool.SaveAsNewTrackBottomSheetDialogFragment; import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet.OnTrackFolderAddListener; import net.osmand.util.Algorithms; @@ -42,6 +41,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem private OsmandApplication app; private String filePath; + private boolean showAllFolders = false; @Override public void createMenuItems(Bundle savedInstanceState) { @@ -87,10 +87,9 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem dividerItem.setMargins(0, 0, 0, 0); items.add(dividerItem); - boolean isSaveAsNewFragment = getTargetFragment() instanceof SaveAsNewTrackBottomSheetDialogFragment; final List dirs = new ArrayList<>(); - collectDirs(app.getAppPath(IndexConstants.GPX_INDEX_DIR), dirs, isSaveAsNewFragment ? null : fileDir); - if (isSaveAsNewFragment || !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(); @@ -165,12 +164,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); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index e0a7290b33..413e22687f 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -791,7 +791,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); From 25390e1d426ebd911136df79ef63405d767f06b7 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Tue, 23 Feb 2021 18:29:32 +0200 Subject: [PATCH 8/9] Fix image download buttons, wrong navigation --- .../main/java/net/osmand/data/Amenity.java | 18 +++++-- .../WikivoyageShowPicturesDialogFragment.java | 47 +++++++------------ .../plus/wikivoyage/data/TravelObfHelper.java | 2 +- 3 files changed, 30 insertions(+), 37 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java index 861a7c9b93..32fb9873e2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/main/java/net/osmand/data/Amenity.java @@ -279,6 +279,19 @@ public class Amenity extends MapObject { } public String getTagContent(String tag, String lang) { + String translateName = getStrictTagContent(tag, lang); + if (translateName != null) { + return translateName; + } + for (String nm : getAdditionalInfoKeys()) { + if (nm.startsWith(tag + ":")) { + return getAdditionalInfo(nm); + } + } + return null; + } + + public String getStrictTagContent(String tag, String lang) { if (lang != null) { String translateName = getAdditionalInfo(tag + ":" + lang); if (!Algorithms.isEmpty(translateName)) { @@ -293,11 +306,6 @@ public class Amenity extends MapObject { if (!Algorithms.isEmpty(enName)) { return enName; } - for (String nm : getAdditionalInfoKeys()) { - if (nm.startsWith(tag + ":")) { - return getAdditionalInfo(nm); - } - } return null; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java index 824a2e9e49..286726e0ac 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/WikivoyageShowPicturesDialogFragment.java @@ -33,50 +33,35 @@ public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragm @Override public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - nightMode=!getMyApplication().getSettings().isLightContent(); + nightMode = !getMyApplication().getSettings().isLightContent(); View view = inflater.inflate(R.layout.fragment_wikivoyage_show_images_first_time, container, false); - view.findViewById(R.id.button_no).setOnClickListener(new View.OnClickListener() { + TextView buttonNo = view.findViewById(R.id.button_no); + buttonNo.setText(R.string.shared_string_only_with_wifi); + buttonNo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { OsmandApplication app = getMyApplication(); if (app != null) { - app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.OFF); + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.WIFI); } sendResult(); dismiss(); } }); TextView buttonDownload = view.findViewById(R.id.button_download); - if (getMyApplication().getSettings().isWifiConnected()) { - buttonDownload.setText(R.string.shared_string_only_with_wifi); - buttonDownload.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - OsmandApplication app = getMyApplication(); - if (app != null) { - app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.WIFI); - } - sendResult(); - dismiss(); + buttonDownload.setText(R.string.shared_string_always); + buttonDownload.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + OsmandApplication app = getMyApplication(); + if (app != null) { + app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.ON); } - }); - } else { - buttonDownload.setText(R.string.shared_string_show); - buttonDownload.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - OsmandApplication app = getMyApplication(); - if (app != null) { - app.getSettings().WIKI_ARTICLE_SHOW_IMAGES.set(WikiArticleShowImages.ON); - } - sendResult(); - dismiss(); - } - }); - } - + sendResult(); + dismiss(); + } + }); setupHeightAndBackground(view); - return view; } diff --git a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java index 56a2b85269..cdd90e21bd 100644 --- a/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java +++ b/OsmAnd/src/net/osmand/plus/wikivoyage/data/TravelObfHelper.java @@ -280,7 +280,7 @@ public class TravelObfHelper implements TravelHelper { res.originalId = 0; res.lang = lang; res.contentsJson = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.CONTENT_JSON, lang)); - res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getTagContent(Amenity.IS_AGGR_PART, lang)); + res.aggregatedPartOf = Algorithms.emptyIfNull(amenity.getStrictTagContent(Amenity.IS_AGGR_PART, lang)); return res; } From b149bb47daac80d95f95aa233aeab48892731c70 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 24 Feb 2021 15:40:52 +0200 Subject: [PATCH 9/9] fix save state to show all folders after screen is rotated --- .../src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java b/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java index 133a2d9552..ade0af2bb3 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/MoveGpxFileBottomSheet.java @@ -38,6 +38,7 @@ 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; @@ -48,6 +49,7 @@ public class MoveGpxFileBottomSheet extends MenuBottomSheetDialogFragment implem app = requiredMyApplication(); if (savedInstanceState != null) { filePath = savedInstanceState.getString(FILE_PATH_KEY); + showAllFolders = savedInstanceState.getBoolean(SHOW_ALL_FOLDERS_KEY); } if (filePath == null) { return; @@ -136,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