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/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..8ab6619762 100644 --- a/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/measurementtool/SaveAsNewTrackBottomSheetDialogFragment.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java b/OsmAnd/src/net/osmand/plus/measurementtool/adapter/FolderListAdapter.java index 30b85910ad..ed3d8fb09f 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,12 +25,14 @@ import java.util.List; public class FolderListAdapter extends RecyclerView.Adapter { - List items = new ArrayList<>(); + private static final int VIEW_TYPE_FOOTER = 1; + private static final int VIEW_TYPE_CELL = 0; + 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; @@ -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 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); } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 797f8fbf6a..b72d4803fe 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -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); 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; }