From d83bdd3389f6c90c0b93676ad2e1252f10dbec48 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Mon, 1 Mar 2021 10:24:14 +0200
Subject: [PATCH 01/20] Base Choose category and Add new category
https://github.com/osmandapp/OsmAnd/issues/10835
---
.../res/layout/add_new_favorite_category.xml | 80 ++++++
...om_sheet_item_with_descr_and_radio_btn.xml | 1 +
OsmAnd/res/values/strings.xml | 1 +
.../osmand/plus/activities/MapActivity.java | 5 +
.../AddNewFavoriteCategoryBottomSheet.java | 231 ++++++++++++++++++
.../editors/PointEditorFragment.java | 7 +-
.../editors/PointEditorFragmentNew.java | 18 +-
.../SelectFavoriteCategoryBottomSheet.java | 208 ++++++++++++++++
8 files changed, 537 insertions(+), 14 deletions(-)
create mode 100644 OsmAnd/res/layout/add_new_favorite_category.xml
create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
create mode 100644 OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
diff --git a/OsmAnd/res/layout/add_new_favorite_category.xml b/OsmAnd/res/layout/add_new_favorite_category.xml
new file mode 100644
index 0000000000..74510f0842
--- /dev/null
+++ b/OsmAnd/res/layout/add_new_favorite_category.xml
@@ -0,0 +1,80 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml b/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml
index a346825302..d4d052c868 100644
--- a/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml
+++ b/OsmAnd/res/layout/bottom_sheet_item_with_descr_and_radio_btn.xml
@@ -9,6 +9,7 @@
+ Select category or add new one
Distance by tap
A toggle to show or hide the Coordinates widget on the map.
Show Coordinates widget
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
index 2273c91742..cc8340e598 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java
@@ -93,6 +93,7 @@ import net.osmand.plus.importfiles.ImportHelper;
import net.osmand.plus.mapcontextmenu.AdditionalActionsBottomSheetDialogFragment;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.mapcontextmenu.builders.cards.dialogs.ContextMenuCardDialogFragment;
+import net.osmand.plus.mapcontextmenu.editors.SelectFavoriteCategoryBottomSheet;
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenu;
import net.osmand.plus.mapmarkers.MapMarker;
@@ -2245,6 +2246,10 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return getFragment(TripRecordingBottomSheet.TAG);
}
+ public SelectFavoriteCategoryBottomSheet getSelectFavoriteCategoryBottomSheet() {
+ return getFragment(SelectFavoriteCategoryBottomSheet.TAG);
+ }
+
public ChooseRouteFragment getChooseRouteFragment() {
return getFragment(ChooseRouteFragment.TAG);
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
new file mode 100644
index 0000000000..5b49efe9ed
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
@@ -0,0 +1,231 @@
+package net.osmand.plus.mapcontextmenu.editors;
+
+import android.content.res.ColorStateList;
+import android.os.Bundle;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+
+import androidx.annotation.ColorInt;
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.app.AlertDialog;
+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.PlatformUtil;
+import net.osmand.plus.FavouritesDbHelper;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+import net.osmand.plus.UiUtilities;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.base.MenuBottomSheetDialogFragment;
+import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
+import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
+import net.osmand.plus.helpers.ColorDialogs;
+import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet;
+import net.osmand.plus.routepreparationmenu.cards.BaseCard;
+import net.osmand.plus.track.ColorsCard;
+import net.osmand.plus.track.CustomColorBottomSheet;
+
+import org.apache.commons.logging.Log;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFragment implements CustomColorBottomSheet.ColorPickerListener, BaseCard.CardListener {
+
+
+ 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";
+ FavouritesDbHelper favoritesHelper;
+ private boolean isGpx;
+ private ArrayList gpxCategories;
+ private int selectedColor;
+ private ColorsCard colorsCard;
+ private TextInputEditText editText;
+ private TextInputLayout nameTextBox;
+ private String folderName;
+ private int defaultColor;
+ private View view;
+ private String editorTag;
+ private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener;
+
+ public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) {
+ if (!fragmentManager.isStateSaved()) {
+ AddNewFavoriteCategoryBottomSheet fragment = new AddNewFavoriteCategoryBottomSheet();
+ fragment.setRetainInstance(true);
+ fragment.setTargetFragment(target, 0);
+ fragment.show(fragmentManager, TAG);
+ }
+ }
+
+ @Override
+ protected int getRightBottomButtonTextId() {
+ return R.string.shared_string_save;
+ }
+
+ private boolean isGpxCategoryExists(@NonNull String name) {
+ boolean res = false;
+ if (gpxCategories != null) {
+ String nameLC = name.toLowerCase();
+ for (String category : gpxCategories) {
+ if (category.toLowerCase().equals(nameLC)) {
+ res = true;
+ break;
+ }
+ }
+ }
+ return res;
+ }
+
+ @Override
+ protected void onRightBottomButtonClick() {
+ String name = editText.getText().toString().trim();
+ FragmentActivity activity = getActivity();
+ if (activity != null) {
+ boolean exists = isGpx ? isGpxCategoryExists(name) : favoritesHelper.groupExists(name);
+ if (exists) {
+ AlertDialog.Builder b = new AlertDialog.Builder(activity);
+ b.setMessage(getString(R.string.favorite_category_dublicate_message));
+ b.setNegativeButton(R.string.shared_string_ok, null);
+ b.show();
+ } else {
+ if (activity instanceof MapActivity) {
+ if (!isGpx) {
+ favoritesHelper.addEmptyCategory(name, selectedColor);
+ }
+ PointEditor editor = ((MapActivity) activity).getContextMenu().getPointEditor(editorTag);
+
+ if (editor != null) {
+ editor.setCategory(name, selectedColor);
+ }
+
+ if (selectionListener != null) {
+ selectionListener.onCategorySelected(name, selectedColor);
+ }
+ }
+ dismiss();
+ }
+ }
+ }
+
+ @Override
+ protected UiUtilities.DialogButtonType getRightBottomButtonType() {
+ return UiUtilities.DialogButtonType.PRIMARY;
+ }
+
+ @Nullable
+ public FavouritesDbHelper getHelper() {
+ return favoritesHelper;
+ }
+
+ @ColorInt
+ public int getCategoryColor(String category) {
+ FavouritesDbHelper helper = getHelper();
+ if (helper != null) {
+ for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
+ if (fg.getDisplayName(getMyApplication()).equals(category)) {
+ return fg.getColor();
+ }
+ }
+ }
+ return defaultColor;
+ }
+
+ @Override
+ public void createMenuItems(Bundle savedInstanceState) {
+ OsmandApplication app = requiredMyApplication();
+ favoritesHelper = app.getFavorites();
+ if (savedInstanceState != null) {
+ folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
+ }
+ items.add(new TitleItem(getString(R.string.favorite_category_add_new_title)));
+ defaultColor = getResources().getColor(R.color.color_favorite);
+ selectedColor = defaultColor;
+
+ view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.add_new_favorite_category, 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(app.getResources().getString(R.string.favorite_category_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(folderName);
+ if (editText.requestFocus()) {
+ getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
+ }
+ nameTextBox.setStartIconTintList(ColorStateList.valueOf(selectedColor));
+ nameTextBox.setBoxStrokeColorStateList(ColorStateList.valueOf(selectedColor));
+ 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) {
+
+ }
+ });
+ BaseBottomSheetItem editFolderName = new BaseBottomSheetItem.Builder()
+ .setCustomView(view)
+ .create();
+ items.add(editFolderName);
+ MapActivity mapActivity = (MapActivity) getActivity();
+ List colors = new ArrayList<>();
+ for (int color : ColorDialogs.pallette) {
+ colors.add(color);
+ }
+ colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors);
+ colorsCard.setListener(this);
+ LinearLayout selectColor = view.findViewById(R.id.select_color);
+ selectColor.addView(colorsCard.build(view.getContext()));
+ }
+
+ private void updateColorSelector(int color) {
+ ((TextView) view.findViewById(R.id.color_name)).setText(ColorDialogs.getColorName(color));
+ selectedColor = color;
+ nameTextBox.setStartIconTintList(ColorStateList.valueOf(selectedColor));
+ nameTextBox.setBoxStrokeColorStateList(ColorStateList.valueOf(selectedColor));
+ }
+
+ @Override
+ public void onCardLayoutNeeded(@NonNull BaseCard card) {
+
+ }
+
+ @Override
+ public void onCardPressed(@NonNull BaseCard card) {
+ if (card instanceof ColorsCard) {
+ int color = ((ColorsCard) card).getSelectedColor();
+ updateColorSelector(color);
+ }
+ }
+
+ @Override
+ public void onCardButtonPressed(@NonNull BaseCard card, int buttonIndex) {
+
+ }
+
+ @Override
+ public void onColorSelected(Integer prevColor, int newColor) {
+ colorsCard.onColorSelected(prevColor, newColor);
+ int color = colorsCard.getSelectedColor();
+ updateColorSelector(color);
+ }
+
+}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
index c24a29ff71..8d118bb7dc 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
@@ -24,6 +24,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
@@ -136,9 +137,9 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
@Override
public boolean onTouch(final View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
- DialogFragment dialogFragment = createSelectCategoryDialog();
- if (dialogFragment != null) {
- dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG);
+ FragmentManager fragmentManager = getFragmentManager();
+ if (fragmentManager != null) {
+ SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment());
}
return true;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
index e59ce02373..6f50d80214 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
@@ -38,6 +38,7 @@ import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
@@ -190,9 +191,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
groupList.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- DialogFragment dialogFragment = createSelectCategoryDialog();
- if (dialogFragment != null) {
- dialogFragment.show(getChildFragmentManager(), SelectCategoryDialogFragment.TAG);
+ FragmentManager fragmentManager = getFragmentManager();
+ if (fragmentManager != null) {
+ SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment());
}
}
});
@@ -887,8 +888,6 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
return true;
}
- ;
-
String getNameTextValue() {
EditText nameEdit = view.findViewById(R.id.name_edit);
return nameEdit.getText().toString().trim();
@@ -1006,12 +1005,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
holder.groupButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- PointEditor editor = getEditor();
- if (editor != null) {
- EditCategoryDialogFragment dialogFragment =
- EditCategoryDialogFragment.createInstance(editor.getFragmentTag(), getCategories(),
- !editor.getFragmentTag().equals(FavoritePointEditor.TAG));
- dialogFragment.show(requireActivity().getSupportFragmentManager(), EditCategoryDialogFragment.TAG);
+ FragmentManager fragmentManager = getFragmentManager();
+ if (fragmentManager != null) {
+ SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment());
}
}
});
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
new file mode 100644
index 0000000000..131f10da71
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -0,0 +1,208 @@
+package net.osmand.plus.mapcontextmenu.editors;
+
+import android.app.Activity;
+import android.graphics.PorterDuff;
+import android.graphics.Typeface;
+import android.graphics.drawable.Drawable;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.LinearLayout;
+import android.widget.RadioButton;
+import android.widget.TextView;
+
+import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
+import androidx.appcompat.content.res.AppCompatResources;
+import androidx.appcompat.widget.AppCompatImageView;
+import androidx.core.content.ContextCompat;
+import androidx.core.graphics.drawable.DrawableCompat;
+import androidx.fragment.app.Fragment;
+import androidx.fragment.app.FragmentActivity;
+import androidx.fragment.app.FragmentManager;
+
+import net.osmand.GPXUtilities;
+import net.osmand.plus.FavouritesDbHelper;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+import net.osmand.plus.UiUtilities;
+import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.base.MenuBottomSheetDialogFragment;
+import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
+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 java.util.List;
+import java.util.Map;
+
+public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFragment {
+
+ public static final String TAG = SelectFavoriteCategoryBottomSheet.class.getSimpleName();
+ private OsmandApplication app;
+ private GPXUtilities.GPXFile gpxFile;
+ private String editorTag;
+ private Map gpxCategories;
+ private SelectCategoryDialogFragment.CategorySelectionListener selectionListener;
+
+ public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) {
+ if (!fragmentManager.isStateSaved()) {
+ SelectFavoriteCategoryBottomSheet fragment = new SelectFavoriteCategoryBottomSheet();
+ fragment.setRetainInstance(true);
+ fragment.setTargetFragment(target, 0);
+ fragment.show(fragmentManager, TAG);
+ }
+ }
+
+ private static Drawable getIcon(final Activity activity, int iconId) {
+ OsmandApplication app = (OsmandApplication) activity.getApplication();
+ UiUtilities iconsCache = app.getUIUtilities();
+ boolean light = app.getSettings().isLightContent();
+ return iconsCache.getIcon(iconId,
+ light ? R.color.icon_color_default_light : R.color.icon_color_default_dark);
+ }
+
+ private static Drawable getIcon(final Activity activity, int resId, int color) {
+ Drawable drawable = AppCompatResources.getDrawable(activity, resId);
+ if (drawable != null) {
+ drawable = DrawableCompat.wrap(drawable).mutate();
+ drawable.clearColorFilter();
+ drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
+ }
+ return drawable;
+ }
+
+
+ public GPXUtilities.GPXFile getGpxFile() {
+ return gpxFile;
+ }
+
+ public void setGpxFile(GPXUtilities.GPXFile gpxFile) {
+ this.gpxFile = gpxFile;
+ }
+
+ public void setGpxCategories(Map gpxCategories) {
+ this.gpxCategories = gpxCategories;
+ }
+
+ @Override
+ public void createMenuItems(Bundle savedInstanceState) {
+ app = requiredMyApplication();
+
+ BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder()
+ .setDescription(getString(R.string.select_category_descr))
+ .setTitle(getString(R.string.favorite_category_select))
+ .setLayoutId(R.layout.bottom_sheet_item_title_with_description)
+ .create();
+ items.add(titleItem);
+ final FragmentActivity activity = requireActivity();
+
+ View addNewCategoryView = UiUtilities.getInflater(app, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_64dp, null);
+ addNewCategoryView.setMinimumHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_list_item_height));
+ TextView title = addNewCategoryView.findViewById(R.id.title);
+ Typeface face = Typeface.createFromAsset(app.getAssets(),
+ "fonts/Roboto-Medium.ttf");
+ title.setTypeface(face);
+ AndroidUiHelper.updateVisibility(addNewCategoryView.findViewById(R.id.description), false);
+ BaseBottomSheetItem addNewFolderItem = new SimpleBottomSheetItem.Builder()
+ .setTitle(getString(R.string.favorite_category_add_new))
+ .setTitleColorId(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light)
+ .setIcon(getActiveIcon(R.drawable.ic_action_folder_add))
+ .setLayoutId(R.layout.bottom_sheet_item_with_descr_64dp)
+ .setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ AddNewFavoriteCategoryBottomSheet.showInstance(getFragmentManager(), getTargetFragment());
+ dismiss();
+ }
+ })
+ .setCustomView(addNewCategoryView)
+ .create();
+ items.add(addNewFolderItem);
+
+ DividerItem dividerItem = new DividerItem(app);
+ dividerItem.setMargins(0, 0, 0, 0);
+ items.add(dividerItem);
+
+ View favoriteCategoryList = UiUtilities.getInflater(app, nightMode).inflate(R.layout.favorite_categories_dialog, null);
+ LinearLayout favoriteCategoryContainer = favoriteCategoryList.findViewById(R.id.list_container);
+
+ final FavouritesDbHelper helper2 = app.getFavorites();
+ if (gpxFile != null) {
+ if (gpxCategories != null) {
+ for (Map.Entry e : gpxCategories.entrySet()) {
+ String categoryName = e.getKey();
+ int favoriteCategoryCount = e.getKey().length();
+ favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue(), favoriteCategoryCount, false, true));
+ }
+ }
+ } else {
+ List gs = helper2.getFavoriteGroups();
+ for (final FavouritesDbHelper.FavoriteGroup category : gs) {
+ int favoriteCategoryCount = category.getPoints().size();
+ favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
+ category.getColor(), favoriteCategoryCount, !category.isVisible(), true));
+ }
+
+ items.add(new BaseBottomSheetItem.Builder()
+ .setCustomView(favoriteCategoryList)
+ .create());
+ }
+ }
+
+ private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden, final boolean selected) {
+ View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
+ final AppCompatImageView button = (AppCompatImageView) itemView.findViewById(R.id.icon);
+ LinearLayout test = itemView.findViewById(R.id.descriptionContainer);
+ test.setPadding(0, 0, 0, 0);
+ View divider = itemView.findViewById(R.id.divider_bottom);
+ divider.setVisibility(View.GONE);
+ itemView.setPadding(0, 0, 0, 0);
+ final RadioButton compoundButton = itemView.findViewById(R.id.compound_button);
+ int activeColorId = nightMode ?
+ R.color.active_color_primary_dark : R.color.active_color_primary_light;
+ int disableColorId = nightMode ?
+ R.color.icon_color_default_dark : R.color.icon_color_default_light;
+ UiUtilities.setupCompoundButton(nightMode, ContextCompat.getColor(app,
+ nightMode ? activeColorId : disableColorId), compoundButton);
+
+ if (isHidden) {
+ button.setImageResource(R.drawable.ic_action_hide);
+ } else {
+ if (categoryColor != 0) {
+ button.setImageDrawable(getIcon(activity, R.drawable.ic_action_folder, categoryColor));
+ } else {
+ button.setImageDrawable(getIcon(activity, R.drawable.ic_action_folder, ContextCompat.getColor(activity,
+ gpxFile != null ? R.color.gpx_color_point : R.color.color_favorite)));
+ }
+ }
+ String name = categoryName.length() == 0 ? getString(R.string.shared_string_favorites) : categoryName;
+ TextView text = itemView.findViewById(R.id.title);
+ TextView description = itemView.findViewById(R.id.description);
+ text.setText(name);
+ description.setText(String.valueOf(categoryPointCount));
+ test.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View v) {
+ FragmentActivity a = getActivity();
+ compoundButton.setSelected(true);
+ if (a instanceof MapActivity) {
+ PointEditor pointEditor = ((MapActivity) a).getContextMenu().getPointEditor(editorTag);
+ if (pointEditor != null) {
+ pointEditor.setCategory(categoryName, categoryColor);
+ }
+ if (selectionListener != null) {
+ selectionListener.onCategorySelected(categoryName, categoryColor);
+ }
+ }
+ dismiss();
+ }
+ });
+ return itemView;
+ }
+
+ public interface CategorySelectionListener {
+
+ void onCategorySelected(String category, int color);
+ }
+}
From 04e90d52845f1b5bd4877825e3d3705db8721b65 Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Mon, 1 Mar 2021 11:46:46 +0200
Subject: [PATCH 02/20] Fix share menu translation
---
OsmAnd/res/values/strings.xml | 1 +
OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java | 2 +-
2 files changed, 2 insertions(+), 1 deletion(-)
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index ed1259ed1f..ccc1ac5617 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -12,6 +12,7 @@
-->
+ Copy POI name
The recording will be continued.
Distance by tap
A toggle to show or hide the Coordinates widget on the map.
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java
index 53384024ff..5d040765b6 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/ShareMenu.java
@@ -38,7 +38,7 @@ public class ShareMenu extends BaseMenuController {
MESSAGE(R.drawable.ic_action_message, R.string.shared_string_send),
CLIPBOARD(R.drawable.ic_action_copy, R.string.shared_string_copy),
ADDRESS(R.drawable.ic_action_street_name, R.string.copy_address),
- NAME(R.drawable.ic_action_copy, R.string.copy_location_name),
+ NAME(R.drawable.ic_action_copy, R.string.copy_poi_name),
COORDINATES(R.drawable.ic_action_copy, R.string.copy_coordinates),
GEO(R.drawable.ic_world_globe_dark, R.string.share_geo),
QR_CODE(R.drawable.ic_action_qrcode, R.string.shared_string_qr_code);
From 0bc9c0cb48f12cc412b110838a0b247adfeab4b0 Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Mon, 1 Mar 2021 11:53:16 +0200
Subject: [PATCH 03/20] Move GPXRouteParams and RouteService to separate
classes
---
.../net/osmand/plus/GpxSelectionHelper.java | 4 +-
.../osmand/plus/OsmAndLocationSimulation.java | 2 +-
.../net/osmand/plus/TargetPointsHelper.java | 2 +-
.../plus/activities/MapActivityActions.java | 2 +-
.../osmand/plus/base/FailSafeFuntions.java | 2 +-
.../other/RoutePreferencesMenu.java | 6 +-
.../MeasurementToolFragment.java | 2 +-
.../ChooseRouteFragment.java | 2 +-
.../FollowTrackFragment.java | 6 +-
.../MapRouteInfoMenu.java | 2 +-
.../RouteOptionsBottomSheet.java | 11 +-
.../RoutingOptionsHelper.java | 24 +-
.../cards/TrackEditCard.java | 2 +-
.../osmand/plus/routing/GPXRouteParams.java | 221 +++++++++++++
.../osmand/plus/routing/GpxApproximator.java | 1 -
.../plus/routing/RouteCalculationParams.java | 1 -
.../plus/routing/RouteCalculationResult.java | 1 -
.../osmand/plus/routing/RouteProvider.java | 293 +-----------------
.../routing/RouteRecalculationHelper.java | 5 +-
.../net/osmand/plus/routing/RouteService.java | 45 +++
.../plus/routing/RoutingEnvironment.java | 36 +++
.../osmand/plus/routing/RoutingHelper.java | 8 +-
.../plus/routing/TransportRoutingHelper.java | 1 -
.../settings/backend/ApplicationMode.java | 2 +-
.../plus/settings/backend/OsmandSettings.java | 2 +-
.../fragments/NavigationFragment.java | 13 +-
.../fragments/ProfileAppearanceFragment.java | 4 +-
.../fragments/RouteParametersFragment.java | 7 +-
.../fragments/VehicleParametersFragment.java | 3 +-
.../osmand/plus/track/TrackMenuFragment.java | 4 +-
.../osmand/plus/views/layers/RouteLayer.java | 6 +-
31 files changed, 370 insertions(+), 350 deletions(-)
create mode 100644 OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
create mode 100644 OsmAnd/src/net/osmand/plus/routing/RouteService.java
create mode 100644 OsmAnd/src/net/osmand/plus/routing/RoutingEnvironment.java
diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
index 69c159bed0..10a8c2ae84 100644
--- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
+++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java
@@ -30,7 +30,7 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.mapmarkers.MapMarkersGroup;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
-import net.osmand.plus.routing.RouteProvider;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.track.GpxSplitType;
import net.osmand.util.Algorithms;
@@ -928,7 +928,7 @@ public class GpxSelectionHelper {
}
public boolean isFollowTrack(OsmandApplication app) {
- RouteProvider.GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
+ GPXRouteParamsBuilder routeParams = app.getRoutingHelper().getCurrentGPXRoute();
if (routeParams != null) {
return gpxFile.path.equals(routeParams.getFile().path);
}
diff --git a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java
index 0b2683fcc6..1ecda23e78 100644
--- a/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java
+++ b/OsmAnd/src/net/osmand/plus/OsmAndLocationSimulation.java
@@ -18,7 +18,7 @@ import net.osmand.GPXUtilities;
import net.osmand.Location;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.settings.backend.ApplicationMode;
import java.util.ArrayList;
diff --git a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java
index 472899862b..bd77ebf33b 100644
--- a/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java
+++ b/OsmAnd/src/net/osmand/plus/TargetPointsHelper.java
@@ -10,7 +10,7 @@ import net.osmand.data.LatLon;
import net.osmand.data.LocationPoint;
import net.osmand.data.PointDescription;
import net.osmand.plus.GeocodingLookupService.AddressLookupRequest;
-import net.osmand.plus.routing.RouteProvider.RouteService;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelperUtils;
import net.osmand.plus.settings.backend.ApplicationMode;
diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
index 2bb6f5caec..e2bec6f7b5 100644
--- a/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
+++ b/OsmAnd/src/net/osmand/plus/activities/MapActivityActions.java
@@ -69,7 +69,7 @@ import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
diff --git a/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java b/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java
index 46708ce5ae..26fe55e1e8 100644
--- a/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java
+++ b/OsmAnd/src/net/osmand/plus/base/FailSafeFuntions.java
@@ -18,7 +18,7 @@ import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.activities.MapActivity;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java
index 005433cbe2..897de79b6c 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java
@@ -36,7 +36,7 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.LocalRoutingPar
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.MuteSoundRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.OtherSettingsRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.VoiceGuidanceRoutingParameter;
-import net.osmand.plus.routing.RouteProvider;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -373,13 +373,13 @@ public class RoutePreferencesMenu {
}
private void updateSpinnerItems(final TextView gpxSpinner) {
- RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
+ GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
gpxSpinner.setText(rp == null ? mapActivity.getString(R.string.shared_string_none) :
new File(rp.getFile().path).getName());
}
private void showOptionsMenu(final TextView gpxSpinner) {
- RouteProvider.GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
+ GPXRouteParamsBuilder rp = mapActivity.getRoutingHelper().getCurrentGPXRoute();
final PopupMenu optionsMenu = new PopupMenu(gpxSpinner.getContext(), gpxSpinner);
MenuItem item = optionsMenu.getMenu().add(
mapActivity.getString(R.string.shared_string_none));
diff --git a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
index bf6ee212dc..e654dc33b2 100644
--- a/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
+++ b/OsmAnd/src/net/osmand/plus/measurementtool/MeasurementToolFragment.java
@@ -2073,7 +2073,7 @@ public class MeasurementToolFragment extends BaseOsmAndFragment implements Route
private void startTrackNavigation() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
- if (editingCtx.hasRoute()) {
+ if (editingCtx.hasRoute() || editingCtx.hasChanges()) {
String trackName = getSuggestedFileName();
GPXFile gpx = editingCtx.exportGpx(trackName);
if (gpx != null) {
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java
index 89afe180e2..e75efb2c25 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/ChooseRouteFragment.java
@@ -58,7 +58,7 @@ import net.osmand.plus.routepreparationmenu.RouteDetailsFragment.CumulativeInfo;
import net.osmand.plus.routepreparationmenu.RouteDetailsFragment.RouteDetailsFragmentListener;
import net.osmand.plus.routepreparationmenu.cards.PublicTransportCard;
import net.osmand.plus.routing.RouteDirectionInfo;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.settings.backend.OsmandSettings;
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java
index 93b26b82a4..b5abb80b65 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/FollowTrackFragment.java
@@ -58,8 +58,8 @@ import net.osmand.plus.routepreparationmenu.cards.SelectTrackCard;
import net.osmand.plus.routepreparationmenu.cards.TrackEditCard;
import net.osmand.plus.routepreparationmenu.cards.TracksToFollowCard;
import net.osmand.plus.routing.IRouteInformationListener;
-import net.osmand.plus.routing.RouteProvider;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet;
@@ -224,7 +224,7 @@ public class FollowTrackFragment extends ContextMenuScrollFragment implements Ca
RoutingHelper routingHelper = app.getRoutingHelper();
GPXRouteParamsBuilder rparams = routingHelper.getCurrentGPXRoute();
- boolean osmandRouter = mode.getRouteService() == RouteProvider.RouteService.OSMAND;
+ boolean osmandRouter = mode.getRouteService() == RouteService.OSMAND;
if (rparams != null && osmandRouter) {
cardsContainer.addView(buildDividerView(cardsContainer, false));
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java
index f88f499125..2475d70f34 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/MapRouteInfoMenu.java
@@ -100,7 +100,7 @@ import net.osmand.plus.routepreparationmenu.cards.SimpleRouteCard;
import net.osmand.plus.routepreparationmenu.cards.TracksCard;
import net.osmand.plus.routing.IRouteInformationListener;
import net.osmand.plus.routing.RouteCalculationResult;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelperUtils;
import net.osmand.plus.routing.TransportRoutingHelper;
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java
index 8ba86dfe35..4275be99a6 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RouteOptionsBottomSheet.java
@@ -46,7 +46,8 @@ import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.OtherSettingsRo
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.RouteSimulationItem;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.ShowAlongTheRouteItem;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.TimeConditionalRoutingItem;
-import net.osmand.plus.routing.RouteProvider;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.CommonPreference;
@@ -501,7 +502,7 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
}
private BaseBottomSheetItem createGpxRoutingItem(final LocalRoutingParameter optionsItem) {
- RouteProvider.GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute();
+ GPXRouteParamsBuilder routeParamsBuilder = mapActivity.getRoutingHelper().getCurrentGPXRoute();
String description = null;
int descriptionColorId;
if (routeParamsBuilder == null) {
@@ -661,11 +662,11 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private List getRoutingParameters(ApplicationMode applicationMode) {
List routingParameters;
- boolean osmandRouter = applicationMode.getRouteService() == RouteProvider.RouteService.OSMAND;
+ boolean osmandRouter = applicationMode.getRouteService() == RouteService.OSMAND;
if (!osmandRouter) {
- if (applicationMode.getRouteService() == RouteProvider.RouteService.STRAIGHT) {
+ if (applicationMode.getRouteService() == RouteService.STRAIGHT) {
routingParameters = AppModeOptions.STRAIGHT.routingParameters;
- } else if (applicationMode.getRouteService() == RouteProvider.RouteService.DIRECT_TO) {
+ } else if (applicationMode.getRouteService() == RouteService.DIRECT_TO) {
routingParameters = AppModeOptions.DIRECT_TO.routingParameters;
} else {
routingParameters = AppModeOptions.OTHER.routingParameters;
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java
index 72e985c353..d03973a796 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java
@@ -37,9 +37,8 @@ import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.download.DownloadActivity;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.helpers.FileNameTranslationHelper;
-import net.osmand.plus.routing.RouteProvider;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
-import net.osmand.plus.routing.RouteProvider.RouteService;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.voice.JSMediaCommandPlayerImpl;
@@ -243,24 +242,25 @@ public class RoutingOptionsHelper {
TargetPointsHelper tg = app.getTargetPointsHelper();
List ps = rp.getPoints(app);
if (ps.size() > 0) {
+ TargetPoint pointToStart = tg.getPointToStart();
+ TargetPoint pointToNavigate = tg.getPointToNavigate();
if (rp.getFile().hasRoute()) {
tg.clearStartPoint(false);
Location finishLoc = ps.get(ps.size() - 1);
- TargetPoint pn = tg.getPointToNavigate();
- tg.navigateToPoint(new LatLon(finishLoc.getLatitude(), finishLoc.getLongitude()), false, -1, pn != null ? pn.getOriginalPointDescription() : null);
+ tg.navigateToPoint(new LatLon(finishLoc.getLatitude(), finishLoc.getLongitude()),
+ false, -1, pointToNavigate != null ? pointToNavigate.getOriginalPointDescription() : null);
tg.updateRouteAndRefresh(true);
} else {
Location first = ps.get(0);
Location end = ps.get(ps.size() - 1);
- TargetPoint pn = tg.getPointToNavigate();
boolean update = false;
- if (pn == null
- || MapUtils.getDistance(pn.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) {
+ if (pointToNavigate == null
+ || MapUtils.getDistance(pointToNavigate.point, new LatLon(first.getLatitude(), first.getLongitude())) < 10) {
tg.navigateToPoint(new LatLon(end.getLatitude(), end.getLongitude()), false, -1);
update = true;
}
- if (tg.getPointToStart() == null
- || MapUtils.getDistance(tg.getPointToStart().point,
+ if (pointToStart == null
+ || MapUtils.getDistance(pointToStart.point,
new LatLon(end.getLatitude(), end.getLongitude())) < 10) {
tg.setStartPoint(new LatLon(first.getLatitude(), first.getLongitude()), false, null);
update = true;
@@ -490,7 +490,7 @@ public class RoutingOptionsHelper {
}
public List getRoutingParametersInner(ApplicationMode am) {
- boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
+ boolean osmandRouter = am.getRouteService() == RouteService.OSMAND;
if (!osmandRouter) {
return getOsmandRouterParameters(am);
}
@@ -1061,7 +1061,7 @@ public class RoutingOptionsHelper {
private List getRoutingParametersForProfileType(ApplicationMode appMode) {
if (appMode != null) {
- boolean osmandRouter = appMode.getRouteService() == RouteProvider.RouteService.OSMAND;
+ boolean osmandRouter = appMode.getRouteService() == RouteService.OSMAND;
if (!osmandRouter) {
return PermanentAppModeOptions.OTHER.routingParameters;
} else if (appMode.isDerivedRoutingFrom(ApplicationMode.CAR)) {
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java
index 646e2da386..e924b46aba 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/cards/TrackEditCard.java
@@ -20,7 +20,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXInfo;
import net.osmand.plus.helpers.TrackSelectSegmentAdapter;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.util.Algorithms;
import java.io.File;
diff --git a/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java b/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
new file mode 100644
index 0000000000..f62c686d3c
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
@@ -0,0 +1,221 @@
+package net.osmand.plus.routing;
+
+import net.osmand.GPXUtilities.GPXFile;
+import net.osmand.GPXUtilities.Route;
+import net.osmand.GPXUtilities.TrkSegment;
+import net.osmand.GPXUtilities.WptPt;
+import net.osmand.Location;
+import net.osmand.PlatformUtil;
+import net.osmand.data.LatLon;
+import net.osmand.data.LocationPoint;
+import net.osmand.data.WptLocationPoint;
+import net.osmand.plus.OsmandApplication;
+import net.osmand.plus.R;
+import net.osmand.plus.settings.backend.OsmandSettings;
+import net.osmand.router.RouteSegmentResult;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import static net.osmand.router.RouteExporter.OSMAND_ROUTER_V2;
+
+public class GPXRouteParams {
+
+ private static final String OSMAND_ROUTER = "OsmAndRouter";
+
+ protected List wpt;
+ protected List route;
+ protected List directions;
+ protected List points = new ArrayList<>();
+ protected List routePoints = new ArrayList<>();
+ protected boolean reverse;
+ protected boolean passWholeRoute;
+ protected boolean calculateOsmAndRoute;
+ protected boolean useIntermediatePointsRTE;
+ protected boolean calculateOsmAndRouteParts;
+
+ boolean addMissingTurns = true;
+
+ public List getPoints() {
+ return points;
+ }
+
+ public List getWpt() {
+ return wpt;
+ }
+
+ public Location getStartPointForRoute() {
+ if (!points.isEmpty()) {
+ return points.get(0);
+ }
+ return null;
+ }
+
+ public Location getEndPointForRoute() {
+ if (!points.isEmpty()) {
+ return points.get(points.size());
+ }
+ return null;
+ }
+
+ public LatLon getLastPoint() {
+ if (!points.isEmpty()) {
+ Location l = points.get(points.size() - 1);
+ return new LatLon(l.getLatitude(), l.getLongitude());
+ }
+ return null;
+ }
+
+ public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder) {
+ GPXFile file = builder.file;
+ reverse = builder.reverse;
+ passWholeRoute = builder.passWholeRoute;
+ calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts;
+ useIntermediatePointsRTE = builder.isUseIntermediatePointsRTE();
+ builder.calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
+ if (!file.isPointsEmpty()) {
+ wpt = new ArrayList(file.getPoints().size());
+ for (WptPt w : file.getPoints()) {
+ wpt.add(new WptLocationPoint(w));
+ }
+ }
+ int selectedSegment = builder.getSelectedSegment();
+ if (OSMAND_ROUTER_V2.equals(file.author)) {
+ route = RouteProvider.parseOsmAndGPXRoute(points, file, selectedSegment);
+ if (selectedSegment == -1) {
+ routePoints = file.getRoutePoints();
+ } else {
+ routePoints = file.getRoutePoints(selectedSegment);
+ }
+ if (reverse) {
+ Collections.reverse(points);
+ Collections.reverse(routePoints);
+ }
+ addMissingTurns = route != null && route.isEmpty();
+ } else if (file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)) {
+ directions = RouteProvider.parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10, selectedSegment);
+ if (OSMAND_ROUTER.equals(file.author) && file.hasRtePt()) {
+ // For files generated by OSMAND_ROUTER use directions contained unaltered
+ addMissingTurns = false;
+ }
+ if (reverse) {
+ // clear directions all turns should be recalculated
+ directions = null;
+ Collections.reverse(points);
+ addMissingTurns = true;
+ }
+ } else {
+ // first of all check tracks
+ if (!useIntermediatePointsRTE) {
+ List segments = file.getNonEmptyTrkSegments(false);
+ if (selectedSegment != -1 && segments.size() > selectedSegment) {
+ TrkSegment segment = segments.get(selectedSegment);
+ for (WptPt p : segment.points) {
+ points.add(RouteProvider.createLocation(p));
+ }
+ } else {
+ for (TrkSegment tkSeg : segments) {
+ for (WptPt p : tkSeg.points) {
+ points.add(RouteProvider.createLocation(p));
+ }
+ }
+ }
+ }
+ if (points.isEmpty()) {
+ for (Route rte : file.routes) {
+ for (WptPt pt : rte.points) {
+ points.add(RouteProvider.createLocation(pt));
+ }
+ }
+ }
+ if (reverse) {
+ Collections.reverse(points);
+ }
+ }
+ return this;
+ }
+
+ public static class GPXRouteParamsBuilder {
+
+ private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(GPXRouteParamsBuilder.class);
+
+ boolean calculateOsmAndRoute = false;
+ // parameters
+ private final GPXFile file;
+ private boolean reverse;
+ private boolean leftSide;
+ private boolean passWholeRoute;
+ private boolean calculateOsmAndRouteParts;
+ private int selectedSegment = -1;
+
+ public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings) {
+ leftSide = settings.DRIVING_REGION.get().leftHandDriving;
+ this.file = file;
+ }
+
+ public boolean isReverse() {
+ return reverse;
+ }
+
+ public boolean isCalculateOsmAndRouteParts() {
+ return calculateOsmAndRouteParts;
+ }
+
+ public void setCalculateOsmAndRouteParts(boolean calculateOsmAndRouteParts) {
+ this.calculateOsmAndRouteParts = calculateOsmAndRouteParts;
+ }
+
+ public boolean isUseIntermediatePointsRTE() {
+ return file.hasRtePt() && !file.hasTrkPt();
+ }
+
+ public boolean isCalculateOsmAndRoute() {
+ return calculateOsmAndRoute;
+ }
+
+ public void setCalculateOsmAndRoute(boolean calculateOsmAndRoute) {
+ this.calculateOsmAndRoute = calculateOsmAndRoute;
+ }
+
+ public int getSelectedSegment() {
+ return selectedSegment;
+ }
+
+ public void setSelectedSegment(int selectedSegment) {
+ this.selectedSegment = selectedSegment;
+ }
+
+ public void setPassWholeRoute(boolean passWholeRoute) {
+ this.passWholeRoute = passWholeRoute;
+ }
+
+ public boolean isPassWholeRoute() {
+ return passWholeRoute;
+ }
+
+ public GPXRouteParams build(OsmandApplication app) {
+ GPXRouteParams res = new GPXRouteParams();
+ try {
+ res.prepareGPXFile(this);
+ } catch (RuntimeException e) {
+ log.error(e.getMessage(), e);
+ app.showShortToastMessage(app.getString(R.string.gpx_parse_error) + " " + e.getMessage());
+ }
+ return res;
+ }
+
+ public void setReverse(boolean reverse) {
+ this.reverse = reverse;
+ }
+
+ public GPXFile getFile() {
+ return file;
+ }
+
+ public List getPoints(OsmandApplication app) {
+ GPXRouteParams copy = build(app);
+ return copy.getPoints();
+ }
+ }
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java b/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java
index 65e683a734..ca10de2812 100644
--- a/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java
+++ b/OsmAnd/src/net/osmand/plus/routing/GpxApproximator.java
@@ -7,7 +7,6 @@ import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.routing.RouteProvider.RoutingEnvironment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.router.RouteCalculationProgress;
import net.osmand.router.RoutePlannerFrontEnd.GpxPoint;
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java
index 7b38b5c91a..0c4f2a4cb6 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationParams.java
@@ -4,7 +4,6 @@ import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmandApplication;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParams;
import net.osmand.router.RouteCalculationProgress;
import java.util.List;
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java
index e6efcc321f..a174c1550c 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java
@@ -15,7 +15,6 @@ import net.osmand.data.QuadRect;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.routing.AlarmInfo.AlarmInfoType;
-import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.router.ExitInfo;
import net.osmand.router.RouteSegmentResult;
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index 3f0a30c99f..042db089bb 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -1,7 +1,6 @@
package net.osmand.plus.routing;
-import android.content.Context;
import android.os.Bundle;
import android.util.Base64;
@@ -16,8 +15,6 @@ import net.osmand.PlatformUtil;
import net.osmand.ResultMatcher;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.LatLon;
-import net.osmand.data.LocationPoint;
-import net.osmand.data.WptLocationPoint;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper;
@@ -70,279 +67,14 @@ import javax.xml.parsers.ParserConfigurationException;
import btools.routingapp.IBRouterService;
-import static net.osmand.router.RouteExporter.OSMAND_ROUTER_V2;
-
public class RouteProvider {
+
private static final org.apache.commons.logging.Log log = PlatformUtil.getLog(RouteProvider.class);
- private static final String OSMAND_ROUTER = "OsmAndRouter";
private static final int MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT = 60;
private static final int ADDITIONAL_DISTANCE_FOR_START_POINT = 300;
private static final int MIN_STRAIGHT_DIST = 50000;
- public enum RouteService {
- OSMAND("OsmAnd (offline)"),
- BROUTER("BRouter (offline)"),
- STRAIGHT("Straight line"),
- DIRECT_TO("Direct To"),
- ONLINE("Online engine");
-
- private final String name;
-
- RouteService(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- public boolean isOnline() {
- return this != OSMAND && this != BROUTER;
- }
-
- boolean isAvailable(OsmandApplication ctx) {
- if (this == BROUTER) {
- return ctx.getBRouterService() != null;
- }
- return true;
- }
-
- public static RouteService[] getAvailableRouters(OsmandApplication ctx) {
- List list = new ArrayList<>();
- for (RouteService r : values()) {
- if (r.isAvailable(ctx)) {
- list.add(r);
- }
- }
- return list.toArray(new RouteService[0]);
- }
- }
-
- public static class RoutingEnvironment {
- private RoutePlannerFrontEnd router;
- private RoutingContext ctx;
- private RoutingContext complexCtx;
- private PrecalculatedRouteDirection precalculated;
-
- public RoutingEnvironment(RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, PrecalculatedRouteDirection precalculated) {
- this.router = router;
- this.ctx = ctx;
- this.complexCtx = complexCtx;
- this.precalculated = precalculated;
- }
-
- public RoutePlannerFrontEnd getRouter() {
- return router;
- }
-
- public RoutingContext getCtx() {
- return ctx;
- }
-
- public RoutingContext getComplexCtx() {
- return complexCtx;
- }
-
- public PrecalculatedRouteDirection getPrecalculated() {
- return precalculated;
- }
- }
-
- public RouteProvider() {
- }
-
- public static class GPXRouteParamsBuilder {
- boolean calculateOsmAndRoute = false;
- // parameters
- private final GPXFile file;
- private boolean reverse;
- private boolean leftSide;
- private boolean passWholeRoute;
- private boolean calculateOsmAndRouteParts;
- private int selectedSegment = -1;
-
- public GPXRouteParamsBuilder(GPXFile file, OsmandSettings settings) {
- leftSide = settings.DRIVING_REGION.get().leftHandDriving;
- this.file = file;
- }
-
- public boolean isReverse() {
- return reverse;
- }
-
- public boolean isCalculateOsmAndRouteParts() {
- return calculateOsmAndRouteParts;
- }
-
- public void setCalculateOsmAndRouteParts(boolean calculateOsmAndRouteParts) {
- this.calculateOsmAndRouteParts = calculateOsmAndRouteParts;
- }
-
- public boolean isUseIntermediatePointsRTE() {
- return file.hasRtePt() && !file.hasTrkPt();
- }
-
- public boolean isCalculateOsmAndRoute() {
- return calculateOsmAndRoute;
- }
-
- public void setCalculateOsmAndRoute(boolean calculateOsmAndRoute) {
- this.calculateOsmAndRoute = calculateOsmAndRoute;
- }
-
- public int getSelectedSegment() {
- return selectedSegment;
- }
-
- public void setSelectedSegment(int selectedSegment) {
- this.selectedSegment = selectedSegment;
- }
-
- public void setPassWholeRoute(boolean passWholeRoute) {
- this.passWholeRoute = passWholeRoute;
- }
-
- public boolean isPassWholeRoute() {
- return passWholeRoute;
- }
-
- public GPXRouteParams build(OsmandApplication app) {
- GPXRouteParams res = new GPXRouteParams();
- try {
- res.prepareGPXFile(this);
- } catch (RuntimeException e) {
- log.error(e.getMessage(), e);
- app.showShortToastMessage(app.getString(R.string.gpx_parse_error) + " " + e.getMessage());
- }
- return res;
- }
-
- public void setReverse(boolean reverse) {
- this.reverse = reverse;
- }
-
- public GPXFile getFile() {
- return file;
- }
-
- public List getPoints(OsmandApplication app) {
- GPXRouteParams copy = build(app);
- return copy.getPoints();
- }
- }
-
- public static class GPXRouteParams {
- List points = new ArrayList<>();
- List directions;
- List route;
- List routePoints = new ArrayList<>();
- boolean reverse;
- boolean calculateOsmAndRoute;
- boolean passWholeRoute;
- boolean calculateOsmAndRouteParts;
- boolean useIntermediatePointsRTE;
- private List wpt;
-
- boolean addMissingTurns = true;
-
- public List getPoints() {
- return points;
- }
-
- public Location getStartPointForRoute(){
- if(!points.isEmpty()){
- return points.get(0);
- }
- return null;
- }
-
- public Location getEndPointForRoute(){
- if(!points.isEmpty()){
- return points.get(points.size());
- }
- return null;
- }
-
- public LatLon getLastPoint() {
- if(!points.isEmpty()){
- Location l = points.get(points.size() - 1);
- LatLon point = new LatLon(l.getLatitude(), l.getLongitude());
- return point;
- }
- return null;
- }
-
- public GPXRouteParams prepareGPXFile(GPXRouteParamsBuilder builder) {
- GPXFile file = builder.file;
- reverse = builder.reverse;
- passWholeRoute = builder.passWholeRoute;
- calculateOsmAndRouteParts = builder.calculateOsmAndRouteParts;
- useIntermediatePointsRTE = builder.isUseIntermediatePointsRTE();
- builder.calculateOsmAndRoute = false; // Disabled temporary builder.calculateOsmAndRoute;
- if (!file.isPointsEmpty()) {
- wpt = new ArrayList(file.getPoints().size());
- for(WptPt w : file.getPoints()) {
- wpt.add(new WptLocationPoint(w));
- }
- }
- int selectedSegment = builder.getSelectedSegment();
- if (OSMAND_ROUTER_V2.equals(file.author)) {
- route = parseOsmAndGPXRoute(points, file, selectedSegment);
- if (selectedSegment == -1) {
- routePoints = file.getRoutePoints();
- } else {
- routePoints = file.getRoutePoints(selectedSegment);
- }
- if (reverse) {
- Collections.reverse(points);
- Collections.reverse(routePoints);
- }
- addMissingTurns = route != null && route.isEmpty();
- } else if (file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)) {
- directions = parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10, selectedSegment);
- if (OSMAND_ROUTER.equals(file.author) && file.hasRtePt()) {
- // For files generated by OSMAND_ROUTER use directions contained unaltered
- addMissingTurns = false;
- }
- if (reverse) {
- // clear directions all turns should be recalculated
- directions = null;
- Collections.reverse(points);
- addMissingTurns = true;
- }
- } else {
- // first of all check tracks
- if (!useIntermediatePointsRTE) {
- List segments = file.getNonEmptyTrkSegments(false);
- if (selectedSegment != -1 && segments.size() > selectedSegment) {
- TrkSegment segment = segments.get(selectedSegment);
- for (WptPt p : segment.points) {
- points.add(createLocation(p));
- }
- } else {
- for (TrkSegment tkSeg : segments) {
- for (WptPt p : tkSeg.points) {
- points.add(createLocation(p));
- }
- }
- }
- }
- if (points.isEmpty()) {
- for (Route rte : file.routes) {
- for (WptPt pt : rte.points) {
- points.add(createLocation(pt));
- }
- }
- }
- if (reverse) {
- Collections.reverse(points);
- }
- }
- return this;
- }
- }
-
public static Location createLocation(WptPt pt){
Location loc = new Location("OsmandRouteProvider");
loc.setLatitude(pt.lat);
@@ -771,13 +503,6 @@ public class RouteProvider {
return nearestPointIndex;
}
- protected String getString(Context ctx, int resId){
- if(ctx == null){
- return ""; //$NON-NLS-1$
- }
- return ctx.getString(resId);
- }
-
public RoutingEnvironment getRoutingEnvironment(OsmandApplication ctx, ApplicationMode mode, LatLon start, LatLon end) throws IOException {
RouteCalculationParams params = new RouteCalculationParams();
params.ctx = ctx;
@@ -788,11 +513,11 @@ public class RouteProvider {
}
public List generateGpxPoints(RoutingEnvironment env, GpxRouteApproximation gctx, LocationsHolder locationsHolder) {
- return env.router.generateGpxPoints(gctx, locationsHolder);
+ return env.getRouter().generateGpxPoints(gctx, locationsHolder);
}
public GpxRouteApproximation calculateGpxPointsApproximation(RoutingEnvironment env, GpxRouteApproximation gctx, List points, ResultMatcher resultMatcher) throws IOException, InterruptedException {
- return env.router.searchGpxRoute(gctx, points, resultMatcher);
+ return env.getRouter().searchGpxRoute(gctx, points, resultMatcher);
}
protected RoutingEnvironment calculateRoutingEnvironment(RouteCalculationParams params, boolean calcGPXRoute, boolean skipComplex) throws IOException {
@@ -885,7 +610,7 @@ public class RouteProvider {
if (params.intermediates != null) {
inters = new ArrayList(params.intermediates);
}
- return calcOfflineRouteImpl(params, env.router, env.ctx, env.complexCtx, st, en, inters, env.precalculated);
+ return calcOfflineRouteImpl(params, env.getRouter(), env.getCtx(), env.getComplexCtx(), st, en, inters, env.getPrecalculated());
}
private RoutingConfiguration initOsmAndRoutingConfig(Builder config, final RouteCalculationParams params, OsmandSettings settings,
@@ -1012,7 +737,7 @@ public class RouteProvider {
return new RouteCalculationResult("Empty result");
}
- private static List parseOsmAndGPXRoute(List points, GPXFile gpxFile, int selectedSegment) {
+ protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile, int selectedSegment) {
List segments = gpxFile.getNonEmptyTrkSegments(false);
if (selectedSegment != -1 && segments.size() > selectedSegment) {
TrkSegment segment = segments.get(selectedSegment);
@@ -1032,8 +757,8 @@ public class RouteProvider {
}
}
- private static List parseOsmAndGPXRoute(List points, GPXFile gpxFile, boolean osmandRouter,
- boolean leftSide, float defSpeed, int selectedSegment) {
+ protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile, boolean osmandRouter,
+ boolean leftSide, float defSpeed, int selectedSegment) {
List directions = null;
if (!osmandRouter) {
for (WptPt pt : gpxFile.getPoints()) {
@@ -1378,6 +1103,4 @@ public class RouteProvider {
}
return new RouteCalculationResult(segments, computeDirections, params, null, false);
}
-
-
-}
+}
\ No newline at end of file
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteRecalculationHelper.java b/OsmAnd/src/net/osmand/plus/routing/RouteRecalculationHelper.java
index 175003fe18..8fb8201dea 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteRecalculationHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteRecalculationHelper.java
@@ -6,6 +6,7 @@ import net.osmand.Location;
import net.osmand.data.LatLon;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.router.RouteCalculationProgress;
@@ -179,7 +180,7 @@ class RouteRecalculationHelper {
}
public void recalculateRouteInBackground(final Location start, final LatLon end, final List intermediates,
- final RouteProvider.GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged) {
+ final GPXRouteParamsBuilder gpxRoute, final RouteCalculationResult previousRoute, boolean paramsChanged, boolean onlyStartPointChanged) {
if (start == null || end == null) {
return;
}
@@ -207,7 +208,7 @@ class RouteRecalculationHelper {
params.mode = mode;
params.ctx = app;
boolean updateProgress = false;
- if (params.mode.getRouteService() == RouteProvider.RouteService.OSMAND) {
+ if (params.mode.getRouteService() == RouteService.OSMAND) {
params.calculationProgress = new RouteCalculationProgress();
updateProgress = true;
} else {
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteService.java b/OsmAnd/src/net/osmand/plus/routing/RouteService.java
new file mode 100644
index 0000000000..6565b09106
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteService.java
@@ -0,0 +1,45 @@
+package net.osmand.plus.routing;
+
+import net.osmand.plus.OsmandApplication;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public enum RouteService {
+ OSMAND("OsmAnd (offline)"),
+ BROUTER("BRouter (offline)"),
+ STRAIGHT("Straight line"),
+ DIRECT_TO("Direct To"),
+ ONLINE("Online engine");
+
+ private final String name;
+
+ RouteService(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isOnline() {
+ return this != OSMAND && this != BROUTER;
+ }
+
+ boolean isAvailable(OsmandApplication ctx) {
+ if (this == BROUTER) {
+ return ctx.getBRouterService() != null;
+ }
+ return true;
+ }
+
+ public static RouteService[] getAvailableRouters(OsmandApplication ctx) {
+ List list = new ArrayList<>();
+ for (RouteService r : values()) {
+ if (r.isAvailable(ctx)) {
+ list.add(r);
+ }
+ }
+ return list.toArray(new RouteService[0]);
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingEnvironment.java b/OsmAnd/src/net/osmand/plus/routing/RoutingEnvironment.java
new file mode 100644
index 0000000000..15b484cc67
--- /dev/null
+++ b/OsmAnd/src/net/osmand/plus/routing/RoutingEnvironment.java
@@ -0,0 +1,36 @@
+package net.osmand.plus.routing;
+
+import net.osmand.router.PrecalculatedRouteDirection;
+import net.osmand.router.RoutePlannerFrontEnd;
+import net.osmand.router.RoutingContext;
+
+public class RoutingEnvironment {
+
+ private RoutingContext ctx;
+ private RoutingContext complexCtx;
+ private RoutePlannerFrontEnd router;
+ private PrecalculatedRouteDirection precalculated;
+
+ public RoutingEnvironment(RoutePlannerFrontEnd router, RoutingContext ctx, RoutingContext complexCtx, PrecalculatedRouteDirection precalculated) {
+ this.router = router;
+ this.ctx = ctx;
+ this.complexCtx = complexCtx;
+ this.precalculated = precalculated;
+ }
+
+ public RoutePlannerFrontEnd getRouter() {
+ return router;
+ }
+
+ public RoutingContext getCtx() {
+ return ctx;
+ }
+
+ public RoutingContext getComplexCtx() {
+ return complexCtx;
+ }
+
+ public PrecalculatedRouteDirection getPrecalculated() {
+ return precalculated;
+ }
+}
diff --git a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
index 1addb2f50a..8ab9405ee1 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RoutingHelper.java
@@ -20,9 +20,7 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.notifications.OsmandNotification.NotificationType;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
-import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
-import net.osmand.plus.routing.RouteProvider.RouteService;
-import net.osmand.plus.routing.RouteProvider.RoutingEnvironment;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmAndAppCustomization.OsmAndAppCustomizationListener;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -670,9 +668,9 @@ public class RoutingHelper {
private static float getDefaultAllowedDeviation(OsmandSettings settings, ApplicationMode mode, float posTolerance) {
if (settings.DISABLE_OFFROUTE_RECALC.getModeValue(mode)) {
return -1.0f;
- } else if (mode.getRouteService() == RouteProvider.RouteService.DIRECT_TO) {
+ } else if (mode.getRouteService() == RouteService.DIRECT_TO) {
return -1.0f;
- } else if (mode.getRouteService() == RouteProvider.RouteService.STRAIGHT) {
+ } else if (mode.getRouteService() == RouteService.STRAIGHT) {
MetricsConstants mc = settings.METRIC_SYSTEM.getModeValue(mode);
if (mc == MetricsConstants.KILOMETERS_AND_METERS || mc == MetricsConstants.MILES_AND_METERS) {
return 500.f;
diff --git a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java
index 08da774f27..637e3078e7 100644
--- a/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routing/TransportRoutingHelper.java
@@ -18,7 +18,6 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.routing.RouteCalculationParams.RouteCalculationResultListener;
-import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java b/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java
index 29a50aae4b..8a27935c06 100644
--- a/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java
+++ b/OsmAnd/src/net/osmand/plus/settings/backend/ApplicationMode.java
@@ -12,7 +12,7 @@ import net.osmand.plus.R;
import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.profiles.NavigationIcon;
import net.osmand.plus.profiles.ProfileIconColors;
-import net.osmand.plus.routing.RouteProvider.RouteService;
+import net.osmand.plus.routing.RouteService;
import net.osmand.util.Algorithms;
import org.apache.commons.lang3.StringUtils;
diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
index 44831fa52c..1667c05264 100644
--- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
+++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java
@@ -48,7 +48,7 @@ import net.osmand.plus.profiles.NavigationIcon;
import net.osmand.plus.profiles.ProfileIconColors;
import net.osmand.plus.rastermaps.LayerTransparencySeekbarMode;
import net.osmand.plus.render.RendererRegistry;
-import net.osmand.plus.routing.RouteProvider.RouteService;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.srtmplugin.TerrainMode;
import net.osmand.plus.views.layers.RadiusRulerControlLayer.RadiusRulerMode;
import net.osmand.plus.voice.CommandPlayer;
diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java
index 8c45d89def..2e86899ee8 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/NavigationFragment.java
@@ -14,14 +14,13 @@ import net.osmand.plus.profiles.ProfileDataObject;
import net.osmand.plus.profiles.ProfileDataUtils;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet;
import net.osmand.plus.routepreparationmenu.RouteOptionsBottomSheet.DialogMode;
-import net.osmand.plus.routing.RouteProvider.RouteService;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.profiles.RoutingProfileDataObject.RoutingProfilesResources;
import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
-import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
import net.osmand.util.Algorithms;
@@ -151,17 +150,17 @@ public class NavigationFragment extends BaseSettingsFragment implements OnSelect
navigationType.setIcon(getActiveIcon(selectedRoutingProfileDataObject.getIconRes()));
ApplicationMode appMode = getSelectedAppMode();
- RouteProvider.RouteService routeService;
+ RouteService routeService;
if (profileKey.equals(RoutingProfilesResources.STRAIGHT_LINE_MODE.name())) {
- routeService = RouteProvider.RouteService.STRAIGHT;
+ routeService = RouteService.STRAIGHT;
} else if (profileKey.equals(RoutingProfilesResources.DIRECT_TO_MODE.name())) {
- routeService = RouteProvider.RouteService.DIRECT_TO;
+ routeService = RouteService.DIRECT_TO;
} else if (profileKey.equals(RoutingProfilesResources.BROUTER_MODE.name())) {
- routeService = RouteProvider.RouteService.BROUTER;
+ routeService = RouteService.BROUTER;
} else if (profileKey.startsWith(ONLINE_ROUTING_ENGINE_PREFIX)) {
routeService = RouteService.ONLINE;
} else {
- routeService = RouteProvider.RouteService.OSMAND;
+ routeService = RouteService.OSMAND;
}
appMode.setRouteService(routeService);
appMode.setRoutingProfile(profileKey);
diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java
index 7e1277ca18..011ceb9287 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/ProfileAppearanceFragment.java
@@ -41,6 +41,7 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.plus.activities.MapActivity;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.settings.backend.backup.ProfileSettingsItem;
@@ -54,7 +55,6 @@ import net.osmand.plus.profiles.ProfileIcons;
import net.osmand.plus.profiles.SelectProfileBottomSheet;
import net.osmand.plus.profiles.SelectProfileBottomSheet.DialogMode;
import net.osmand.plus.profiles.SelectProfileBottomSheet.OnSelectProfileCallback;
-import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.widgets.FlowLayout;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.util.Algorithms;
@@ -965,7 +965,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment implements O
ProfileIconColors color;
int iconRes;
String routingProfile;
- RouteProvider.RouteService routeService;
+ RouteService routeService;
NavigationIcon navigationIcon;
LocationIcon locationIcon;
diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java
index 4ec93b68ef..5321670187 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/RouteParametersFragment.java
@@ -31,6 +31,7 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import net.osmand.plus.routing.RouteProvider;
import net.osmand.plus.routing.RoutingHelper;
@@ -229,7 +230,7 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
fastRoute.setSummaryOn(R.string.shared_string_on);
fastRoute.setSummaryOff(R.string.shared_string_off);
- if (am.getRouteService() == RouteProvider.RouteService.OSMAND) {
+ if (am.getRouteService() == RouteService.OSMAND) {
GeneralRouter router = app.getRouter(am);
clearParameters();
if (router != null) {
@@ -308,10 +309,10 @@ public class RouteParametersFragment extends BaseSettingsFragment implements OnP
}
}
setupTimeConditionalRoutingPref();
- } else if (am.getRouteService() == RouteProvider.RouteService.BROUTER) {
+ } else if (am.getRouteService() == RouteService.BROUTER) {
screen.addPreference(fastRoute);
setupTimeConditionalRoutingPref();
- } else if (am.getRouteService() == RouteProvider.RouteService.STRAIGHT) {
+ } else if (am.getRouteService() == RouteService.STRAIGHT) {
Preference straightAngle = new Preference(app.getApplicationContext());
straightAngle.setPersistent(false);
straightAngle.setKey(settings.ROUTE_STRAIGHT_ANGLE.getId());
diff --git a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java
index 7885a6700b..1aa061a363 100644
--- a/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java
+++ b/OsmAnd/src/net/osmand/plus/settings/fragments/VehicleParametersFragment.java
@@ -25,8 +25,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.helpers.enums.SpeedConstants;
-import net.osmand.plus.routing.RouteProvider.RouteService;
-import net.osmand.plus.routing.RoutingHelper;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.StringPreference;
import net.osmand.plus.settings.bottomsheets.VehicleParametersBottomSheet;
diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
index b72d4803fe..c674ea82ab 100644
--- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
+++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java
@@ -81,7 +81,7 @@ import net.osmand.plus.myplaces.TrackActivityFragmentAdapter;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.routepreparationmenu.cards.BaseCard.CardListener;
-import net.osmand.plus.routing.RouteProvider;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
import net.osmand.plus.track.TrackSelectSegmentBottomSheet.OnSegmentSelectedListener;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
@@ -1156,7 +1156,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
startNavigationForGPX(gpxFile, mapActivity.getMapActions());
- RouteProvider.GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
+ GPXRouteParamsBuilder paramsBuilder = app.getRoutingHelper().getCurrentGPXRoute();
if (paramsBuilder != null) {
paramsBuilder.setSelectedSegment(selectedSegment);
app.getRoutingHelper().onSettingsChanged(true);
diff --git a/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java
index f966b7d897..083d94f4ff 100644
--- a/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java
+++ b/OsmAnd/src/net/osmand/plus/views/layers/RouteLayer.java
@@ -32,7 +32,7 @@ import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.profiles.LocationIcon;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.routing.RouteDirectionInfo;
-import net.osmand.plus.routing.RouteProvider;
+import net.osmand.plus.routing.RouteService;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.TransportRoutingHelper;
import net.osmand.plus.views.OsmandMapLayer;
@@ -360,8 +360,8 @@ public class RouteLayer extends OsmandMapLayer implements ContextMenuLayer.ICont
}
} else {
RouteCalculationResult route = helper.getRoute();
- boolean directTo = route.getRouteService() == RouteProvider.RouteService.DIRECT_TO;
- boolean straight = route.getRouteService() == RouteProvider.RouteService.STRAIGHT;
+ boolean directTo = route.getRouteService() == RouteService.DIRECT_TO;
+ boolean straight = route.getRouteService() == RouteService.STRAIGHT;
publicTransportRouteGeometry.clearRoute();
routeGeometry.updateRoute(tb, route);
if (directTo) {
From e5e77effac17126eaa998280cd345f86b43bbf36 Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Mon, 1 Mar 2021 11:55:27 +0200
Subject: [PATCH 04/20] Fix compilation
---
.../osmand/plus/routepreparationmenu/RoutingOptionsHelper.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java
index d03973a796..c81ac6d3cd 100644
--- a/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java
+++ b/OsmAnd/src/net/osmand/plus/routepreparationmenu/RoutingOptionsHelper.java
@@ -458,7 +458,7 @@ public class RoutingOptionsHelper {
public List getOsmandRouterParameters(ApplicationMode am) {
OsmandSettings settings = app.getSettings();
List list = new ArrayList();
- boolean osmandRouter = am.getRouteService() == RouteProvider.RouteService.OSMAND;
+ boolean osmandRouter = am.getRouteService() == RouteService.OSMAND;
if (!osmandRouter) {
list.add(new OtherLocalRoutingParameter(R.string.calculate_osmand_route_without_internet,
app.getString(R.string.calculate_osmand_route_without_internet), settings.GPX_ROUTE_CALC_OSMAND_PARTS.get()));
From 1985928d60e819910e93c6391e29a99f35b8a715 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Mon, 1 Mar 2021 15:23:50 +0200
Subject: [PATCH 05/20] init
---
.../AddNewFavoriteCategoryBottomSheet.java | 41 ++++++++++-------
.../editors/PointEditorFragment.java | 5 ++-
.../editors/PointEditorFragmentNew.java | 8 ++--
.../editors/RtePtEditorFragment.java | 4 +-
.../SelectFavoriteCategoryBottomSheet.java | 45 +++++++++++++------
.../editors/WptPtEditorFragment.java | 4 +-
.../editors/WptPtEditorFragmentNew.java | 4 +-
.../quickaction/actions/FavoriteAction.java | 11 ++---
.../plus/quickaction/actions/GPXAction.java | 11 ++---
9 files changed, 84 insertions(+), 49 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
index 5b49efe9ed..5b076a69d9 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
@@ -40,6 +40,7 @@ import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
+import java.util.Set;
public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFragment implements CustomColorBottomSheet.ColorPickerListener, BaseCard.CardListener {
@@ -47,6 +48,9 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
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 static final String KEY_CTX_EDIT_CAT_EDITOR_TAG = "key_ctx_edit_cat_editor_tag";
+ private static final String KEY_CTX_EDIT_GPX_FILE = "key_ctx_edit_gpx_file";
+ private static final String KEY_CTX_EDIT_GPX_CATEGORIES = "key_ctx_edit_gpx_categories";
FavouritesDbHelper favoritesHelper;
private boolean isGpx;
private ArrayList gpxCategories;
@@ -55,7 +59,6 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
private TextInputEditText editText;
private TextInputLayout nameTextBox;
private String folderName;
- private int defaultColor;
private View view;
private String editorTag;
private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener;
@@ -69,6 +72,22 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
}
}
+ public static AddNewFavoriteCategoryBottomSheet createInstance(@NonNull String editorTag, @Nullable Set gpxCategories, boolean isGpx) {
+ AddNewFavoriteCategoryBottomSheet fragment = new AddNewFavoriteCategoryBottomSheet();
+ Bundle bundle = new Bundle();
+ bundle.putString(KEY_CTX_EDIT_CAT_EDITOR_TAG, editorTag);
+ bundle.putBoolean(KEY_CTX_EDIT_GPX_FILE, isGpx);
+ if (gpxCategories != null) {
+ bundle.putStringArrayList(KEY_CTX_EDIT_GPX_CATEGORIES, new ArrayList<>(gpxCategories));
+ }
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+
+ public void setSelectionListener(SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener) {
+ this.selectionListener = selectionListener;
+ }
+
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_save;
@@ -129,19 +148,6 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
return favoritesHelper;
}
- @ColorInt
- public int getCategoryColor(String category) {
- FavouritesDbHelper helper = getHelper();
- if (helper != null) {
- for (FavouritesDbHelper.FavoriteGroup fg : getHelper().getFavoriteGroups()) {
- if (fg.getDisplayName(getMyApplication()).equals(category)) {
- return fg.getColor();
- }
- }
- }
- return defaultColor;
- }
-
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = requiredMyApplication();
@@ -150,7 +156,7 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
}
items.add(new TitleItem(getString(R.string.favorite_category_add_new_title)));
- defaultColor = getResources().getColor(R.color.color_favorite);
+ int defaultColor = getResources().getColor(R.color.color_favorite);
selectedColor = defaultColor;
view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.add_new_favorite_category, null);
@@ -228,4 +234,9 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
updateColorSelector(color);
}
+ public interface CategorySelectionListener {
+
+ void onCategorySelected(String category, int color);
+ }
+
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
index 8d118bb7dc..c8309cf8d4 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
@@ -32,6 +32,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
+import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
import net.osmand.util.Algorithms;
@@ -177,10 +178,10 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
}
@Nullable
- protected DialogFragment createSelectCategoryDialog() {
+ protected BottomSheetDialogFragment createSelectCategoryDialog() {
PointEditor editor = getEditor();
if (editor != null) {
- return SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
+ return SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
} else {
return null;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
index 6f50d80214..8fd97cbf38 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
@@ -50,6 +50,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
+import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
@@ -192,8 +193,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
+ SelectFavoriteCategoryBottomSheet dialogFragment = createSelectCategoryDialog();
if (fragmentManager != null) {
- SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment());
+ dialogFragment.showInstance(getChildFragmentManager(), getTargetFragment());
}
}
});
@@ -730,10 +732,10 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
}
@Nullable
- protected DialogFragment createSelectCategoryDialog() {
+ protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
PointEditor editor = getEditor();
if (editor != null) {
- return SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
+ return SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
} else {
return null;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java
index 840ebba24f..2539bc2f2c 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java
@@ -21,9 +21,9 @@ public class RtePtEditorFragment extends WptPtEditorFragment {
}
@Override
- protected DialogFragment createSelectCategoryDialog() {
+ protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
PointEditor editor = getEditor();
- return editor != null ? SelectCategoryDialogFragment.createInstance(editor.getFragmentTag()) : null;
+ return editor != null ? SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag()) : null;
}
public static void showInstance(final MapActivity mapActivity) {
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index 131f10da71..0d7c78599e 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -35,15 +35,17 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import java.util.List;
import java.util.Map;
+import java.util.Set;
public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFragment {
public static final String TAG = SelectFavoriteCategoryBottomSheet.class.getSimpleName();
+ private static final String KEY_CTX_SEL_CAT_EDITOR_TAG = "key_ctx_sel_cat_editor_tag";
private OsmandApplication app;
private GPXUtilities.GPXFile gpxFile;
private String editorTag;
private Map gpxCategories;
- private SelectCategoryDialogFragment.CategorySelectionListener selectionListener;
+ private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener;
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) {
if (!fragmentManager.isStateSaved()) {
@@ -54,14 +56,6 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
}
}
- private static Drawable getIcon(final Activity activity, int iconId) {
- OsmandApplication app = (OsmandApplication) activity.getApplication();
- UiUtilities iconsCache = app.getUIUtilities();
- boolean light = app.getSettings().isLightContent();
- return iconsCache.getIcon(iconId,
- light ? R.color.icon_color_default_light : R.color.icon_color_default_dark);
- }
-
private static Drawable getIcon(final Activity activity, int resId, int color) {
Drawable drawable = AppCompatResources.getDrawable(activity, resId);
if (drawable != null) {
@@ -72,6 +66,17 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
return drawable;
}
+ public static SelectFavoriteCategoryBottomSheet createInstance(String editorTag) {
+ SelectFavoriteCategoryBottomSheet fragment = new SelectFavoriteCategoryBottomSheet();
+ Bundle bundle = new Bundle();
+ bundle.putString(KEY_CTX_SEL_CAT_EDITOR_TAG, editorTag);
+ fragment.setArguments(bundle);
+ return fragment;
+ }
+
+ public void setSelectionListener(SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener) {
+ this.selectionListener = selectionListener;
+ }
public GPXUtilities.GPXFile getGpxFile() {
return gpxFile;
@@ -88,6 +93,11 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = requiredMyApplication();
+ if (savedInstanceState != null) {
+ restoreState(savedInstanceState);
+ } else if (getArguments() != null) {
+ restoreState(getArguments());
+ }
BaseBottomSheetItem titleItem = new BottomSheetItemWithDescription.Builder()
.setDescription(getString(R.string.select_category_descr))
@@ -112,7 +122,11 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- AddNewFavoriteCategoryBottomSheet.showInstance(getFragmentManager(), getTargetFragment());
+ MapActivity mapActivity = (MapActivity) activity;
+ Set categories = gpxCategories != null ? gpxCategories.keySet() : null;
+ AddNewFavoriteCategoryBottomSheet fragment = AddNewFavoriteCategoryBottomSheet.createInstance(editorTag, categories, gpxFile != null);
+ AddNewFavoriteCategoryBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), getTargetFragment());
+ fragment.setSelectionListener(selectionListener);
dismiss();
}
})
@@ -153,8 +167,8 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden, final boolean selected) {
View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
final AppCompatImageView button = (AppCompatImageView) itemView.findViewById(R.id.icon);
- LinearLayout test = itemView.findViewById(R.id.descriptionContainer);
- test.setPadding(0, 0, 0, 0);
+ LinearLayout descriptionContainer = itemView.findViewById(R.id.descriptionContainer);
+ descriptionContainer.setPadding(0, 0, 0, 0);
View divider = itemView.findViewById(R.id.divider_bottom);
divider.setVisibility(View.GONE);
itemView.setPadding(0, 0, 0, 0);
@@ -181,7 +195,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
TextView description = itemView.findViewById(R.id.description);
text.setText(name);
description.setText(String.valueOf(categoryPointCount));
- test.setOnClickListener(new View.OnClickListener() {
+ descriptionContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity a = getActivity();
@@ -201,8 +215,13 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
return itemView;
}
+ public void restoreState(Bundle bundle) {
+ editorTag = bundle.getString(KEY_CTX_SEL_CAT_EDITOR_TAG);
+ }
+
public interface CategorySelectionListener {
void onCategorySelected(String category, int color);
}
+
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
index f5ef3033c8..b6b0d7106a 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
@@ -64,10 +64,10 @@ public class WptPtEditorFragment extends PointEditorFragment {
}
@Override
- protected DialogFragment createSelectCategoryDialog() {
+ protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
- SelectCategoryDialogFragment selectCategoryDialogFragment = SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
+ SelectFavoriteCategoryBottomSheet selectCategoryDialogFragment = SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
selectCategoryDialogFragment.setGpxFile(gpx);
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java
index c948b5414e..6f60f5b8b2 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java
@@ -78,10 +78,10 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
}
@Override
- protected DialogFragment createSelectCategoryDialog() {
+ protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
- SelectCategoryDialogFragment selectCategoryDialogFragment = SelectCategoryDialogFragment.createInstance(editor.getFragmentTag());
+ SelectFavoriteCategoryBottomSheet selectCategoryDialogFragment = SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
GPXFile gpx = editor.getGpxFile();
if (gpx != null) {
selectCategoryDialogFragment.setGpxFile(gpx);
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java
index fbe79b0681..ecd277b092 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java
@@ -22,6 +22,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
+import net.osmand.plus.mapcontextmenu.editors.SelectFavoriteCategoryBottomSheet;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
@@ -175,13 +176,13 @@ public class FavoriteAction extends QuickAction {
@Override
public void onClick(final View view) {
- SelectCategoryDialogFragment dialogFragment = SelectCategoryDialogFragment.createInstance("");
+ SelectFavoriteCategoryBottomSheet dialogFragment = SelectFavoriteCategoryBottomSheet.createInstance("");
dialogFragment.show(
activity.getSupportFragmentManager(),
SelectCategoryDialogFragment.TAG);
- dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {
+ dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
public void onCategorySelected(String category, int color) {
@@ -191,12 +192,12 @@ public class FavoriteAction extends QuickAction {
}
});
- SelectCategoryDialogFragment dialogFragment = (SelectCategoryDialogFragment)
+ SelectFavoriteCategoryBottomSheet dialogFragment = (SelectFavoriteCategoryBottomSheet)
activity.getSupportFragmentManager().findFragmentByTag(SelectCategoryDialogFragment.TAG);
if (dialogFragment != null) {
- dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {
+ dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
public void onCategorySelected(String category, int color) {
@@ -211,7 +212,7 @@ public class FavoriteAction extends QuickAction {
if (dialog != null) {
- dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {
+ dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
public void onCategorySelected(String category, int color) {
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java
index 6fc153bb23..e077d68c97 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java
@@ -16,6 +16,7 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
+import net.osmand.plus.mapcontextmenu.editors.SelectFavoriteCategoryBottomSheet;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.widgets.AutoCompleteTextViewEx;
@@ -119,13 +120,13 @@ public class GPXAction extends QuickAction {
@Override
public void onClick(final View view) {
- SelectCategoryDialogFragment dialogFragment = SelectCategoryDialogFragment.createInstance("");
+ SelectFavoriteCategoryBottomSheet dialogFragment = SelectFavoriteCategoryBottomSheet.createInstance("");
dialogFragment.show(
activity.getSupportFragmentManager(),
SelectCategoryDialogFragment.TAG);
- dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {
+ dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
public void onCategorySelected(String category, int color) {
@@ -135,12 +136,12 @@ public class GPXAction extends QuickAction {
}
});
- SelectCategoryDialogFragment dialogFragment = (SelectCategoryDialogFragment)
+ SelectFavoriteCategoryBottomSheet dialogFragment = (SelectFavoriteCategoryBottomSheet)
activity.getSupportFragmentManager().findFragmentByTag(SelectCategoryDialogFragment.TAG);
if (dialogFragment != null) {
- dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {
+ dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
public void onCategorySelected(String category, int color) {
@@ -155,7 +156,7 @@ public class GPXAction extends QuickAction {
if (dialog != null) {
- dialogFragment.setSelectionListener(new SelectCategoryDialogFragment.CategorySelectionListener() {
+ dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
public void onCategorySelected(String category, int color) {
From 4c04c7ee19e1b8681d421e3c5ad6ccd2477de442 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Mon, 1 Mar 2021 15:48:07 +0200
Subject: [PATCH 06/20] change2
---
.../plus/mapcontextmenu/editors/PointEditorFragment.java | 7 ++++---
.../mapcontextmenu/editors/PointEditorFragmentNew.java | 2 +-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
index c8309cf8d4..fa8d62fb88 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
@@ -139,8 +139,9 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
public boolean onTouch(final View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP) {
FragmentManager fragmentManager = getFragmentManager();
- if (fragmentManager != null) {
- SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment());
+ SelectFavoriteCategoryBottomSheet dialogFragment = createSelectCategoryDialog();
+ if (fragmentManager != null && dialogFragment != null) {
+ dialogFragment.showInstance(getChildFragmentManager(), getTargetFragment());
}
return true;
}
@@ -178,7 +179,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
}
@Nullable
- protected BottomSheetDialogFragment createSelectCategoryDialog() {
+ protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
PointEditor editor = getEditor();
if (editor != null) {
return SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
index 8fd97cbf38..3b7768db5c 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
@@ -194,7 +194,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
SelectFavoriteCategoryBottomSheet dialogFragment = createSelectCategoryDialog();
- if (fragmentManager != null) {
+ if (fragmentManager != null && dialogFragment != null) {
dialogFragment.showInstance(getChildFragmentManager(), getTargetFragment());
}
}
From c78a934d8fee52ee1684c76c5b4ec6cff7ba434d Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Mon, 1 Mar 2021 16:58:22 +0200
Subject: [PATCH 07/20] Selected categories
---
.../editors/PointEditorFragment.java | 2 +-
.../editors/PointEditorFragmentNew.java | 18 +++++++++++++++---
.../SelectFavoriteCategoryBottomSheet.java | 5 +++--
3 files changed, 19 insertions(+), 6 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
index fa8d62fb88..bdf49bf7b6 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
@@ -141,7 +141,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
FragmentManager fragmentManager = getFragmentManager();
SelectFavoriteCategoryBottomSheet dialogFragment = createSelectCategoryDialog();
if (fragmentManager != null && dialogFragment != null) {
- dialogFragment.showInstance(getChildFragmentManager(), getTargetFragment());
+ dialogFragment.show(fragmentManager, SelectFavoriteCategoryBottomSheet.class.getSimpleName());
}
return true;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
index 3b7768db5c..7388c08415 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
@@ -195,7 +195,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
FragmentManager fragmentManager = getFragmentManager();
SelectFavoriteCategoryBottomSheet dialogFragment = createSelectCategoryDialog();
if (fragmentManager != null && dialogFragment != null) {
- dialogFragment.showInstance(getChildFragmentManager(), getTargetFragment());
+ dialogFragment.show(fragmentManager, SelectFavoriteCategoryBottomSheet.class.getSimpleName());
}
}
});
@@ -741,6 +741,17 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
}
}
+ @Nullable
+ protected AddNewFavoriteCategoryBottomSheet createAddCategoryDialog() {
+ PointEditor editor = getEditor();
+ if (editor != null) {
+ return AddNewFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag(), getCategories(),
+ !editor.getFragmentTag().equals(FavoritePointEditor.TAG));
+ } else {
+ return null;
+ }
+ }
+
@Override
public void onDestroyView() {
PointEditor editor = getEditor();
@@ -1008,8 +1019,9 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
@Override
public void onClick(View view) {
FragmentManager fragmentManager = getFragmentManager();
- if (fragmentManager != null) {
- SelectFavoriteCategoryBottomSheet.showInstance(getChildFragmentManager(), getTargetFragment());
+ AddNewFavoriteCategoryBottomSheet dialogFragment = createAddCategoryDialog();
+ if (fragmentManager != null && dialogFragment != null) {
+ dialogFragment.show(fragmentManager, SelectFavoriteCategoryBottomSheet.class.getSimpleName());
}
}
});
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index 0d7c78599e..ad19a14700 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -32,6 +32,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.myplaces.AddNewTrackFolderBottomSheet;
import java.util.List;
import java.util.Map;
@@ -43,7 +44,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
private static final String KEY_CTX_SEL_CAT_EDITOR_TAG = "key_ctx_sel_cat_editor_tag";
private OsmandApplication app;
private GPXUtilities.GPXFile gpxFile;
- private String editorTag;
+ private static String editorTag;
private Map gpxCategories;
private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener;
@@ -125,7 +126,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
MapActivity mapActivity = (MapActivity) activity;
Set categories = gpxCategories != null ? gpxCategories.keySet() : null;
AddNewFavoriteCategoryBottomSheet fragment = AddNewFavoriteCategoryBottomSheet.createInstance(editorTag, categories, gpxFile != null);
- AddNewFavoriteCategoryBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), getTargetFragment());
+ fragment.show(mapActivity.getSupportFragmentManager(), AddNewTrackFolderBottomSheet.class.getName());
fragment.setSelectionListener(selectionListener);
dismiss();
}
From 2b8a233e4d3d07bfed5092486d704b12170a13ba Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Mon, 1 Mar 2021 18:04:17 +0200
Subject: [PATCH 08/20] Add new focus on
---
.../AddNewFavoriteCategoryBottomSheet.java | 97 ++++++++++---------
.../SelectFavoriteCategoryBottomSheet.java | 13 +--
2 files changed, 52 insertions(+), 58 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
index 5b076a69d9..1e21c880b0 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
@@ -2,26 +2,20 @@ package net.osmand.plus.mapcontextmenu.editors;
import android.content.res.ColorStateList;
import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
import android.view.View;
-import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
-import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
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.PlatformUtil;
+import net.osmand.AndroidUtils;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@@ -35,8 +29,7 @@ import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet;
import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import net.osmand.plus.track.ColorsCard;
import net.osmand.plus.track.CustomColorBottomSheet;
-
-import org.apache.commons.logging.Log;
+import net.osmand.util.Algorithms;
import java.util.ArrayList;
import java.util.List;
@@ -46,32 +39,25 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
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 static final String KEY_CTX_EDIT_CAT_EDITOR_TAG = "key_ctx_edit_cat_editor_tag";
private static final String KEY_CTX_EDIT_GPX_FILE = "key_ctx_edit_gpx_file";
private static final String KEY_CTX_EDIT_GPX_CATEGORIES = "key_ctx_edit_gpx_categories";
+ private static final String KEY_CTX_EDIT_CAT_NEW = "key_ctx_edit_cat_new";
+ private static final String KEY_CTX_EDIT_CAT_NAME = "key_ctx_edit_cat_name";
+ private static final String KEY_CTX_EDIT_CAT_COLOR = "key_ctx_edit_cat_color";
FavouritesDbHelper favoritesHelper;
+ private boolean isNew = true;
+ private String name = "";
private boolean isGpx;
private ArrayList gpxCategories;
private int selectedColor;
private ColorsCard colorsCard;
private TextInputEditText editText;
private TextInputLayout nameTextBox;
- private String folderName;
private View view;
private String editorTag;
private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener;
- public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) {
- if (!fragmentManager.isStateSaved()) {
- AddNewFavoriteCategoryBottomSheet fragment = new AddNewFavoriteCategoryBottomSheet();
- fragment.setRetainInstance(true);
- fragment.setTargetFragment(target, 0);
- fragment.show(fragmentManager, TAG);
- }
- }
-
public static AddNewFavoriteCategoryBottomSheet createInstance(@NonNull String editorTag, @Nullable Set gpxCategories, boolean isGpx) {
AddNewFavoriteCategoryBottomSheet fragment = new AddNewFavoriteCategoryBottomSheet();
Bundle bundle = new Bundle();
@@ -109,7 +95,7 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
@Override
protected void onRightBottomButtonClick() {
- String name = editText.getText().toString().trim();
+ name = editText.getText().toString().trim();
FragmentActivity activity = getActivity();
if (activity != null) {
boolean exists = isGpx ? isGpxCategoryExists(name) : favoritesHelper.groupExists(name);
@@ -148,16 +134,37 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
return favoritesHelper;
}
+ @Override
+ public void onSaveInstanceState(@NonNull Bundle outState) {
+ saveState(outState);
+ super.onSaveInstanceState(outState);
+ }
+
+ public void saveState(Bundle bundle) {
+ bundle.putString(KEY_CTX_EDIT_CAT_EDITOR_TAG, editorTag);
+ bundle.putString(KEY_CTX_EDIT_CAT_NEW, Boolean.valueOf(isNew).toString());
+ bundle.putString(KEY_CTX_EDIT_CAT_NAME, editText.getText().toString().trim());
+ bundle.putString(KEY_CTX_EDIT_CAT_COLOR, "" + selectedColor);
+ bundle.putBoolean(KEY_CTX_EDIT_GPX_FILE, isGpx);
+ if (gpxCategories != null) {
+ bundle.putStringArrayList(KEY_CTX_EDIT_GPX_CATEGORIES, gpxCategories);
+ }
+ }
+
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = requiredMyApplication();
favoritesHelper = app.getFavorites();
+
if (savedInstanceState != null) {
- folderName = savedInstanceState.getString(FOLDER_NAME_KEY);
+ restoreState(savedInstanceState);
+ } else if (getArguments() != null) {
+ restoreState(getArguments());
}
+
+
items.add(new TitleItem(getString(R.string.favorite_category_add_new_title)));
- int defaultColor = getResources().getColor(R.color.color_favorite);
- selectedColor = defaultColor;
+ selectedColor = getResources().getColor(R.color.color_favorite);
view = UiUtilities.getInflater(app, nightMode).inflate(R.layout.add_new_favorite_category, null);
nameTextBox = view.findViewById(R.id.name_text_box);
@@ -167,26 +174,12 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
.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(folderName);
- if (editText.requestFocus()) {
- getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
- }
+ editText.setText(name);
+ editText.requestFocus();
+ AndroidUtils.softKeyboardDelayed(getActivity(), editText);
nameTextBox.setStartIconTintList(ColorStateList.valueOf(selectedColor));
nameTextBox.setBoxStrokeColorStateList(ColorStateList.valueOf(selectedColor));
- 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) {
-
- }
- });
BaseBottomSheetItem editFolderName = new BaseBottomSheetItem.Builder()
.setCustomView(view)
.create();
@@ -234,9 +227,21 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
updateColorSelector(color);
}
- public interface CategorySelectionListener {
-
- void onCategorySelected(String category, int color);
+ public void restoreState(Bundle bundle) {
+ editorTag = bundle.getString(KEY_CTX_EDIT_CAT_EDITOR_TAG);
+ String isNewStr = bundle.getString(KEY_CTX_EDIT_CAT_NEW);
+ if (isNewStr != null) {
+ isNew = Boolean.parseBoolean(isNewStr);
+ }
+ name = bundle.getString(KEY_CTX_EDIT_CAT_NAME);
+ if (name == null) {
+ name = "";
+ }
+ String colorStr = bundle.getString(KEY_CTX_EDIT_CAT_COLOR);
+ if (!Algorithms.isEmpty(colorStr)) {
+ selectedColor = Integer.parseInt(colorStr);
+ }
+ isGpx = bundle.getBoolean(KEY_CTX_EDIT_GPX_FILE, false);
+ gpxCategories = bundle.getStringArrayList(KEY_CTX_EDIT_GPX_CATEGORIES);
}
-
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index ad19a14700..8d912945c2 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -11,14 +11,11 @@ import android.widget.RadioButton;
import android.widget.TextView;
import androidx.annotation.NonNull;
-import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
-import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
-import androidx.fragment.app.FragmentManager;
import net.osmand.GPXUtilities;
import net.osmand.plus.FavouritesDbHelper;
@@ -42,20 +39,12 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
public static final String TAG = SelectFavoriteCategoryBottomSheet.class.getSimpleName();
private static final String KEY_CTX_SEL_CAT_EDITOR_TAG = "key_ctx_sel_cat_editor_tag";
+ private static String editorTag;
private OsmandApplication app;
private GPXUtilities.GPXFile gpxFile;
- private static String editorTag;
private Map gpxCategories;
private SelectFavoriteCategoryBottomSheet.CategorySelectionListener selectionListener;
- public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment target) {
- if (!fragmentManager.isStateSaved()) {
- SelectFavoriteCategoryBottomSheet fragment = new SelectFavoriteCategoryBottomSheet();
- fragment.setRetainInstance(true);
- fragment.setTargetFragment(target, 0);
- fragment.show(fragmentManager, TAG);
- }
- }
private static Drawable getIcon(final Activity activity, int resId, int color) {
Drawable drawable = AppCompatResources.getDrawable(activity, resId);
From 63530f571ac184b68bc72dca40d757e8da4a617d Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Mon, 1 Mar 2021 20:33:11 +0200
Subject: [PATCH 09/20] Minor fix
---
OsmAnd/res/layout/favorite_categories_dialog.xml | 1 +
.../editors/SelectFavoriteCategoryBottomSheet.java | 11 +++++++++--
.../osmand/plus/quickaction/actions/GPXAction.java | 2 +-
3 files changed, 11 insertions(+), 3 deletions(-)
diff --git a/OsmAnd/res/layout/favorite_categories_dialog.xml b/OsmAnd/res/layout/favorite_categories_dialog.xml
index e9503bd3b9..a821d16b8b 100644
--- a/OsmAnd/res/layout/favorite_categories_dialog.xml
+++ b/OsmAnd/res/layout/favorite_categories_dialog.xml
@@ -1,5 +1,6 @@
e : gpxCategories.entrySet()) {
@@ -141,7 +146,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
}
}
} else {
- List gs = helper2.getFavoriteGroups();
+ List gs = favoritesHelper.getFavoriteGroups();
for (final FavouritesDbHelper.FavoriteGroup category : gs) {
int favoriteCategoryCount = category.getPoints().size();
favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
@@ -157,6 +162,8 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden, final boolean selected) {
View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
final AppCompatImageView button = (AppCompatImageView) itemView.findViewById(R.id.icon);
+ final int dp8 = AndroidUtils.dpToPx(app, 8f);
+ button.setPadding(0,0, dp8,0);
LinearLayout descriptionContainer = itemView.findViewById(R.id.descriptionContainer);
descriptionContainer.setPadding(0, 0, 0, 0);
View divider = itemView.findViewById(R.id.divider_bottom);
diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java
index e077d68c97..d0bfd98cbf 100644
--- a/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java
+++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java
@@ -124,7 +124,7 @@ public class GPXAction extends QuickAction {
dialogFragment.show(
activity.getSupportFragmentManager(),
- SelectCategoryDialogFragment.TAG);
+ SelectFavoriteCategoryBottomSheet.TAG);
dialogFragment.setSelectionListener(new SelectFavoriteCategoryBottomSheet.CategorySelectionListener() {
@Override
From cae7027177d76393d7f90c40edd9d29e27c43cf4 Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Tue, 2 Mar 2021 04:48:45 +0200
Subject: [PATCH 10/20] Calculate route among segments
---
.../osmand/plus/routing/GPXRouteParams.java | 23 ++---
.../osmand/plus/routing/RouteProvider.java | 99 +++++++++++++------
2 files changed, 77 insertions(+), 45 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java b/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
index f62c686d3c..93b2f0875d 100644
--- a/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
+++ b/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
@@ -1,8 +1,9 @@
package net.osmand.plus.routing;
+import android.util.Pair;
+
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.Route;
-import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.PlatformUtil;
@@ -18,6 +19,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
+import static net.osmand.plus.routing.RouteProvider.collectSegmentPointsFromGpx;
import static net.osmand.router.RouteExporter.OSMAND_ROUTER_V2;
public class GPXRouteParams {
@@ -29,6 +31,7 @@ public class GPXRouteParams {
protected List directions;
protected List points = new ArrayList<>();
protected List routePoints = new ArrayList<>();
+ protected List> segmentEndpoints = new ArrayList<>();
protected boolean reverse;
protected boolean passWholeRoute;
protected boolean calculateOsmAndRoute;
@@ -82,7 +85,7 @@ public class GPXRouteParams {
}
int selectedSegment = builder.getSelectedSegment();
if (OSMAND_ROUTER_V2.equals(file.author)) {
- route = RouteProvider.parseOsmAndGPXRoute(points, file, selectedSegment);
+ route = RouteProvider.parseOsmAndGPXRoute(points, file, segmentEndpoints, selectedSegment);
if (selectedSegment == -1) {
routePoints = file.getRoutePoints();
} else {
@@ -94,7 +97,7 @@ public class GPXRouteParams {
}
addMissingTurns = route != null && route.isEmpty();
} else if (file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)) {
- directions = RouteProvider.parseOsmAndGPXRoute(points, file, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10, selectedSegment);
+ directions = RouteProvider.parseOsmAndGPXRoute(points, file, segmentEndpoints, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10, selectedSegment);
if (OSMAND_ROUTER.equals(file.author) && file.hasRtePt()) {
// For files generated by OSMAND_ROUTER use directions contained unaltered
addMissingTurns = false;
@@ -108,19 +111,7 @@ public class GPXRouteParams {
} else {
// first of all check tracks
if (!useIntermediatePointsRTE) {
- List segments = file.getNonEmptyTrkSegments(false);
- if (selectedSegment != -1 && segments.size() > selectedSegment) {
- TrkSegment segment = segments.get(selectedSegment);
- for (WptPt p : segment.points) {
- points.add(RouteProvider.createLocation(p));
- }
- } else {
- for (TrkSegment tkSeg : segments) {
- for (WptPt p : tkSeg.points) {
- points.add(RouteProvider.createLocation(p));
- }
- }
- }
+ collectSegmentPointsFromGpx(file, points, segmentEndpoints, selectedSegment);
}
if (points.isEmpty()) {
for (Route rte : file.routes) {
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index 9521ccb52d..45e113c597 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -3,6 +3,7 @@ package net.osmand.plus.routing;
import android.os.Bundle;
import android.util.Base64;
+import android.util.Pair;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
@@ -22,6 +23,7 @@ import net.osmand.plus.TargetPointsHelper.TargetPoint;
import net.osmand.plus.onlinerouting.OnlineRoutingHelper;
import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine.OnlineRoutingResponse;
import net.osmand.plus.render.NativeOsmandLibrary;
+import net.osmand.plus.routing.GPXRouteParams.GPXRouteParamsBuilder;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.CommonPreference;
import net.osmand.plus.settings.backend.OsmandSettings;
@@ -266,6 +268,7 @@ public class RouteProvider {
}
final List inputDirections = gpxParams.directions;
List gpxDirections = calcDirections(startI, endI, inputDirections);
+ insertSegments(routeParams, gpxRoute, gpxDirections, gpxParams.segmentEndpoints, calculateOsmAndRouteParts);
insertInitialSegment(routeParams, gpxRoute, gpxDirections, calculateOsmAndRouteParts);
insertFinalSegment(routeParams, gpxRoute, gpxDirections, calculateOsmAndRouteParts);
@@ -279,6 +282,28 @@ public class RouteProvider {
gpxParams.wpt, routeParams.gpxRoute.addMissingTurns);
}
+ public void insertSegments(RouteCalculationParams routeParams, List points, List directions,
+ List> segmentEndpoints, boolean calculateOsmAndRouteParts) {
+ for (Pair pair : segmentEndpoints) {
+ int index = points.indexOf(pair.second);
+ if (calculateOsmAndRouteParts && index != -1 && points.contains(pair.first)) {
+ LatLon end = new LatLon(pair.second.getLatitude(), pair.second.getLongitude());
+ RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, pair.first, end);
+
+ if (newRes != null && newRes.isCalculated()) {
+ List loct = newRes.getImmutableAllLocations();
+ List dt = newRes.getImmutableAllDirections();
+
+ for (RouteDirectionInfo i : dt) {
+ i.routePointOffset += points.size();
+ }
+ points.addAll(index, loct);
+ directions.addAll(dt);
+ }
+ }
+ }
+ }
+
private RouteCalculationResult calculateOsmAndRouteWithIntermediatePoints(RouteCalculationParams routeParams,
final List intermediates) throws IOException {
RouteCalculationParams rp = new RouteCalculationParams();
@@ -737,7 +762,9 @@ public class RouteProvider {
return new RouteCalculationResult("Empty result");
}
- protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile, int selectedSegment) {
+ protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile,
+ List> segmentEndpoints,
+ int selectedSegment) {
List segments = gpxFile.getNonEmptyTrkSegments(false);
if (selectedSegment != -1 && segments.size() > selectedSegment) {
TrkSegment segment = segments.get(selectedSegment);
@@ -747,37 +774,50 @@ public class RouteProvider {
RouteImporter routeImporter = new RouteImporter(segment);
return routeImporter.importRoute();
} else {
- for (TrkSegment ts : segments) {
- for (WptPt p : ts.points) {
- points.add(createLocation(p));
- }
- }
+ collectPointsFromSegments(segments, points, segmentEndpoints);
RouteImporter routeImporter = new RouteImporter(gpxFile);
return routeImporter.importRoute();
}
}
- protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile, boolean osmandRouter,
- boolean leftSide, float defSpeed, int selectedSegment) {
+ protected static void collectSegmentPointsFromGpx(GPXFile gpxFile, List points,
+ List> segmentEndpoints, int selectedSegment) {
+ List segments = gpxFile.getNonEmptyTrkSegments(false);
+ if (selectedSegment != -1 && segments.size() > selectedSegment) {
+ TrkSegment segment = segments.get(selectedSegment);
+ for (WptPt wptPt : segment.points) {
+ points.add(createLocation(wptPt));
+ }
+ } else {
+ collectPointsFromSegments(segments, points, segmentEndpoints);
+ }
+ }
+
+ protected static void collectPointsFromSegments(List segments, List points, List> segmentEndpoints) {
+ Location lastPoint = null;
+ for (int i = 0; i < segments.size(); i++) {
+ TrkSegment segment = segments.get(i);
+ for (WptPt wptPt : segment.points) {
+ points.add(createLocation(wptPt));
+ }
+ if (i <= segments.size() - 1 && lastPoint != null) {
+ segmentEndpoints.add(new Pair<>(lastPoint, points.get((points.size() - segment.points.size()))));
+ }
+ lastPoint = points.get(points.size() - 1);
+ }
+ }
+
+ protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile,
+ List> segmentEndpoints,
+ boolean osmandRouter, boolean leftSide,
+ float defSpeed, int selectedSegment) {
List directions = null;
if (!osmandRouter) {
for (WptPt pt : gpxFile.getPoints()) {
points.add(createLocation(pt));
}
} else {
- List segments = gpxFile.getNonEmptyTrkSegments(false);
- if (selectedSegment != -1 && segments.size() > selectedSegment) {
- TrkSegment segment = segments.get(selectedSegment);
- for (WptPt p : segment.points) {
- points.add(createLocation(p));
- }
- } else {
- for (TrkSegment ts : segments) {
- for (WptPt p : ts.points) {
- points.add(createLocation(p));
- }
- }
- }
+ collectSegmentPointsFromGpx(gpxFile, points, segmentEndpoints, selectedSegment);
}
float[] distanceToEnd = new float[points.size()];
for (int i = points.size() - 2; i >= 0; i--) {
@@ -1042,9 +1082,10 @@ public class RouteProvider {
bpars.putString("turnInstructionFormat", "osmand");
bpars.putString("acceptCompressedResult", "true");
- OsmandApplication ctx = (OsmandApplication) params.ctx;
+ OsmandApplication ctx = params.ctx;
List res = new ArrayList();
- List dir = new ArrayList<>();
+ List dir = new ArrayList<>();
+ List> segmentEndpoints = new ArrayList<>();
IBRouterService brouterService = ctx.getBRouterService();
if (brouterService == null) {
@@ -1057,22 +1098,22 @@ public class RouteProvider {
boolean isZ64Encoded = gpxMessage.startsWith("ejY0"); // base-64 version of "z64"
- if (!( isZ64Encoded || gpxMessage.startsWith("<") ) ) {
+ if (!(isZ64Encoded || gpxMessage.startsWith("<"))) {
return new RouteCalculationResult(gpxMessage);
}
InputStream gpxStream;
- if ( isZ64Encoded ) {
- ByteArrayInputStream bais = new ByteArrayInputStream( Base64.decode(gpxMessage, Base64.DEFAULT) );
- bais.read( new byte[3] ); // skip prefix
- gpxStream = new GZIPInputStream( bais );
+ if (isZ64Encoded) {
+ ByteArrayInputStream bais = new ByteArrayInputStream(Base64.decode(gpxMessage, Base64.DEFAULT));
+ bais.read(new byte[3]); // skip prefix
+ gpxStream = new GZIPInputStream(bais);
} else {
gpxStream = new ByteArrayInputStream(gpxMessage.getBytes("UTF-8"));
}
GPXFile gpxFile = GPXUtilities.loadGPXFile(gpxStream);
- dir = parseOsmAndGPXRoute(res, gpxFile, true, params.leftSide, params.mode.getDefaultSpeed(), -1);
+ dir = parseOsmAndGPXRoute(res, gpxFile, segmentEndpoints, true, params.leftSide, params.mode.getDefaultSpeed(), -1);
if (dir != null) {
addMissingTurns = false;
From f1e0ad342c5489cba8337f922be4215c4d0afddd Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Tue, 2 Mar 2021 05:11:21 +0200
Subject: [PATCH 11/20] Fix reverse route between segments
---
.../osmand/plus/routing/GPXRouteParams.java | 10 +++---
.../osmand/plus/routing/RouteProvider.java | 33 ++++++++++---------
2 files changed, 24 insertions(+), 19 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java b/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
index 93b2f0875d..9290195acd 100644
--- a/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
+++ b/OsmAnd/src/net/osmand/plus/routing/GPXRouteParams.java
@@ -1,7 +1,5 @@
package net.osmand.plus.routing;
-import android.util.Pair;
-
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.Route;
import net.osmand.GPXUtilities.WptPt;
@@ -30,8 +28,8 @@ public class GPXRouteParams {
protected List route;
protected List directions;
protected List points = new ArrayList<>();
+ protected List segmentEndpoints = new ArrayList<>();
protected List routePoints = new ArrayList<>();
- protected List> segmentEndpoints = new ArrayList<>();
protected boolean reverse;
protected boolean passWholeRoute;
protected boolean calculateOsmAndRoute;
@@ -94,10 +92,12 @@ public class GPXRouteParams {
if (reverse) {
Collections.reverse(points);
Collections.reverse(routePoints);
+ Collections.reverse(segmentEndpoints);
}
addMissingTurns = route != null && route.isEmpty();
} else if (file.isCloudmadeRouteFile() || OSMAND_ROUTER.equals(file.author)) {
- directions = RouteProvider.parseOsmAndGPXRoute(points, file, segmentEndpoints, OSMAND_ROUTER.equals(file.author), builder.leftSide, 10, selectedSegment);
+ directions = RouteProvider.parseOsmAndGPXRoute(points, file, segmentEndpoints,
+ OSMAND_ROUTER.equals(file.author), builder.leftSide, 10, selectedSegment);
if (OSMAND_ROUTER.equals(file.author) && file.hasRtePt()) {
// For files generated by OSMAND_ROUTER use directions contained unaltered
addMissingTurns = false;
@@ -106,6 +106,7 @@ public class GPXRouteParams {
// clear directions all turns should be recalculated
directions = null;
Collections.reverse(points);
+ Collections.reverse(segmentEndpoints);
addMissingTurns = true;
}
} else {
@@ -122,6 +123,7 @@ public class GPXRouteParams {
}
if (reverse) {
Collections.reverse(points);
+ Collections.reverse(segmentEndpoints);
}
}
return this;
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index 45e113c597..99cfb9f0ef 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -3,7 +3,6 @@ package net.osmand.plus.routing;
import android.os.Bundle;
import android.util.Base64;
-import android.util.Pair;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
@@ -283,19 +282,22 @@ public class RouteProvider {
}
public void insertSegments(RouteCalculationParams routeParams, List points, List directions,
- List> segmentEndpoints, boolean calculateOsmAndRouteParts) {
- for (Pair pair : segmentEndpoints) {
- int index = points.indexOf(pair.second);
- if (calculateOsmAndRouteParts && index != -1 && points.contains(pair.first)) {
- LatLon end = new LatLon(pair.second.getLatitude(), pair.second.getLongitude());
- RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, pair.first, end);
+ List segmentEndpoints, boolean calculateOsmAndRouteParts) {
+ for (int i = 0; i < segmentEndpoints.size() - 1; i++) {
+ Location prevSegmentPoint = segmentEndpoints.get(i);
+ Location newSegmentPoint = segmentEndpoints.get(i + 1);
+
+ int index = points.indexOf(newSegmentPoint);
+ if (calculateOsmAndRouteParts && index != -1 && points.contains(prevSegmentPoint)) {
+ LatLon end = new LatLon(newSegmentPoint.getLatitude(), newSegmentPoint.getLongitude());
+ RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, prevSegmentPoint, end);
if (newRes != null && newRes.isCalculated()) {
List loct = newRes.getImmutableAllLocations();
List dt = newRes.getImmutableAllDirections();
- for (RouteDirectionInfo i : dt) {
- i.routePointOffset += points.size();
+ for (RouteDirectionInfo directionInfo : dt) {
+ directionInfo.routePointOffset += points.size();
}
points.addAll(index, loct);
directions.addAll(dt);
@@ -763,7 +765,7 @@ public class RouteProvider {
}
protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile,
- List> segmentEndpoints,
+ List segmentEndpoints,
int selectedSegment) {
List segments = gpxFile.getNonEmptyTrkSegments(false);
if (selectedSegment != -1 && segments.size() > selectedSegment) {
@@ -781,7 +783,7 @@ public class RouteProvider {
}
protected static void collectSegmentPointsFromGpx(GPXFile gpxFile, List points,
- List> segmentEndpoints, int selectedSegment) {
+ List segmentEndpoints, int selectedSegment) {
List segments = gpxFile.getNonEmptyTrkSegments(false);
if (selectedSegment != -1 && segments.size() > selectedSegment) {
TrkSegment segment = segments.get(selectedSegment);
@@ -793,7 +795,7 @@ public class RouteProvider {
}
}
- protected static void collectPointsFromSegments(List segments, List points, List> segmentEndpoints) {
+ protected static void collectPointsFromSegments(List segments, List points, List segmentEndpoints) {
Location lastPoint = null;
for (int i = 0; i < segments.size(); i++) {
TrkSegment segment = segments.get(i);
@@ -801,14 +803,15 @@ public class RouteProvider {
points.add(createLocation(wptPt));
}
if (i <= segments.size() - 1 && lastPoint != null) {
- segmentEndpoints.add(new Pair<>(lastPoint, points.get((points.size() - segment.points.size()))));
+ segmentEndpoints.add(lastPoint);
+ segmentEndpoints.add(points.get((points.size() - segment.points.size())));
}
lastPoint = points.get(points.size() - 1);
}
}
protected static List parseOsmAndGPXRoute(List points, GPXFile gpxFile,
- List> segmentEndpoints,
+ List segmentEndpoints,
boolean osmandRouter, boolean leftSide,
float defSpeed, int selectedSegment) {
List directions = null;
@@ -1085,7 +1088,7 @@ public class RouteProvider {
OsmandApplication ctx = params.ctx;
List res = new ArrayList();
List dir = new ArrayList<>();
- List> segmentEndpoints = new ArrayList<>();
+ List segmentEndpoints = new ArrayList<>();
IBRouterService brouterService = ctx.getBRouterService();
if (brouterService == null) {
From 0dfd710013c435c356fbd09ec5d08a1cb9ce0a79 Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Tue, 2 Mar 2021 06:48:00 +0200
Subject: [PATCH 12/20] Calculate route between segments with gpxRouteResult
---
.../plus/routing/RouteCalculationResult.java | 8 +-
.../osmand/plus/routing/RouteProvider.java | 111 ++++++++++++------
2 files changed, 82 insertions(+), 37 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java
index a174c1550c..7b7bd7d8d9 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java
@@ -290,12 +290,16 @@ public class RouteCalculationResult {
}
public List getOriginalRoute(int startIndex) {
+ return getOriginalRoute(startIndex, segments.size());
+ }
+
+ public List getOriginalRoute(int startIndex, int endIndex) {
if (segments.size() == 0) {
return null;
}
- List list = new ArrayList();
+ List list = new ArrayList<>();
list.add(segments.get(startIndex++));
- for (int i = startIndex; i < segments.size(); i++) {
+ for (int i = startIndex; i < endIndex; i++) {
if (segments.get(i - 1) != segments.get(i)) {
list.add(segments.get(i));
}
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index 99cfb9f0ef..f717f6fe7b 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -153,8 +153,9 @@ public class RouteProvider {
GPXRouteParams gpxParams = routeParams.gpxRoute;
boolean calcWholeRoute = routeParams.gpxRoute.passWholeRoute && (routeParams.previousToRecalculate == null || !routeParams.onlyStartPointChanged);
boolean calculateOsmAndRouteParts = gpxParams.calculateOsmAndRouteParts;
+ boolean reverseRoutePoints = gpxParams.reverse && gpxParams.routePoints.size() > 1;
List gpxRouteResult = routeParams.gpxRoute.route;
- if (gpxParams.reverse && gpxParams.routePoints.size() > 1) {
+ if (reverseRoutePoints) {
List gpxRouteLocations = new ArrayList<>();
List gpxRoute = new ArrayList<>();
WptPt firstGpxPoint = gpxParams.routePoints.get(0);
@@ -214,18 +215,27 @@ public class RouteProvider {
List firstSegmentRoute = null;
List lastSegmentRoute = null;
List gpxRoute;
- if (nearestGpxPointInd > 0) {
- nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
- gpxRoute = result.getOriginalRoute(nearestGpxPointInd);
- if (gpxRoute.size() > 0) {
- gpxRoute.remove(0);
+
+ if (calculateOsmAndRouteParts && !reverseRoutePoints && !Algorithms.isEmpty(gpxParams.segmentEndpoints)) {
+ if (nearestGpxPointInd > 0) {
+ nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
}
+ gpxRoute = findRouteWithIntermediateSegments(routeParams, result, gpxRouteLocations, gpxParams.segmentEndpoints, nearestGpxPointInd);
} else {
- if (!gpxRouteLocations.isEmpty()) {
- nearestGpxLocation = gpxRouteLocations.get(0);
+ if (nearestGpxPointInd > 0) {
+ nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
+ gpxRoute = result.getOriginalRoute(nearestGpxPointInd);
+ if (gpxRoute.size() > 0) {
+ gpxRoute.remove(0);
+ }
+ } else {
+ if (!gpxRouteLocations.isEmpty()) {
+ nearestGpxLocation = gpxRouteLocations.get(0);
+ }
+ gpxRoute = result.getOriginalRoute();
}
- gpxRoute = result.getOriginalRoute();
}
+
if (calculateOsmAndRouteParts
&& routeParams.start != null && nearestGpxLocation != null
&& nearestGpxLocation.distanceTo(routeParams.start) > MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
@@ -267,7 +277,7 @@ public class RouteProvider {
}
final List inputDirections = gpxParams.directions;
List gpxDirections = calcDirections(startI, endI, inputDirections);
- insertSegments(routeParams, gpxRoute, gpxDirections, gpxParams.segmentEndpoints, calculateOsmAndRouteParts);
+ insertIntermediateSegments(routeParams, gpxRoute, gpxDirections, gpxParams.segmentEndpoints, calculateOsmAndRouteParts);
insertInitialSegment(routeParams, gpxRoute, gpxDirections, calculateOsmAndRouteParts);
insertFinalSegment(routeParams, gpxRoute, gpxDirections, calculateOsmAndRouteParts);
@@ -281,31 +291,6 @@ public class RouteProvider {
gpxParams.wpt, routeParams.gpxRoute.addMissingTurns);
}
- public void insertSegments(RouteCalculationParams routeParams, List points, List directions,
- List segmentEndpoints, boolean calculateOsmAndRouteParts) {
- for (int i = 0; i < segmentEndpoints.size() - 1; i++) {
- Location prevSegmentPoint = segmentEndpoints.get(i);
- Location newSegmentPoint = segmentEndpoints.get(i + 1);
-
- int index = points.indexOf(newSegmentPoint);
- if (calculateOsmAndRouteParts && index != -1 && points.contains(prevSegmentPoint)) {
- LatLon end = new LatLon(newSegmentPoint.getLatitude(), newSegmentPoint.getLongitude());
- RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, prevSegmentPoint, end);
-
- if (newRes != null && newRes.isCalculated()) {
- List loct = newRes.getImmutableAllLocations();
- List dt = newRes.getImmutableAllDirections();
-
- for (RouteDirectionInfo directionInfo : dt) {
- directionInfo.routePointOffset += points.size();
- }
- points.addAll(index, loct);
- directions.addAll(dt);
- }
- }
- }
- }
-
private RouteCalculationResult calculateOsmAndRouteWithIntermediatePoints(RouteCalculationParams routeParams,
final List intermediates) throws IOException {
RouteCalculationParams rp = new RouteCalculationParams();
@@ -442,6 +427,62 @@ public class RouteProvider {
}
}
+ public void insertIntermediateSegments(RouteCalculationParams routeParams, List points, List directions,
+ List segmentEndpoints, boolean calculateOsmAndRouteParts) {
+ for (int i = 0; i < segmentEndpoints.size() - 1; i++) {
+ Location prevSegmentPoint = segmentEndpoints.get(i);
+ Location newSegmentPoint = segmentEndpoints.get(i + 1);
+
+ int index = points.indexOf(newSegmentPoint);
+ if (calculateOsmAndRouteParts && index != -1 && points.contains(prevSegmentPoint)) {
+ LatLon end = new LatLon(newSegmentPoint.getLatitude(), newSegmentPoint.getLongitude());
+ RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, prevSegmentPoint, end);
+
+ if (newRes != null && newRes.isCalculated()) {
+ List loct = newRes.getImmutableAllLocations();
+ List dt = newRes.getImmutableAllDirections();
+
+ for (RouteDirectionInfo directionInfo : dt) {
+ directionInfo.routePointOffset += points.size();
+ }
+ points.addAll(index, loct);
+ directions.addAll(dt);
+ }
+ }
+ }
+ }
+
+ public List findRouteWithIntermediateSegments(RouteCalculationParams routeParams,
+ RouteCalculationResult result,
+ List gpxRouteLocations,
+ List segmentEndpoints,
+ int nearestGpxPointInd) {
+ List newGpxRoute = new ArrayList<>();
+
+ int lastIndex = nearestGpxPointInd;
+ for (int i = 0; i < segmentEndpoints.size() - 1; i++) {
+ Location prevSegmentPoint = segmentEndpoints.get(i);
+ Location newSegmentPoint = segmentEndpoints.get(i + 1);
+
+ int indexNew = findNearestGpxPointIndexFromRoute(gpxRouteLocations, newSegmentPoint, routeParams.gpxRoute.calculateOsmAndRouteParts);
+ int indexPrev = findNearestGpxPointIndexFromRoute(gpxRouteLocations, prevSegmentPoint, routeParams.gpxRoute.calculateOsmAndRouteParts);
+ if (indexPrev != -1 && indexPrev > nearestGpxPointInd && indexNew != -1) {
+ newGpxRoute.addAll(result.getOriginalRoute(lastIndex, indexPrev));
+ lastIndex = indexNew;
+
+ LatLon end = new LatLon(newSegmentPoint.getLatitude(), newSegmentPoint.getLongitude());
+ RouteCalculationResult newRes = findOfflineRouteSegment(routeParams, prevSegmentPoint, end);
+ List segmentResults = newRes.getOriginalRoute();
+ if (!Algorithms.isEmpty(segmentResults)) {
+ newGpxRoute.addAll(segmentResults);
+ }
+ }
+ }
+ newGpxRoute.addAll(result.getOriginalRoute(lastIndex));
+
+ return newGpxRoute;
+ }
+
private RouteCalculationResult findOfflineRouteSegment(RouteCalculationParams rParams, Location start,
LatLon end) {
RouteCalculationParams newParams = new RouteCalculationParams();
From c6c8b3753cc7779c5750118a7bfcfe4fc2b9ec77 Mon Sep 17 00:00:00 2001
From: Vitaliy
Date: Tue, 2 Mar 2021 07:03:30 +0200
Subject: [PATCH 13/20] Add check for distance between segments
---
.../net/osmand/plus/routing/RouteProvider.java | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
index f717f6fe7b..e5974fc32d 100644
--- a/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
+++ b/OsmAnd/src/net/osmand/plus/routing/RouteProvider.java
@@ -216,22 +216,20 @@ public class RouteProvider {
List lastSegmentRoute = null;
List gpxRoute;
+ if (nearestGpxPointInd > 0) {
+ nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
+ } else if (!gpxRouteLocations.isEmpty()) {
+ nearestGpxLocation = gpxRouteLocations.get(0);
+ }
if (calculateOsmAndRouteParts && !reverseRoutePoints && !Algorithms.isEmpty(gpxParams.segmentEndpoints)) {
- if (nearestGpxPointInd > 0) {
- nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
- }
gpxRoute = findRouteWithIntermediateSegments(routeParams, result, gpxRouteLocations, gpxParams.segmentEndpoints, nearestGpxPointInd);
} else {
if (nearestGpxPointInd > 0) {
- nearestGpxLocation = gpxRouteLocations.get(nearestGpxPointInd);
gpxRoute = result.getOriginalRoute(nearestGpxPointInd);
if (gpxRoute.size() > 0) {
gpxRoute.remove(0);
}
} else {
- if (!gpxRouteLocations.isEmpty()) {
- nearestGpxLocation = gpxRouteLocations.get(0);
- }
gpxRoute = result.getOriginalRoute();
}
}
@@ -433,6 +431,9 @@ public class RouteProvider {
Location prevSegmentPoint = segmentEndpoints.get(i);
Location newSegmentPoint = segmentEndpoints.get(i + 1);
+ if (prevSegmentPoint.distanceTo(newSegmentPoint) <= MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
+ continue;
+ }
int index = points.indexOf(newSegmentPoint);
if (calculateOsmAndRouteParts && index != -1 && points.contains(prevSegmentPoint)) {
LatLon end = new LatLon(newSegmentPoint.getLatitude(), newSegmentPoint.getLongitude());
@@ -464,6 +465,9 @@ public class RouteProvider {
Location prevSegmentPoint = segmentEndpoints.get(i);
Location newSegmentPoint = segmentEndpoints.get(i + 1);
+ if (prevSegmentPoint.distanceTo(newSegmentPoint) <= MIN_DISTANCE_FOR_INSERTING_ROUTE_SEGMENT) {
+ continue;
+ }
int indexNew = findNearestGpxPointIndexFromRoute(gpxRouteLocations, newSegmentPoint, routeParams.gpxRoute.calculateOsmAndRouteParts);
int indexPrev = findNearestGpxPointIndexFromRoute(gpxRouteLocations, prevSegmentPoint, routeParams.gpxRoute.calculateOsmAndRouteParts);
if (indexPrev != -1 && indexPrev > nearestGpxPointInd && indexNew != -1) {
From d2e36e07830507ca9ad70f6c39c568519986c55f Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 08:55:55 +0200
Subject: [PATCH 14/20] Review
---
.../res/layout/favorite_categories_dialog.xml | 2 +-
.../osmand/plus/activities/MapActivity.java | 4 ----
.../editors/PointEditorFragment.java | 2 +-
.../editors/PointEditorFragmentNew.java | 4 ++--
.../SelectFavoriteCategoryBottomSheet.java | 18 ++++++++++--------
5 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/OsmAnd/res/layout/favorite_categories_dialog.xml b/OsmAnd/res/layout/favorite_categories_dialog.xml
index a821d16b8b..5dc2e799c4 100644
--- a/OsmAnd/res/layout/favorite_categories_dialog.xml
+++ b/OsmAnd/res/layout/favorite_categories_dialog.xml
@@ -1,6 +1,6 @@
categories = gpxCategories != null ? gpxCategories.keySet() : null;
AddNewFavoriteCategoryBottomSheet fragment = AddNewFavoriteCategoryBottomSheet.createInstance(editorTag, categories, gpxFile != null);
- fragment.show(mapActivity.getSupportFragmentManager(), AddNewTrackFolderBottomSheet.class.getName());
+ if (mapActivity != null) {
+ fragment.show(mapActivity.getSupportFragmentManager(), AddNewTrackFolderBottomSheet.class.getName());
+ }
fragment.setSelectionListener(selectionListener);
dismiss();
}
@@ -142,7 +144,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
for (Map.Entry e : gpxCategories.entrySet()) {
String categoryName = e.getKey();
int favoriteCategoryCount = e.getKey().length();
- favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue(), favoriteCategoryCount, false, true));
+ favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue(), favoriteCategoryCount, false));
}
}
} else {
@@ -150,7 +152,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
for (final FavouritesDbHelper.FavoriteGroup category : gs) {
int favoriteCategoryCount = category.getPoints().size();
favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
- category.getColor(), favoriteCategoryCount, !category.isVisible(), true));
+ category.getColor(), favoriteCategoryCount, !category.isVisible()));
}
items.add(new BaseBottomSheetItem.Builder()
@@ -159,7 +161,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
}
}
- private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden, final boolean selected) {
+ private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden) {
View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
final AppCompatImageView button = (AppCompatImageView) itemView.findViewById(R.id.icon);
final int dp8 = AndroidUtils.dpToPx(app, 8f);
From be5c29f7e55966f80271ecc2c6cd2ddd06c07f25 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 09:24:37 +0200
Subject: [PATCH 15/20] Empty for 0
---
.../editors/SelectFavoriteCategoryBottomSheet.java | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index dadda5afe7..e6aafac360 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -143,14 +143,17 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
if (gpxCategories != null) {
for (Map.Entry e : gpxCategories.entrySet()) {
String categoryName = e.getKey();
- int favoriteCategoryCount = e.getKey().length();
+ String favoriteCategoryCount = String.valueOf(e.getKey().length());
favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, categoryName, e.getValue(), favoriteCategoryCount, false));
}
}
} else {
List gs = favoritesHelper.getFavoriteGroups();
for (final FavouritesDbHelper.FavoriteGroup category : gs) {
- int favoriteCategoryCount = category.getPoints().size();
+ String favoriteCategoryCount = String.valueOf(category.getPoints().size());
+ if (favoriteCategoryCount.equals("0")){
+ favoriteCategoryCount = app.getString(R.string.shared_string_empty);
+ }
favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
category.getColor(), favoriteCategoryCount, !category.isVisible()));
}
@@ -161,7 +164,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
}
}
- private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, int categoryPointCount, boolean isHidden) {
+ private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, String categoryPointCount, boolean isHidden) {
View itemView = UiUtilities.getInflater(activity, nightMode).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, null);
final AppCompatImageView button = (AppCompatImageView) itemView.findViewById(R.id.icon);
final int dp8 = AndroidUtils.dpToPx(app, 8f);
From 19c9dd0c7131a9ab71d65bedbe64afea8d6df6d4 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 11:07:31 +0200
Subject: [PATCH 16/20] Update SelectFavoriteCategoryBottomSheet.java
---
.../editors/SelectFavoriteCategoryBottomSheet.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index e6aafac360..1066d50cc3 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -33,6 +33,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.myplaces.AddNewTrackFolderBottomSheet;
+import net.osmand.util.Algorithms;
import java.util.List;
import java.util.Map;
@@ -150,9 +151,11 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
} else {
List gs = favoritesHelper.getFavoriteGroups();
for (final FavouritesDbHelper.FavoriteGroup category : gs) {
- String favoriteCategoryCount = String.valueOf(category.getPoints().size());
- if (favoriteCategoryCount.equals("0")){
+ String favoriteCategoryCount;
+ if (Algorithms.isEmpty(category.getPoints())) {
favoriteCategoryCount = app.getString(R.string.shared_string_empty);
+ } else {
+ favoriteCategoryCount = String.valueOf(category.getPoints().size());
}
favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
category.getColor(), favoriteCategoryCount, !category.isVisible()));
From 77b325c6ad83f96460183683affb1dd60091adb5 Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 11:13:44 +0200
Subject: [PATCH 17/20] Rename
---
.../osmand/plus/mapcontextmenu/editors/PointEditorFragment.java | 2 +-
.../plus/mapcontextmenu/editors/PointEditorFragmentNew.java | 2 +-
.../osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java | 2 +-
.../osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java | 2 +-
.../plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java | 2 +-
5 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
index 9b0743abf7..8b8fc64f5b 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragment.java
@@ -179,7 +179,7 @@ public abstract class PointEditorFragment extends BaseOsmAndFragment {
}
@Nullable
- protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
+ protected DialogFragment createSelectCategoryDialog() {
PointEditor editor = getEditor();
if (editor != null) {
return SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
index c75391b11c..d8eac1ca9a 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/PointEditorFragmentNew.java
@@ -732,7 +732,7 @@ public abstract class PointEditorFragmentNew extends BaseOsmAndFragment implemen
}
@Nullable
- protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
+ protected DialogFragment createSelectCategoryDialog() {
PointEditor editor = getEditor();
if (editor != null) {
return SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java
index 2539bc2f2c..9bbbb0ec34 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/RtePtEditorFragment.java
@@ -21,7 +21,7 @@ public class RtePtEditorFragment extends WptPtEditorFragment {
}
@Override
- protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
+ protected DialogFragment createSelectCategoryDialog() {
PointEditor editor = getEditor();
return editor != null ? SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag()) : null;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
index b6b0d7106a..a3efbca5ad 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragment.java
@@ -64,7 +64,7 @@ public class WptPtEditorFragment extends PointEditorFragment {
}
@Override
- protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
+ protected DialogFragment createSelectCategoryDialog() {
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
SelectFavoriteCategoryBottomSheet selectCategoryDialogFragment = SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java
index 6f60f5b8b2..456049403e 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/WptPtEditorFragmentNew.java
@@ -78,7 +78,7 @@ public class WptPtEditorFragmentNew extends PointEditorFragmentNew {
}
@Override
- protected SelectFavoriteCategoryBottomSheet createSelectCategoryDialog() {
+ protected DialogFragment createSelectCategoryDialog() {
WptPtEditor editor = getWptPtEditor();
if (editor != null) {
SelectFavoriteCategoryBottomSheet selectCategoryDialogFragment = SelectFavoriteCategoryBottomSheet.createInstance(editor.getFragmentTag());
From c52a8ae0216b76ff669a162b5961306817b7987a Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 11:29:04 +0200
Subject: [PATCH 18/20] Update AddNewFavoriteCategoryBottomSheet.java
---
.../editors/AddNewFavoriteCategoryBottomSheet.java | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
index 1e21c880b0..6687aad46b 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
@@ -189,7 +189,7 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
for (int color : ColorDialogs.pallette) {
colors.add(color);
}
- colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors);
+ colorsCard = new ColorsCard(mapActivity, selectedColor, this, colors, app.getSettings().CUSTOM_TRACK_COLORS, null);
colorsCard.setListener(this);
LinearLayout selectColor = view.findViewById(R.id.select_color);
selectColor.addView(colorsCard.build(view.getContext()));
From f400e755fd67d040548420ff787102c12b7662de Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 12:33:53 +0200
Subject: [PATCH 19/20] Fix bug addwaypoint
---
.../editors/SelectFavoriteCategoryBottomSheet.java | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index 1066d50cc3..4da4d932ee 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -160,11 +160,10 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
favoriteCategoryContainer.addView(createCategoryItem(activity, nightMode, category.getDisplayName(getContext()),
category.getColor(), favoriteCategoryCount, !category.isVisible()));
}
-
- items.add(new BaseBottomSheetItem.Builder()
- .setCustomView(favoriteCategoryList)
- .create());
}
+ items.add(new BaseBottomSheetItem.Builder()
+ .setCustomView(favoriteCategoryList)
+ .create());
}
private View createCategoryItem(@NonNull final Activity activity, boolean nightMode, final String categoryName, final int categoryColor, String categoryPointCount, boolean isHidden) {
From e035824afc02dc85aac4ab8e65f6b7c5729ad32a Mon Sep 17 00:00:00 2001
From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com>
Date: Tue, 2 Mar 2021 13:09:55 +0200
Subject: [PATCH 20/20] Fix rotate screen on list favorite group
---
.../editors/AddNewFavoriteCategoryBottomSheet.java | 1 +
.../editors/SelectFavoriteCategoryBottomSheet.java | 1 +
2 files changed, 2 insertions(+)
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
index 6687aad46b..d90c06b609 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/AddNewFavoriteCategoryBottomSheet.java
@@ -67,6 +67,7 @@ public class AddNewFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
bundle.putStringArrayList(KEY_CTX_EDIT_GPX_CATEGORIES, new ArrayList<>(gpxCategories));
}
fragment.setArguments(bundle);
+ fragment.setRetainInstance(true);
return fragment;
}
diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
index 4da4d932ee..c3ee4169dc 100644
--- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
+++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/SelectFavoriteCategoryBottomSheet.java
@@ -65,6 +65,7 @@ public class SelectFavoriteCategoryBottomSheet extends MenuBottomSheetDialogFrag
Bundle bundle = new Bundle();
bundle.putString(KEY_CTX_SEL_CAT_EDITOR_TAG, editorTag);
fragment.setArguments(bundle);
+ fragment.setRetainInstance(true);
return fragment;
}