Add "Remove from Map Markers" item to EditFavoriteGroupDialog

This commit is contained in:
Alexander Sytnyk 2017-09-15 16:18:30 +03:00
parent 0f66f0595f
commit 8430f9d5fb
4 changed files with 57 additions and 4 deletions

View file

@ -181,6 +181,36 @@
</LinearLayout>
<LinearLayout
android:id="@+id/remove_from_markers_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/list_item_height"
android:paddingLeft="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/remove_from_markers_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:src="@drawable/ic_action_delete_dark"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="6dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingTop="6dp"
android:text="@string/remove_from_map_markers"
android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
</LinearLayout>
<LinearLayout
android:id="@+id/share_view"
android:layout_width="match_parent"

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="remove_from_map_markers">Remove from Map Markers</string>
<string name="descendingly">Descendingly</string>
<string name="ascendingly">Ascendingly</string>
<string name="map_orientation_change_in_accordance_with_speed">Map orientation change in accordance with speed</string>

View file

@ -287,6 +287,10 @@ public class MapMarkersHelper {
}
}
public boolean isGroupSynced(MarkersSyncGroup group) {
return markersDbHelper.getGroup(group.getId()) != null;
}
public void syncAllGroups() {
List<MarkersSyncGroup> groups = markersDbHelper.getAllGroups();
for (MarkersSyncGroup gr : groups) {
@ -515,7 +519,8 @@ public class MapMarkersHelper {
if (syncGroupId != null) {
markersDbHelper.removeActiveMarkersFromSyncGroup(syncGroupId);
for (Iterator<MapMarker> iterator = mapMarkers.iterator(); iterator.hasNext(); ) {
if (iterator.next().groupKey.equals(syncGroupId)) {
String groupKey = iterator.next().groupKey;
if (groupKey != null && groupKey.equals(syncGroupId)) {
iterator.remove();
}
}

View file

@ -175,21 +175,23 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
}
});
final MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
final MarkersSyncGroup syncGroup = new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE);
boolean groupSyncedWithMarkers = markersHelper.isGroupSynced(syncGroup);
View addToMarkersView = view.findViewById(R.id.add_to_markers_view);
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0) {
if (app.getSettings().USE_MAP_MARKERS.get() && group.points.size() > 0 && !groupSyncedWithMarkers) {
((ImageView) view.findViewById(R.id.add_to_markers_icon))
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_flag_dark));
addToMarkersView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapMarkersHelper markersHelper = getMyApplication().getMapMarkersHelper();
List<LatLon> points = new ArrayList<>(group.points.size());
List<PointDescription> names = new ArrayList<>(group.points.size());
for (FavouritePoint fp : group.points) {
points.add(new LatLon(fp.getLatitude(), fp.getLongitude()));
names.add(new PointDescription(PointDescription.POINT_TYPE_MAP_MARKER, fp.getName()));
}
MarkersSyncGroup syncGroup = new MarkersSyncGroup(group.name, group.name, MarkersSyncGroup.FAVORITES_TYPE);
markersHelper.addMarkersSyncGroup(syncGroup);
markersHelper.addMapMarkers(points, names, syncGroup);
dismiss();
@ -200,6 +202,21 @@ public class EditFavoriteGroupDialogFragment extends BottomSheetDialogFragment {
addToMarkersView.setVisibility(View.GONE);
}
View removeFromMarkersView = view.findViewById(R.id.remove_from_markers_view);
if (app.getSettings().USE_MAP_MARKERS.get() && groupSyncedWithMarkers) {
removeFromMarkersView.setVisibility(View.VISIBLE);
((ImageView) view.findViewById(R.id.remove_from_markers_icon))
.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_delete_dark));
removeFromMarkersView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
markersHelper.removeMarkersSyncGroup(syncGroup.getId(), true);
dismiss();
MapActivity.launchMapActivityMoveToTop(getActivity());
}
});
}
View shareView = view.findViewById(R.id.share_view);
if (group.points.size() > 0) {
((ImageView) view.findViewById(R.id.share_icon))