From c41238fdb1e67ecf8ea636fdea2f4c6718582174 Mon Sep 17 00:00:00 2001 From: Chumva Date: Tue, 17 Apr 2018 12:20:29 +0300 Subject: [PATCH] add categories and open wikivoyage article to markers --- .../res/layout/map_marker_item_categories.xml | 78 +++++++++++++ .../src/net/osmand/plus/MapMarkersHelper.java | 43 +++++++ ...ptCategoriesBottomSheetDialogFragment.java | 36 +++++- .../MapMarkerCategoriesViewHolder.java | 24 ++++ .../MapMarkerWikivoyageArticleViewHolder.java | 21 ++++ .../adapters/MapMarkersGroupsAdapter.java | 107 +++++++++++++++++- 6 files changed, 303 insertions(+), 6 deletions(-) create mode 100644 OsmAnd/res/layout/map_marker_item_categories.xml create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerCategoriesViewHolder.java create mode 100644 OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerWikivoyageArticleViewHolder.java diff --git a/OsmAnd/res/layout/map_marker_item_categories.xml b/OsmAnd/res/layout/map_marker_item_categories.xml new file mode 100644 index 0000000000..09d317a74b --- /dev/null +++ b/OsmAnd/res/layout/map_marker_item_categories.xml @@ -0,0 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index c37de47294..e1c25ddb27 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -462,13 +462,20 @@ public class MapMarkersHelper { private void createHeaderInGroup(@NonNull MapMarkersGroup group) { GroupHeader header = new GroupHeader(); + CategoriesHeader categoriesHeader = new CategoriesHeader(); + WikivoyageArticleHeader wikivoyageArticleHeader = new WikivoyageArticleHeader(); int type = group.getType(); if (type != -1) { header.iconRes = type == MapMarkersGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_polygom_dark; + categoriesHeader.iconRes = R.drawable.ic_action_filter; } header.group = group; + categoriesHeader.group = group; + wikivoyageArticleHeader.group = group; group.header = header; + group.categoriesHeader = categoriesHeader; + group.wikivoyageArticleHeader = wikivoyageArticleHeader; } private void removeMarkerFromGroup(MapMarker marker) { @@ -1216,6 +1223,8 @@ public class MapMarkersHelper { private List markers = new ArrayList<>(); // TODO should be removed from this class: private GroupHeader header; + private CategoriesHeader categoriesHeader; + private WikivoyageArticleHeader wikivoyageArticleHeader; private ShowHideHistoryButton showHideHistoryButton; public MapMarkersGroup() { @@ -1272,6 +1281,14 @@ public class MapMarkersHelper { return header; } + public CategoriesHeader getCategoriesHeader() { + return categoriesHeader; + } + + public WikivoyageArticleHeader getWikivoyageArticleHeader() { + return wikivoyageArticleHeader; + } + public ShowHideHistoryButton getShowHideHistoryButton() { return showHideHistoryButton; } @@ -1323,6 +1340,32 @@ public class MapMarkersHelper { } } + public static class CategoriesHeader { + private int iconRes; + private MapMarkersGroup group; + + public int getIconRes() { + return iconRes; + } + + public MapMarkersGroup getGroup() { + return group; + } + } + + public static class WikivoyageArticleHeader { + private int iconRes; + private MapMarkersGroup group; + + public int getIconRes() { + return iconRes; + } + + public MapMarkersGroup getGroup() { + return group; + } + } + public static class MapMarker implements LocationPoint { private static int[] colors; diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java index 4e076694ec..b428722e64 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/SelectWptCategoriesBottomSheetDialogFragment.java @@ -32,19 +32,22 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee public static final String TAG = "SelectWptCategoriesBottomSheetDialogFragment"; public static final String GPX_FILE_PATH_KEY = "gpx_file_path"; + public static final String UPDATE_CATEGORIES_KEY = "update_categories"; private GPXFile gpxFile; private Set selectedCategories = new HashSet<>(); private List categoryItems = new ArrayList<>(); + private boolean isUpdateMode =false; + @Override public void createMenuItems(Bundle savedInstanceState) { gpxFile = getGpxFile(); if (gpxFile == null) { return; } - + isUpdateMode = getArguments().getBoolean(UPDATE_CATEGORIES_KEY); items.add(new TitleItem(getGpxName(gpxFile))); items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description))); @@ -108,11 +111,35 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee @Override protected int getRightBottomButtonTextId() { - return R.string.shared_string_import; + if (isUpdateMode) { + return -1; + } else { + return super.getRightBottomButtonTextId(); + } + } + + @Override + protected int getDismissButtonTextId() { + if (isUpdateMode) { + return R.string.update; + } else { + return super.getDismissButtonTextId(); + } + } + + protected void onDismissButtonClickAction() { + if (isUpdateMode) { + updateGroupWptCategories(); + } } @Override protected void onRightBottomButtonClick() { + updateGroupWptCategories(); + dismiss(); + } + + private void updateGroupWptCategories() { OsmandApplication app = getMyApplication(); GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper(); MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper(); @@ -122,12 +149,11 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee gpxSelectionHelper.selectGpxFile(gpxFile, true, false); } MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile); - if(group == null) { + if (group == null) { group = mapMarkersHelper.addOrEnableGroup(gpxFile); } mapMarkersHelper.updateGroupWptCategories(group, selectedCategories); - - dismiss(); + mapMarkersHelper.runSynchronization(group); } private boolean isAllChecked() { diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerCategoriesViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerCategoriesViewHolder.java new file mode 100644 index 0000000000..675100f419 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerCategoriesViewHolder.java @@ -0,0 +1,24 @@ +package net.osmand.plus.mapmarkers.adapters; + + +import android.support.v7.widget.RecyclerView; +import android.support.v7.widget.SwitchCompat; +import android.view.View; +import android.widget.ImageButton; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.plus.R; + +public class MapMarkerCategoriesViewHolder extends RecyclerView.ViewHolder { + + final ImageView icon; + final TextView title; + + public MapMarkerCategoriesViewHolder(View itemView) { + super(itemView); + icon = (ImageView) itemView.findViewById(R.id.icon_right); + title = (TextView) itemView.findViewById(R.id.title); + } +} + diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerWikivoyageArticleViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerWikivoyageArticleViewHolder.java new file mode 100644 index 0000000000..08b5a7e573 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerWikivoyageArticleViewHolder.java @@ -0,0 +1,21 @@ +package net.osmand.plus.mapmarkers.adapters; + + +import android.support.v7.widget.RecyclerView; +import android.view.View; +import android.widget.ImageView; +import android.widget.TextView; + +import net.osmand.plus.R; + +public class MapMarkerWikivoyageArticleViewHolder extends RecyclerView.ViewHolder { + + final ImageView icon; + final TextView title; + + public MapMarkerWikivoyageArticleViewHolder(View itemView) { + super(itemView); + icon = (ImageView) itemView.findViewById(R.id.icon_right); + title = (TextView) itemView.findViewById(R.id.title); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 00d5f875f0..931ba35787 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -1,16 +1,24 @@ package net.osmand.plus.mapmarkers.adapters; +import android.os.AsyncTask; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; +import android.support.v7.app.AppCompatActivity; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.ImageView; +import android.widget.Toast; + import net.osmand.AndroidUtils; +import net.osmand.IndexConstants; +import net.osmand.OsmAndCollator; import net.osmand.data.LatLon; +import net.osmand.plus.GPXDatabase; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; @@ -25,6 +33,12 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashLocationFragment; +import net.osmand.plus.mapmarkers.AddTracksGroupBottomSheetDialogFragment; +import net.osmand.plus.mapmarkers.SelectWptCategoriesBottomSheetDialogFragment; +import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; +import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; +import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper; import java.io.File; import java.text.SimpleDateFormat; @@ -39,6 +53,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles(); + for (TravelArticle art : savedArticles) { + String gpxName = travelDbHelper.getGPXName(art); + File path = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName); + if (path.getAbsolutePath().equals(group.getGpxPath())) { + MapMarkersHelper.WikivoyageArticleHeader wikivoyageArticleHeader = group.getWikivoyageArticleHeader(); + items.add(wikivoyageArticleHeader); + } + } + } + } populateAdapterWithGroupMarkers(group, getItemCount()); } } @@ -221,6 +255,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter savedArticles = travelDbHelper.getLocalDataHelper().getSavedArticles(); + for (TravelArticle art : savedArticles) { + String gpxName = travelDbHelper.getGPXName(art); + File path = mapActivity.getMyApplication().getAppPath(IndexConstants.GPX_TRAVEL_DIR + gpxName); + if (path.getAbsolutePath().equals(group.getGpxPath())) { + MapMarkersHelper.WikivoyageArticleHeader wikivoyageArticleHeader = group.getWikivoyageArticleHeader(); + items.add(wikivoyageArticleHeader); + test = art; + } + } + } + if (mapActivity.getSupportFragmentManager() != null && test != null) { + WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), test.getCityId(), test.getLang()); + } + } + }); } } @@ -490,6 +591,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter