use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.
the class MapMarkersActiveAdapter method onItemSwiped.
@Override
public void onItemSwiped(RecyclerView.ViewHolder holder) {
final int pos = holder.getAdapterPosition();
final MapMarker marker = getItem(pos);
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey, ItineraryType.MARKERS);
if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
}
changeMarkers();
notifyDataSetChanged();
snackbar = Snackbar.make(holder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, pos);
changeMarkers();
notifyDataSetChanged();
}
});
UiUtilities.setupSnackbar(snackbar, night);
snackbar.show();
}
use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.
the class MapMarkersGroupsAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, final int position) {
UiUtilities iconsCache = app.getUIUtilities();
if (holder instanceof MapMarkerItemViewHolder) {
final MapMarkerItemViewHolder itemViewHolder = (MapMarkerItemViewHolder) holder;
final MapMarker marker = (MapMarker) getItem(position);
final boolean markerInHistory = marker.history;
int color;
if (marker.history) {
color = R.color.icon_color_default_dark;
} else {
color = MapMarker.getColorId(marker.colorIndex);
}
ImageView markerImageViewToUpdate;
int drawableResToUpdate;
int actionIconColor = night ? R.color.icon_color_primary_dark : R.color.icon_color_primary_light;
final boolean markerToHighlight = showDirectionMarkers.contains(marker);
if (showDirectionEnabled && markerToHighlight) {
itemViewHolder.iconDirection.setVisibility(View.GONE);
itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_arrow_marker_diretion, color));
itemViewHolder.mainLayout.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.list_divider_dark : R.color.markers_top_bar_background));
itemViewHolder.title.setTextColor(ContextCompat.getColor(mapActivity, night ? R.color.text_color_primary_dark : R.color.color_white));
itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_divider_color));
itemViewHolder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, R.drawable.marker_circle_background_on_map_with_inset));
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed, R.color.color_white));
itemViewHolder.description.setTextColor(ContextCompat.getColor(mapActivity, R.color.map_markers_on_map_color));
drawableResToUpdate = R.drawable.ic_arrow_marker_diretion;
markerImageViewToUpdate = itemViewHolder.icon;
} else {
itemViewHolder.iconDirection.setVisibility(View.VISIBLE);
itemViewHolder.icon.setImageDrawable(iconsCache.getIcon(R.drawable.ic_action_flag, color));
itemViewHolder.mainLayout.setBackgroundColor(ColorUtilities.getListBgColor(mapActivity, night));
itemViewHolder.title.setTextColor(ColorUtilities.getPrimaryTextColor(mapActivity, night));
itemViewHolder.divider.setBackgroundColor(ContextCompat.getColor(mapActivity, night ? R.color.app_bar_color_dark : R.color.divider_color_light));
itemViewHolder.optionsBtn.setBackgroundDrawable(AppCompatResources.getDrawable(mapActivity, night ? R.drawable.marker_circle_background_dark_with_inset : R.drawable.marker_circle_background_light_with_inset));
itemViewHolder.optionsBtn.setImageDrawable(iconsCache.getIcon(markerInHistory ? R.drawable.ic_action_reset_to_default_dark : R.drawable.ic_action_marker_passed, actionIconColor));
itemViewHolder.description.setTextColor(ColorUtilities.getDefaultIconColor(mapActivity, night));
drawableResToUpdate = R.drawable.ic_direction_arrow;
markerImageViewToUpdate = itemViewHolder.iconDirection;
}
itemViewHolder.title.setText(marker.getName(app));
boolean noGroup = marker.groupName == null;
boolean createdEarly = false;
if (noGroup && !markerInHistory) {
Calendar currentDateCalendar = Calendar.getInstance();
currentDateCalendar.setTimeInMillis(System.currentTimeMillis());
int currentDay = currentDateCalendar.get(Calendar.DAY_OF_YEAR);
int currentYear = currentDateCalendar.get(Calendar.YEAR);
Calendar markerCalendar = Calendar.getInstance();
markerCalendar.setTimeInMillis(System.currentTimeMillis());
int markerDay = markerCalendar.get(Calendar.DAY_OF_YEAR);
int markerYear = markerCalendar.get(Calendar.YEAR);
createdEarly = currentDay - markerDay >= 2 || currentYear != markerYear;
}
if (markerInHistory || createdEarly) {
itemViewHolder.point.setVisibility(View.VISIBLE);
itemViewHolder.description.setVisibility(View.VISIBLE);
long date;
if (markerInHistory) {
date = marker.visitedDate;
} else {
date = marker.creationDate;
}
itemViewHolder.description.setText(app.getString(R.string.passed, OsmAndFormatter.getFormattedDate(app, date)));
} else {
itemViewHolder.point.setVisibility(View.GONE);
itemViewHolder.description.setVisibility(View.GONE);
}
itemViewHolder.optionsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int position = itemViewHolder.getAdapterPosition();
if (position < 0) {
return;
}
if (markerInHistory) {
app.getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
} else {
app.getMapMarkersHelper().moveMapMarkerToHistory(marker);
}
updateDisplayedData();
if (!markerInHistory) {
snackbar = Snackbar.make(itemViewHolder.itemView, R.string.marker_moved_to_history, Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
mapActivity.getMyApplication().getMapMarkersHelper().restoreMarkerFromHistory(marker, 0);
updateDisplayedData();
}
});
UiUtilities.setupSnackbar(snackbar, night);
snackbar.show();
}
}
});
itemViewHolder.iconReorder.setVisibility(View.GONE);
itemViewHolder.flagIconLeftSpace.setVisibility(View.VISIBLE);
boolean lastItem = position == getItemCount() - 1;
if ((getItemCount() > position + 1 && getItemViewType(position + 1) == HEADER_TYPE) || lastItem) {
itemViewHolder.divider.setVisibility(View.GONE);
} else {
itemViewHolder.divider.setVisibility(View.VISIBLE);
}
itemViewHolder.bottomShadow.setVisibility(lastItem ? View.VISIBLE : View.GONE);
LatLon markerLatLon = new LatLon(marker.getLatitude(), marker.getLongitude());
updateLocationViewCache.arrowResId = drawableResToUpdate;
updateLocationViewCache.arrowColor = markerToHighlight ? color : 0;
app.getUIUtilities().updateLocationView(updateLocationViewCache, markerImageViewToUpdate, itemViewHolder.distance, markerLatLon);
} else if (holder instanceof MapMarkerHeaderViewHolder) {
final MapMarkerHeaderViewHolder headerViewHolder = (MapMarkerHeaderViewHolder) holder;
final Object header = getItem(position);
String headerString;
if (header instanceof MarkerGroupItem) {
headerViewHolder.icon.setVisibility(View.GONE);
headerViewHolder.iconSpace.setVisibility(View.VISIBLE);
headerString = ((MarkerGroupItem) header).getName(app);
headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
headerViewHolder.articleDescription.setVisibility(View.GONE);
} else if (header instanceof GroupHeader) {
final GroupHeader groupHeader = (GroupHeader) header;
final MapMarkersGroup group = groupHeader.getGroup();
String groupName = group.getName();
if (groupName.isEmpty()) {
groupName = app.getString(R.string.shared_string_favorites);
} else if (group.getType() == ItineraryType.TRACK) {
groupName = groupName.replace(IndexConstants.GPX_FILE_EXT, "").replace("/", " ").replace("_", " ");
}
if (group.isDisabled()) {
headerString = groupName;
} else {
headerString = groupName + " \u2014 " + group.getActiveMarkers().size() + "/" + group.getMarkers().size();
}
headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
final boolean groupIsDisabled = group.isDisabled();
headerViewHolder.disableGroupSwitch.setVisibility(View.VISIBLE);
final TravelArticle article = group.getWikivoyageArticle();
if (article != null && !groupIsDisabled) {
headerViewHolder.articleDescription.setVisibility(View.VISIBLE);
View.OnClickListener openWikiwoyageArticle = new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mapActivity.getSupportFragmentManager() != null) {
WikivoyageArticleDialogFragment.showInstance(app, mapActivity.getSupportFragmentManager(), article.generateIdentifier(), article.getLang());
}
}
};
if (article.getContent().isEmpty()) {
headerViewHolder.content.setVisibility(View.GONE);
} else {
headerViewHolder.content.setText(article.getContent());
headerViewHolder.content.setOnClickListener(openWikiwoyageArticle);
}
headerViewHolder.button.setText(R.string.shared_string_read);
headerViewHolder.button.setOnClickListener(openWikiwoyageArticle);
} else {
headerViewHolder.articleDescription.setVisibility(View.GONE);
}
CompoundButton.OnCheckedChangeListener checkedChangeListener = new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean enabled) {
final MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
final GPXFile[] gpxFile = new GPXFile[1];
boolean disabled = !enabled;
if (groupIsDisabled && !group.wasShown() && group.getWptCategories().size() > 1) {
group.setWasShown(true);
Bundle args = new Bundle();
args.putString(SelectWptCategoriesBottomSheetDialogFragment.GPX_FILE_PATH_KEY, group.getGpxPath(app));
args.putString(SelectWptCategoriesBottomSheetDialogFragment.ACTIVE_CATEGORIES_KEY, group.getWptCategoriesString());
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);
if (group.getType() == ItineraryType.TRACK) {
group.setVisibleUntilRestart(disabled);
String gpxPath = group.getGpxPath(app);
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxPath);
if (selectedGpxFile != null) {
gpxFile[0] = selectedGpxFile.getGpxFile();
} else {
// TODO IO load in another thread ?
gpxFile[0] = GPXUtilities.loadGPXFile(new File(gpxPath));
}
switchGpxVisibility(gpxFile[0], selectedGpxFile, !disabled);
}
if (!disabled) {
mapMarkersHelper.enableGroup(group);
} else {
mapMarkersHelper.runSynchronization(group);
}
if (disabled) {
snackbar = Snackbar.make(holder.itemView, app.getString(R.string.group_will_be_removed_after_restart), Snackbar.LENGTH_LONG).setAction(R.string.shared_string_undo, new View.OnClickListener() {
@Override
public void onClick(View view) {
if (group.getType() == ItineraryType.TRACK && gpxFile[0] != null) {
switchGpxVisibility(gpxFile[0], null, true);
}
mapMarkersHelper.enableGroup(group);
}
});
UiUtilities.setupSnackbar(snackbar, night);
snackbar.show();
}
}
};
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(null);
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(checkedChangeListener);
UiUtilities.setupCompoundButton(headerViewHolder.disableGroupSwitch, night, UiUtilities.CompoundButtonType.GLOBAL);
} else {
throw new IllegalArgumentException("Unsupported header");
}
headerViewHolder.title.setText(headerString);
headerViewHolder.bottomShadow.setVisibility(position == getItemCount() - 1 ? View.VISIBLE : View.GONE);
} else if (holder instanceof MapMarkersShowHideHistoryViewHolder) {
final MapMarkersShowHideHistoryViewHolder showHideHistoryViewHolder = (MapMarkersShowHideHistoryViewHolder) holder;
final ShowHideHistoryButton showHideHistoryButton = (ShowHideHistoryButton) getItem(position);
final boolean showHistory = showHideHistoryButton.showHistory;
if (position == getItemCount() - 1) {
showHideHistoryViewHolder.bottomShadow.setVisibility(View.VISIBLE);
} else {
showHideHistoryViewHolder.bottomShadow.setVisibility(View.GONE);
}
showHideHistoryViewHolder.title.setText(app.getString(showHistory ? R.string.hide_passed : R.string.show_passed));
showHideHistoryViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
showHideHistoryButton.showHistory = !showHistory;
createDisplayGroups();
notifyDataSetChanged();
}
});
} else if (holder instanceof MapMarkerCategoriesViewHolder) {
final MapMarkerCategoriesViewHolder categoriesViewHolder = (MapMarkerCategoriesViewHolder) holder;
final Object header = getItem(position);
if (header instanceof CategoriesSubHeader) {
final CategoriesSubHeader categoriesSubHeader = (CategoriesSubHeader) header;
final MapMarkersGroup group = categoriesSubHeader.getGroup();
View.OnClickListener openChooseCategoriesDialog = 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(app));
args.putBoolean(SelectWptCategoriesBottomSheetDialogFragment.UPDATE_CATEGORIES_KEY, true);
args.putStringArrayList(SelectWptCategoriesBottomSheetDialogFragment.ACTIVE_CATEGORIES_KEY, new ArrayList<String>(group.getWptCategories()));
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(app)));
}
}
};
categoriesViewHolder.title.setText(getGroupWptCategoriesString(group));
categoriesViewHolder.divider.setVisibility(View.VISIBLE);
categoriesViewHolder.button.setCompoundDrawablesWithIntrinsicBounds(null, null, app.getUIUtilities().getIcon(R.drawable.ic_action_filter, night ? R.color.wikivoyage_active_dark : R.color.wikivoyage_active_light), null);
categoriesViewHolder.button.setOnClickListener(openChooseCategoriesDialog);
categoriesViewHolder.title.setOnClickListener(openChooseCategoriesDialog);
}
}
}
use of net.osmand.plus.mapmarkers.MapMarkersGroup in project Osmand by osmandapp.
the class GpxSelectionHelper method syncGpxWithMarkers.
private void syncGpxWithMarkers(GPXFile gpxFile) {
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group != null) {
mapMarkersHelper.runSynchronization(group);
}
}
Aggregations