Add disabling groups

This commit is contained in:
PavelRatushnyi 2017-09-21 09:47:49 +03:00
parent d2cb331beb
commit a5e0a5120e
2 changed files with 34 additions and 51 deletions

View file

@ -873,19 +873,12 @@ public class MapMarkersHelper {
}
private void createHeaderAndHistoryButtonInGroup(MapMarkersGroup group) {
String markerGroupName = group.getName();
if (markerGroupName.equals("")) {
markerGroupName = ctx.getString(R.string.shared_string_favorites);
}
GroupHeader header = new GroupHeader();
header.setGroupName(markerGroupName);
int type = group.getType();
if (type != -1) {
header.setIconRes(type == MapMarkersHelper.MarkersSyncGroup.FAVORITES_TYPE ? R.drawable.ic_action_fav_dark : R.drawable.ic_action_track_16);
}
header.setActiveMarkersCount(group.getActiveMarkers().size());
header.setMarkersCount(group.getMarkers().size());
header.setColor(group.getColor());
header.setGroup(group);
group.setGroupHeader(header);
updateShowHideHistoryButtonInGroup(group);
}
@ -981,6 +974,7 @@ public class MapMarkersHelper {
private long creationDate;
private ShowHideHistoryButton showHideHistoryButton;
private int color;
private boolean disabled;
public String getName() {
return name;
@ -1057,6 +1051,14 @@ public class MapMarkersHelper {
public void setColor(int color) {
this.color = color;
}
public boolean isDisabled() {
return disabled;
}
public void setDisabled(boolean disabled) {
this.disabled = disabled;
}
}
public static class ShowHideHistoryButton {
@ -1081,35 +1083,8 @@ public class MapMarkersHelper {
}
public static class GroupHeader {
private String groupName;
private int activeMarkersCount;
private int markersCount;
private int iconRes;
private int color;
public String getGroupName() {
return groupName;
}
public void setGroupName(String groupName) {
this.groupName = groupName;
}
public int getActiveMarkersCount() {
return activeMarkersCount;
}
public void setActiveMarkersCount(int activeMarkersCount) {
this.activeMarkersCount = activeMarkersCount;
}
public int getMarkersCount() {
return markersCount;
}
public void setMarkersCount(int markersCount) {
this.markersCount = markersCount;
}
private MapMarkersGroup group;
public int getIconRes() {
return iconRes;
@ -1119,12 +1094,12 @@ public class MapMarkersHelper {
this.iconRes = iconRes;
}
public int getColor() {
return color;
public MapMarkersGroup getGroup() {
return group;
}
public void setColor(int color) {
this.color = color;
public void setGroup(MapMarkersGroup group) {
this.group = group;
}
}
}

View file

@ -5,6 +5,7 @@ import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import net.osmand.data.LatLon;
@ -249,13 +250,6 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
}
}
}
if (group != null) {
GroupHeader header = group.getGroupHeader();
if (header != null) {
header.setActiveMarkersCount(group.getActiveMarkers().size());
header.setMarkersCount(group.getMarkers().size());
}
}
updateShowDirectionMarkers();
notifyDataSetChanged();
}
@ -296,14 +290,28 @@ public class MapMarkersGroupsAdapter extends RecyclerView.Adapter<RecyclerView.V
} else {
headerString = String.valueOf(dateHeader);
}
headerViewHolder.disableGroupSwitch.setVisibility(View.GONE);
} else if (header instanceof GroupHeader) {
GroupHeader groupHeader = (GroupHeader) header;
headerString = groupHeader.getGroupName() + " \u2014 "
+ groupHeader.getActiveMarkersCount()
+ "/" + (groupHeader.getMarkersCount());
final GroupHeader groupHeader = (GroupHeader) header;
String groupName = groupHeader.getGroup().getName();
if (groupName.equals("")) {
groupName = app.getString(R.string.shared_string_favorites);
}
headerString = groupName + " \u2014 "
+ groupHeader.getGroup().getActiveMarkers().size()
+ "/" + groupHeader.getGroup().getMarkers().size();
headerViewHolder.icon.setVisibility(View.VISIBLE);
headerViewHolder.iconSpace.setVisibility(View.GONE);
headerViewHolder.icon.setImageDrawable(iconsCache.getIcon(groupHeader.getIconRes(), R.color.divider_color));
boolean groupIsDisabled = groupHeader.getGroup().isDisabled();
headerViewHolder.disableGroupSwitch.setChecked(!groupIsDisabled);
headerViewHolder.disableGroupSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
groupHeader.getGroup().setDisabled(!b);
notifyDataSetChanged();
}
});
} else {
throw new IllegalArgumentException("Unsupported header");
}