Merge pull request #5247 from osmandapp/MarkersCategories

Markers categories
This commit is contained in:
vshcherb 2018-04-17 17:02:08 +02:00 committed by GitHub
commit 73a60c8e89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 344 additions and 10 deletions

View file

@ -46,6 +46,14 @@
</LinearLayout> </LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_marginLeft="@dimen/map_button_shadow_width"
android:layout_marginStart="@dimen/map_button_shadow_width"
tools:background="?attr/dashboard_divider"/>
<include <include
android:id="@+id/bottom_shadow" android:id="@+id/bottom_shadow"
layout="@layout/card_bottom_divider" layout="@layout/card_bottom_divider"

View file

@ -0,0 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:descendantFocusability="blocksDescendants"
android:orientation="vertical">
<ImageView
android:id="@+id/top_divider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:visibility="visible"
tools:visibility="visible" />
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/map_button_shadow_width"
android:background="?attr/selectableItemBackground">
<ImageView
android:id="@+id/icon_left"
android:layout_width="@dimen/map_button_shadow_width"
android:layout_height="@dimen/map_button_shadow_width"
android:visibility="invisible" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<android.support.v7.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:textColor="@color/dashboard_blue"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Van Gogh Museum" />
</LinearLayout>
<ImageView
android:id="@+id/icon_right"
android:layout_width="wrap_content"
android:layout_height="@dimen/map_button_shadow_width"
android:paddingEnd="@dimen/list_content_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
tools:src="@drawable/ic_action_filter" />
</LinearLayout>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
</LinearLayout>
</LinearLayout>

View file

@ -418,7 +418,7 @@ public class MapMarkersHelper {
if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) { if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) {
return; return;
} }
createHeaderInGroup(mapMarkersGroup); createHeadersInGroup(mapMarkersGroup);
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size(); int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton(); ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
if (showHideHistoryButton != null) { 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(); GroupHeader header = new GroupHeader();
CategoriesSubHeader categoriesSubHeader = new CategoriesSubHeader();
WikivoyageArticleSubHeader wikivoyageArticleSubHeader = new WikivoyageArticleSubHeader();
int type = group.getType(); int type = group.getType();
if (type != -1) { if (type != -1) {
header.iconRes = type == MapMarkersGroup.FAVORITES_TYPE header.iconRes = type == MapMarkersGroup.FAVORITES_TYPE
? R.drawable.ic_action_fav_dark : R.drawable.ic_action_polygom_dark; ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_polygom_dark;
categoriesSubHeader.iconRes = R.drawable.ic_action_filter;
} }
header.group = group; header.group = group;
categoriesSubHeader.group = group;
wikivoyageArticleSubHeader.group = group;
group.header = header; group.header = header;
group.categoriesSubHeader = categoriesSubHeader;
group.wikivoyageArticleSubHeader = wikivoyageArticleSubHeader;
} }
private void removeMarkerFromGroup(MapMarker marker) { private void removeMarkerFromGroup(MapMarker marker) {
@ -534,7 +541,7 @@ public class MapMarkersHelper {
if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) { if (search == null && selected.getGpxFile() != null && selected.getGpxFile().path != null) {
MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path)); MapMarkersGroup group = createGPXMarkerGroup(new File(selected.getGpxFile().path));
group.disabled = true; group.disabled = true;
createHeaderInGroup(group); createHeadersInGroup(group);
res.add(group); res.add(group);
} }
} }
@ -555,7 +562,7 @@ public class MapMarkersHelper {
if (search == null) { if (search == null) {
MapMarkersGroup group = createGPXMarkerGroup(path); MapMarkersGroup group = createGPXMarkerGroup(path);
group.disabled = true; group.disabled = true;
createHeaderInGroup(group); createHeadersInGroup(group);
res.add(group); res.add(group);
} }
} }
@ -1212,10 +1219,14 @@ public class MapMarkersHelper {
private long creationDate; private long creationDate;
private boolean disabled; private boolean disabled;
private boolean visible = true; private boolean visible = true;
private boolean wasShown = false;
private boolean visibleUntilRestart; private boolean visibleUntilRestart;
private List<MapMarker> markers = new ArrayList<>(); private List<MapMarker> markers = new ArrayList<>();
private TravelArticle wikivoyageArticle;
// TODO should be removed from this class: // TODO should be removed from this class:
private GroupHeader header; private GroupHeader header;
private CategoriesSubHeader categoriesSubHeader;
private WikivoyageArticleSubHeader wikivoyageArticleSubHeader;
private ShowHideHistoryButton showHideHistoryButton; private ShowHideHistoryButton showHideHistoryButton;
public MapMarkersGroup() { public MapMarkersGroup() {
@ -1236,6 +1247,14 @@ public class MapMarkersHelper {
return id; return id;
} }
public TravelArticle getWikivoyageArticle() {
return wikivoyageArticle;
}
public void setWikivoyageArticle(TravelArticle wikivoyageArticle) {
this.wikivoyageArticle = wikivoyageArticle;
}
public String getName() { public String getName() {
return name; return name;
} }
@ -1248,6 +1267,10 @@ public class MapMarkersHelper {
this.wptCategories = wptCategories; this.wptCategories = wptCategories;
} }
public Set<String> getWptCategories() {
return wptCategories;
}
public boolean isDisabled() { public boolean isDisabled() {
return disabled; return disabled;
} }
@ -1260,6 +1283,14 @@ public class MapMarkersHelper {
return visible; return visible;
} }
public boolean wasShown() {
return wasShown;
}
public void setWasShown(boolean wasShown) {
this.wasShown = wasShown;
}
public void setVisibleUntilRestart(boolean visibleUntilRestart) { public void setVisibleUntilRestart(boolean visibleUntilRestart) {
this.visibleUntilRestart = visibleUntilRestart; this.visibleUntilRestart = visibleUntilRestart;
} }
@ -1272,6 +1303,14 @@ public class MapMarkersHelper {
return header; return header;
} }
public CategoriesSubHeader getCategoriesSubHeader() {
return categoriesSubHeader;
}
public WikivoyageArticleSubHeader getWikivoyageArticleSubHeader() {
return wikivoyageArticleSubHeader;
}
public ShowHideHistoryButton getShowHideHistoryButton() { public ShowHideHistoryButton getShowHideHistoryButton() {
return showHideHistoryButton; 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 { public static class MapMarker implements LocationPoint {
private static int[] colors; private static int[] colors;

View file

@ -32,19 +32,22 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
public static final String TAG = "SelectWptCategoriesBottomSheetDialogFragment"; public static final String TAG = "SelectWptCategoriesBottomSheetDialogFragment";
public static final String GPX_FILE_PATH_KEY = "gpx_file_path"; public static final String GPX_FILE_PATH_KEY = "gpx_file_path";
public static final String UPDATE_CATEGORIES_KEY = "update_categories";
private GPXFile gpxFile; private GPXFile gpxFile;
private Set<String> selectedCategories = new HashSet<>(); private Set<String> selectedCategories = new HashSet<>();
private List<BottomSheetItemWithCompoundButton> categoryItems = new ArrayList<>(); private List<BottomSheetItemWithCompoundButton> categoryItems = new ArrayList<>();
private boolean isUpdateMode =false;
@Override @Override
public void createMenuItems(Bundle savedInstanceState) { public void createMenuItems(Bundle savedInstanceState) {
gpxFile = getGpxFile(); gpxFile = getGpxFile();
if (gpxFile == null) { if (gpxFile == null) {
return; return;
} }
isUpdateMode = getArguments().getBoolean(UPDATE_CATEGORIES_KEY);
items.add(new TitleItem(getGpxName(gpxFile))); items.add(new TitleItem(getGpxName(gpxFile)));
items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description))); items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
@ -108,11 +111,35 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
@Override @Override
protected int getRightBottomButtonTextId() { 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 @Override
protected void onRightBottomButtonClick() { protected void onRightBottomButtonClick() {
updateAddOrEnableGroupWptCategories();
dismiss();
}
private void updateAddOrEnableGroupWptCategories() {
OsmandApplication app = getMyApplication(); OsmandApplication app = getMyApplication();
GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper(); GpxSelectionHelper gpxSelectionHelper = app.getSelectedGpxHelper();
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper(); MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
@ -122,12 +149,11 @@ public class SelectWptCategoriesBottomSheetDialogFragment extends MenuBottomShee
gpxSelectionHelper.selectGpxFile(gpxFile, true, false); gpxSelectionHelper.selectGpxFile(gpxFile, true, false);
} }
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile); MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if(group == null) { if (group == null) {
group = mapMarkersHelper.addOrEnableGroup(gpxFile); group = mapMarkersHelper.addOrEnableGroup(gpxFile);
} }
mapMarkersHelper.updateGroupWptCategories(group, selectedCategories); mapMarkersHelper.updateGroupWptCategories(group, selectedCategories);
mapMarkersHelper.runSynchronization(group);
dismiss();
} }
private boolean isAllChecked() { private boolean isAllChecked() {

View file

@ -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);
}
}

View file

@ -16,6 +16,7 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
final TextView title; final TextView title;
final SwitchCompat disableGroupSwitch; final SwitchCompat disableGroupSwitch;
final View bottomShadow; final View bottomShadow;
final View divider;
public MapMarkerHeaderViewHolder(View itemView) { public MapMarkerHeaderViewHolder(View itemView) {
super(itemView); super(itemView);
@ -24,5 +25,6 @@ public class MapMarkerHeaderViewHolder extends RecyclerView.ViewHolder {
title = (TextView) itemView.findViewById(R.id.title); title = (TextView) itemView.findViewById(R.id.title);
disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch); disableGroupSwitch = (SwitchCompat) itemView.findViewById(R.id.disable_group_switch);
bottomShadow = itemView.findViewById(R.id.bottom_shadow); bottomShadow = itemView.findViewById(R.id.bottom_shadow);
divider = itemView.findViewById(R.id.divider);
} }
} }

View file

@ -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);
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.mapmarkers.adapters; package net.osmand.plus.mapmarkers.adapters;
import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
@ -9,7 +10,9 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CompoundButton; import android.widget.CompoundButton;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.plus.GPXUtilities.GPXFile; import net.osmand.plus.GPXUtilities.GPXFile;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
@ -25,6 +28,10 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.DashLocationFragment; 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.io.File;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
@ -39,6 +46,8 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
private static final int HEADER_TYPE = 1; private static final int HEADER_TYPE = 1;
private static final int MARKER_TYPE = 2; private static final int MARKER_TYPE = 2;
private static final int SHOW_HIDE_HISTORY_TYPE = 3; private static final int SHOW_HIDE_HISTORY_TYPE = 3;
private static final int CATEGORIES_TYPE = 4;
private static final int WIKIVOYAGE_ARTICLE_TYPE = 5;
private static final int TODAY_HEADER = 56; private static final int TODAY_HEADER = 56;
private static final int YESTERDAY_HEADER = 57; private static final int YESTERDAY_HEADER = 57;
@ -145,11 +154,45 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else { } else {
GroupHeader header = group.getGroupHeader(); GroupHeader header = group.getGroupHeader();
items.add(header); items.add(header);
if (!group.isDisabled()) {
if (group.getWptCategories() != null && !group.getWptCategories().isEmpty()) {
MapMarkersHelper.CategoriesSubHeader categoriesSubHeader = group.getCategoriesSubHeader();
items.add(categoriesSubHeader);
}
TravelDbHelper travelDbHelper = mapActivity.getMyApplication().getTravelDbHelper();
if (travelDbHelper.getSelectedTravelBook() != null) {
List<TravelArticle> 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()); 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) { private void populateAdapterWithGroupMarkers(MapMarkersGroup group, int position) {
if (position != RecyclerView.NO_POSITION) { if (position != RecyclerView.NO_POSITION) {
ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton(); ShowHideHistoryButton showHideHistoryButton = group.getShowHideHistoryButton();
@ -221,6 +264,12 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else if (viewType == SHOW_HIDE_HISTORY_TYPE) { } else if (viewType == SHOW_HIDE_HISTORY_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_show_hide_history, viewGroup, false); View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_show_hide_history, viewGroup, false);
return new MapMarkersShowHideHistoryViewHolder(view); return new MapMarkersShowHideHistoryViewHolder(view);
} else if (viewType == CATEGORIES_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_subheader, viewGroup, false);
return new MapMarkerCategoriesViewHolder(view);
}else if (viewType == WIKIVOYAGE_ARTICLE_TYPE) {
View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.map_marker_item_subheader, viewGroup, false);
return new MapMarkerOpenWikivoyageArticleViewHolder(view);
} else { } else {
throw new IllegalArgumentException("Unsupported view type"); throw new IllegalArgumentException("Unsupported view type");
} }
@ -391,8 +440,9 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
headerViewHolder.icon.setVisibility(View.VISIBLE); headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE); headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color)); headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
boolean groupIsDisabled = group.isDisabled(); final boolean groupIsDisabled = group.isDisabled();
headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE); headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
headerViewHolder.divider.setVisibility(group.getWptCategories().isEmpty() ? View.GONE : View.VISIBLE);
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() { CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override @Override
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) { public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
@ -400,6 +450,17 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
final GPXFile[] gpxFile = new GPXFile[1]; final GPXFile[] gpxFile = new GPXFile[1];
boolean disabled = !enabled; boolean disabled = !enabled;
if (groupIsDisabled && !group.wasShown() && !group.getWptCategories().isEmpty()) {
group.setWasShown(true);
Bundle args = new Bundle();
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath());
args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
}
mapMarkersHelper.updateGroupDisabled(group, disabled); mapMarkersHelper.updateGroupDisabled(group, disabled);
if (group.getType() == MapMarkersGroup.GPX_TYPE) { if (group.getType() == MapMarkersGroup.GPX_TYPE) {
group.setVisibleUntilRestart(disabled); group.setVisibleUntilRestart(disabled);
@ -467,6 +528,49 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
notifyDataSetChanged(); notifyDataSetChanged();
} }
}); });
} else if (holder instanceof MapMarkerCategoriesViewHolder) {
final MapMarkerCategoriesViewHolder categoriesViewHolder = (MapMarkerCategoriesViewHolder) holder;
final Object header = getItem(position);
if (header instanceof MapMarkersHelper.CategoriesSubHeader) {
final MapMarkersHelper.CategoriesSubHeader categoriesSubHeader = (MapMarkersHelper.CategoriesSubHeader) header;
final MapMarkersGroup group = categoriesSubHeader.getGroup();
categoriesViewHolder.icon.setImageDrawable(iconsCache.getIcon(categoriesSubHeader.getIconRes(), R.color.divider_color));
categoriesViewHolder.title.setText(group.getWptCategoriesString());
categoriesViewHolder.divider.setVisibility(View.VISIBLE);
categoriesViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!group.getWptCategories().isEmpty()) {
Bundle args = new Bundle();
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath());
args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
SelectWptCategoriesBottomSheetDialogFragment fragment = new SelectWptCategoriesBottomSheetDialogFragment();
fragment.setArguments(args);
fragment.setUsedOnMap(false);
fragment.show(mapActivity.getSupportFragmentManager(), SelectWptCategoriesBottomSheetDialogFragment.TAG);
} else {
mapActivity.getMyApplication().getMapMarkersHelper().addOrEnableGpxGroup(new File(group.getGpxPath()));
}
}
});
}
} else if (holder instanceof MapMarkerOpenWikivoyageArticleViewHolder) {
final MapMarkerOpenWikivoyageArticleViewHolder wikivoyageArticleViewHolder = (MapMarkerOpenWikivoyageArticleViewHolder) holder;
final Object header = getItem(position);
final MapMarkersHelper.WikivoyageArticleSubHeader wikivoyageArticleSubHeader = (MapMarkersHelper.WikivoyageArticleSubHeader) header;
final MapMarkersGroup group = wikivoyageArticleSubHeader.getGroup();
wikivoyageArticleViewHolder.title.setText(R.string.context_menu_read_article);
wikivoyageArticleViewHolder.icon.setVisibility(View.INVISIBLE);
wikivoyageArticleViewHolder.divider.setVisibility(View.VISIBLE);
wikivoyageArticleViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TravelArticle article = group.getWikivoyageArticle();
if (mapActivity.getSupportFragmentManager() != null && article != null) {
WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), article.getCityId(), article.getLang());
}
}
});
} }
} }
@ -490,6 +594,10 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
return HEADER_TYPE; return HEADER_TYPE;
} else if (item instanceof ShowHideHistoryButton) { } else if (item instanceof ShowHideHistoryButton) {
return SHOW_HIDE_HISTORY_TYPE; return SHOW_HIDE_HISTORY_TYPE;
}else if (item instanceof MapMarkersHelper.CategoriesSubHeader) {
return CATEGORIES_TYPE;
}else if (item instanceof MapMarkersHelper.WikivoyageArticleSubHeader) {
return WIKIVOYAGE_ARTICLE_TYPE;
} else { } else {
throw new IllegalArgumentException("Unsupported view type"); throw new IllegalArgumentException("Unsupported view type");
} }