Remove unnecessary method from MapMarkersHelper

This commit is contained in:
Alexander Sytnyk 2018-03-21 14:50:49 +02:00
parent f19477be2b
commit b60130f7e8
3 changed files with 14 additions and 24 deletions

View file

@ -356,6 +356,9 @@ public class MapMarkersHelper {
} }
public void updateGroup(MapMarkersGroup mapMarkersGroup) { public void updateGroup(MapMarkersGroup mapMarkersGroup) {
if (mapMarkersGroup.getId() == null || mapMarkersGroup.getName() == null) {
return;
}
createHeaderInGroup(mapMarkersGroup); createHeaderInGroup(mapMarkersGroup);
int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size(); int historyMarkersCount = mapMarkersGroup.getHistoryMarkers().size();
ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton(); ShowHideHistoryButton showHideHistoryButton = mapMarkersGroup.getShowHideHistoryButton();
@ -399,21 +402,19 @@ public class MapMarkersHelper {
} }
private void createHeaderInGroup(@NonNull MapMarkersGroup group) { private void createHeaderInGroup(@NonNull MapMarkersGroup group) {
if (group.getName() != null) { GroupHeader header = new GroupHeader();
GroupHeader header = new GroupHeader(); 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;
}
header.group = group;
group.header = header;
} }
header.group = group;
group.header = header;
} }
private void removeMarkerFromGroup(MapMarker marker) { private void removeMarkerFromGroup(MapMarker marker) {
if (marker != null) { if (marker != null) {
MapMarkersGroup mapMarkersGroup = getMapMarkerGroupByName(marker.groupName); MapMarkersGroup mapMarkersGroup = getMapMarkerGroupById(marker.groupKey);
if (mapMarkersGroup != null) { if (mapMarkersGroup != null) {
mapMarkersGroup.getMarkers().remove(marker); mapMarkersGroup.getMarkers().remove(marker);
updateGroup(mapMarkersGroup); updateGroup(mapMarkersGroup);
@ -434,17 +435,6 @@ public class MapMarkersHelper {
} }
} }
@Nullable
public MapMarkersGroup getMapMarkerGroupByName(String name) {
for (MapMarkersGroup group : mapMarkersGroups) {
if ((name == null && group.getName() == null)
|| (group.getName() != null && group.getName().equals(name))) {
return group;
}
}
return null;
}
@Nullable @Nullable
public MapMarkersGroup getMapMarkerGroupById(String id) { public MapMarkersGroup getMapMarkerGroupById(String id) {
for (MapMarkersGroup group : mapMarkersGroups) { for (MapMarkersGroup group : mapMarkersGroups) {

View file

@ -8,8 +8,8 @@ import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.View; import android.view.View;
import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup; import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.MapMarkersHelper.OnGroupSyncedListener;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
@ -60,7 +60,7 @@ public abstract class AddGroupBottomSheetDialogFragment extends MenuBottomSheetD
} }
protected void addAndSyncGroup(MapMarkersGroup group) { protected void addAndSyncGroup(MapMarkersGroup group) {
getMyApplication().getMapMarkersHelper().addAndSyncGroup(group, new MapMarkersHelper.OnGroupSyncedListener() { getMyApplication().getMapMarkersHelper().addAndSyncGroup(group, new OnGroupSyncedListener() {
@Override @Override
public void onSyncDone() { public void onSyncDone() {
Fragment parent = getParentFragment(); Fragment parent = getParentFragment();

View file

@ -237,7 +237,7 @@ public class MapMarkersActiveAdapter extends RecyclerView.Adapter<MapMarkerItemV
final int pos = holder.getAdapterPosition(); final int pos = holder.getAdapterPosition();
final MapMarker marker = getItem(pos); final MapMarker marker = getItem(pos);
mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker); mapActivity.getMyApplication().getMapMarkersHelper().moveMapMarkerToHistory(marker);
MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupByName(marker.groupName); MapMarkersHelper.MapMarkersGroup group = mapActivity.getMyApplication().getMapMarkersHelper().getMapMarkerGroupById(marker.groupKey);
if (group != null) { if (group != null) {
mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group); mapActivity.getMyApplication().getMapMarkersHelper().updateGroup(group);
} }