diff --git a/OsmAnd/res/layout/map_marker_item_header.xml b/OsmAnd/res/layout/map_marker_item_header.xml index e8184ea870..b4bb2b9212 100644 --- a/OsmAnd/res/layout/map_marker_item_header.xml +++ b/OsmAnd/res/layout/map_marker_item_header.xml @@ -46,6 +46,14 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java index c37de47294..1046dd3eaf 100644 --- a/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java +++ b/OsmAnd/src/net/osmand/plus/MapMarkersHelper.java @@ -418,7 +418,7 @@ public class MapMarkersHelper { if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) { return; } - createHeaderInGroup(mapMarkersGroup); + createHeadersInGroup(mapMarkersGroup); int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size(); ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton(); if (showHideHistoryButton != null) { @@ -460,15 +460,22 @@ public class MapMarkersHelper { } } - private void createHeaderInGroup(@NonNull MapMarkersGroup group) { + private void createHeadersInGroup(@NonNull MapMarkersGroup group) { GroupHeader header = new GroupHeader(); + CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader(); + WikivoyageArticleSubHeader wikivoyageArticleSubHeader = new WikivoyageArticleSubHeader(); 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; + categoriesSubHeader.iconRes = R.drawable.ic_action_filter; } header.group = group; + categoriesSubHeader.group = group; + wikivoyageArticleSubHeader.group = group; group.header = header; + group.categoriesSubHeader = categoriesSubHeader; + group.wikivoyageArticleSubHeader = wikivoyageArticleSubHeader; } private void removeMarkerFromGroup(MapMarker marker) { @@ -534,7 +541,7 @@ public class MapMarkersHelper { if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) { MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path)); group.disabled = true; - createHeaderInGroup(group); + createHeadersInGroup(group); res.add(group); } } @@ -555,7 +562,7 @@ public class MapMarkersHelper { if (search == null) { MapMarkersGroup group = createGPXMarkerGroup(path); group.disabled = true; - createHeaderInGroup(group); + createHeadersInGroup(group); res.add(group); } } @@ -1212,10 +1219,14 @@ public class MapMarkersHelper { private long creationDate; private boolean disabled; private boolean visible = true; + private boolean wasShown = false; private boolean visibleUntilRestart; private List markers = new ArrayList<>(); + private TravelArticle wikivoyageArticle; // TODO should be removed from this class: private GroupHeader header; + private CategoriesSubHeader categoriesSubHeader; + private WikivoyageArticleSubHeader wikivoyageArticleSubHeader; private ShowHideHistoryButton showHideHistoryButton; public MapMarkersGroup() { @@ -1236,6 +1247,14 @@ public class MapMarkersHelper { return id; } + public TravelArticle getWikivoyageArticle() { + return wikivoyageArticle; + } + + public void setWikivoyageArticle(TravelArticle wikivoyageArticle) { + this.wikivoyageArticle = wikivoyageArticle; + } + public String getName() { return name; } @@ -1248,6 +1267,10 @@ public class MapMarkersHelper { this.wptCategories = wptCategories; } + public Set getWptCategories() { + return wptCategories; + } + public boolean isDisabled() { return disabled; } @@ -1260,6 +1283,14 @@ public class MapMarkersHelper { return visible; } + public boolean wasShown() { + return wasShown; + } + + public void setWasShown(boolean wasShown) { + this.wasShown = wasShown; + } + public void setVisibleUntilRestart(boolean visibleUntilRestart) { this.visibleUntilRestart = visibleUntilRestart; } @@ -1272,6 +1303,14 @@ public class MapMarkersHelper { return header; } + public CategoriesSubHeader getCategoriesSubHeader() { + return categoriesSubHeader; + } + + public WikivoyageArticleSubHeader getWikivoyageArticleSubHeader() { + return wikivoyageArticleSubHeader; + } + public ShowHideHistoryButton getShowHideHistoryButton() { return showHideHistoryButton; } @@ -1323,6 +1362,32 @@ public class MapMarkersHelper { } } + public static class CategoriesSubHeader { + private int iconRes; + private MapMarkersGroup group; + + public int getIconRes() { + return iconRes; + } + + public MapMarkersGroup getGroup() { + return group; + } + } + + public static class WikivoyageArticleSubHeader { + 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..c639a0e867 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 super.getRightBottomButtonTextId(); + } else { + return R.string.shared_string_add; + } + } + + @Override + protected int getDismissButtonTextId() { + if (isUpdateMode) { + return R.string.shared_string_update; + } else { + return super.getDismissButtonTextId(); + } + } + + protected void onDismissButtonClickAction() { + if (isUpdateMode) { + updateAddOrEnableGroupWptCategories(); + } } @Override protected void onRightBottomButtonClick() { + updateAddOrEnableGroupWptCategories(); + dismiss(); + } + + private void updateAddOrEnableGroupWptCategories() { 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..15b9b9c928 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerCategoriesViewHolder.java @@ -0,0 +1,25 @@ +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; + final View divider; + + public MapMarkerCategoriesViewHolder(View itemView) { + super(itemView); + icon = (ImageView) itemView.findViewById(R.id.icon_right); + title = (TextView) itemView.findViewById(R.id.title); + divider = itemView.findViewById(R.id.divider); + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java index 9d71f5f943..dfd4f80baa 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerHeaderViewHolder.java @@ -16,6 +16,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder { final TextView title; final SwitchCompat disableGroupSwitch; final View bottomShadow; + final View divider; public MapMarkerHeaderViewHolder(View itemView) { super(itemView); @@ -24,5 +25,6 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder { title = (TextView) itemView.findViewById(R.id.title); disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch); bottomShadow = itemView.findViewById(R.id.bottom_shadow); + divider = itemView.findViewById(R.id.divider); } } diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerOpenWikivoyageArticleViewHolder.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerOpenWikivoyageArticleViewHolder.java new file mode 100644 index 0000000000..fb8ec18859 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkerOpenWikivoyageArticleViewHolder.java @@ -0,0 +1,23 @@ +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 MapMarkerOpenWikivoyageArticleViewHolder extends RecyclerView.ViewHolder { + + final ImageView icon; + final TextView title; + final View divider; + + public MapMarkerOpenWikivoyageArticleViewHolder(View itemView) { + super(itemView); + icon = (ImageView) itemView.findViewById(R.id.icon_right); + title = (TextView) itemView.findViewById(R.id.title); + divider = itemView.findViewById(R.id.divider); + } +} diff --git a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java index 00d5f875f0..5d5a30d94f 100644 --- a/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java +++ b/OsmAnd/src/net/osmand/plus/mapmarkers/adapters/MapMarkersGroupsAdapter.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapmarkers.adapters; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.Snackbar; import android.support.v4.content.ContextCompat; @@ -9,7 +10,9 @@ import android.view.View; import android.view.ViewGroup; import android.widget.CompoundButton; import android.widget.ImageView; + import net.osmand.AndroidUtils; +import net.osmand.IndexConstants; import net.osmand.data.LatLon; import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GpxSelectionHelper; @@ -25,6 +28,10 @@ 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.SelectWptCategoriesBottomSheetDialogFragment; +import net.osmand.plus.wikivoyage.article.WikivoyageArticleDialogFragment; +import net.osmand.plus.wikivoyage.data.TravelArticle; +import net.osmand.plus.wikivoyage.data.TravelDbHelper; import java.io.File; import java.text.SimpleDateFormat; @@ -39,6 +46,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.WikivoyageArticleSubHeader wikivoyageArticleSubHeader = group.getWikivoyageArticleSubHeader(); + items.add(wikivoyageArticleSubHeader); + group.setWikivoyageArticle(art); + } + } + } + } + if (group.getWptCategories() == null || group.getWptCategories().isEmpty()) { + helper.updateGroupWptCategories(group, getGpxFile(group.getGpxPath()).getPointsByCategories().keySet()); + } populateAdapterWithGroupMarkers(group, getItemCount()); } } } + private GPXFile getGpxFile(String filePath) { + if (filePath != null) { + OsmandApplication app = mapActivity.getMyApplication(); + SelectedGpxFile selectedGpx = app.getSelectedGpxHelper().getSelectedFileByPath(filePath); + if (selectedGpx != null && selectedGpx.getGpxFile() != null) { + return selectedGpx.getGpxFile(); + } + return GPXUtilities.loadGPXFile(app, new File(filePath)); + } + return null; + } + private void populateAdapterWithGroupMarkers(MapMarkersGroup group, int position) { if (position != RecyclerView.NO_POSITION) { ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); @@ -221,6 +264,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter