colorize selected items icons
This commit is contained in:
parent
429e4ca6cf
commit
7e7f5ed34b
2 changed files with 39 additions and 20 deletions
|
@ -36,12 +36,16 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
private OsmandApplication app;
|
||||
private UiUtilities uiUtilities;
|
||||
private List<? super Object> items;
|
||||
private int activeColorRes;
|
||||
|
||||
DuplicatesSettingsAdapter(OsmandApplication app, List<? super Object> items, boolean nightMode) {
|
||||
this.app = app;
|
||||
this.items = items;
|
||||
this.nightMode = nightMode;
|
||||
this.uiUtilities = app.getUIUtilities();
|
||||
uiUtilities = app.getUIUtilities();
|
||||
activeColorRes = nightMode
|
||||
? R.color.icon_color_active_dark
|
||||
: R.color.icon_color_active_light;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
@ -93,30 +97,30 @@ public class DuplicatesSettingsAdapter extends RecyclerView.Adapter<RecyclerView
|
|||
} else if (currentItem instanceof QuickAction) {
|
||||
QuickAction action = (QuickAction) currentItem;
|
||||
itemHolder.title.setText(action.getName(app));
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(action.getIconRes(), nightMode));
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(action.getIconRes(), activeColorRes));
|
||||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
} else if (currentItem instanceof PoiUIFilter) {
|
||||
PoiUIFilter filter = (PoiUIFilter) currentItem;
|
||||
itemHolder.title.setText(filter.getName());
|
||||
int iconRes = RenderingIcons.getBigIconResourceId(filter.getIconId());
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, nightMode));
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, activeColorRes));
|
||||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
} else if (currentItem instanceof ITileSource) {
|
||||
itemHolder.title.setText(((ITileSource) currentItem).getName());
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_map, nightMode));
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_map, activeColorRes));
|
||||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
} else if (currentItem instanceof File) {
|
||||
File file = (File) currentItem;
|
||||
itemHolder.title.setText(file.getName());
|
||||
if (file.getAbsolutePath().contains(IndexConstants.RENDERERS_DIR)) {
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_map_style, nightMode));
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_map_style, activeColorRes));
|
||||
} else if (file.getAbsolutePath().contains(IndexConstants.ROUTING_PROFILES_DIR)) {
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_route_distance, nightMode));
|
||||
itemHolder.icon.setImageDrawable(uiUtilities.getIcon(R.drawable.ic_action_route_distance, activeColorRes));
|
||||
}
|
||||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
} else if (currentItem instanceof AvoidRoadInfo) {
|
||||
itemHolder.title.setText(((AvoidRoadInfo) currentItem).name);
|
||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, nightMode));
|
||||
itemHolder.icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, activeColorRes));
|
||||
itemHolder.subTitle.setVisibility(View.GONE);
|
||||
}
|
||||
itemHolder.divider.setVisibility(shouldShowDivider(position) ? View.VISIBLE : View.GONE);
|
||||
|
|
|
@ -39,19 +39,25 @@ import static net.osmand.view.ThreeStateCheckbox.State.MISC;
|
|||
class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
||||
|
||||
private OsmandApplication app;
|
||||
private UiUtilities uiUtilities;
|
||||
private List<? super Object> dataToOperate;
|
||||
private List<AdditionalDataWrapper> dataList;
|
||||
private boolean nightMode;
|
||||
private boolean importState;
|
||||
private int profileColor;
|
||||
private int activeColorRes;
|
||||
|
||||
ExportImportSettingsAdapter(OsmandApplication app, boolean nightMode, boolean importState) {
|
||||
this.app = app;
|
||||
this.nightMode = nightMode;
|
||||
this.importState = importState;
|
||||
this.dataList = new ArrayList<>();
|
||||
this.dataToOperate = new ArrayList<>();
|
||||
this.profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
|
||||
dataList = new ArrayList<>();
|
||||
dataToOperate = new ArrayList<>();
|
||||
profileColor = app.getSettings().getApplicationMode().getIconColorInfo().getColor(nightMode);
|
||||
uiUtilities = app.getUIUtilities();
|
||||
activeColorRes = nightMode
|
||||
? R.color.icon_color_active_dark
|
||||
: R.color.icon_color_active_light;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -78,7 +84,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
lineDivider.setVisibility(importState || isExpanded || isLastGroup ? View.GONE : View.VISIBLE);
|
||||
cardTopDivider.setVisibility(importState ? View.VISIBLE : View.GONE);
|
||||
cardBottomDivider.setVisibility(importState && !isExpanded ? View.VISIBLE : View.GONE);
|
||||
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, profileColor)));
|
||||
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, activeColorRes)));
|
||||
|
||||
final List<?> listItems = dataList.get(groupPosition).getItems();
|
||||
subTextTv.setText(String.valueOf(listItems.size()));
|
||||
|
@ -125,6 +131,7 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
final Object currentItem = dataList.get(groupPosition).getItems().get(childPosition);
|
||||
|
||||
boolean isLastGroup = groupPosition == getGroupCount() - 1;
|
||||
boolean itemSelected = dataToOperate.contains(currentItem);
|
||||
final AdditionalDataWrapper.Type type = dataList.get(groupPosition).getType();
|
||||
|
||||
TextView title = child.findViewById(R.id.title_tv);
|
||||
|
@ -136,9 +143,9 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
|
||||
lineDivider.setVisibility(!importState && isLastChild && !isLastGroup ? View.VISIBLE : View.GONE);
|
||||
cardBottomDivider.setVisibility(importState && isLastChild ? View.VISIBLE : View.GONE);
|
||||
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, profileColor)));
|
||||
CompoundButtonCompat.setButtonTintList(checkBox, ColorStateList.valueOf(ContextCompat.getColor(app, activeColorRes)));
|
||||
|
||||
checkBox.setChecked(dataToOperate.contains(currentItem));
|
||||
checkBox.setChecked(itemSelected);
|
||||
checkBox.setClickable(false);
|
||||
child.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
@ -172,42 +179,42 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
}
|
||||
int profileIconRes = AndroidUtils.getDrawableId(app, ((ApplicationMode.ApplicationModeBean) currentItem).iconName);
|
||||
ProfileIconColors iconColor = ((ApplicationMode.ApplicationModeBean) currentItem).iconColor;
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(profileIconRes, iconColor.getColor(nightMode)));
|
||||
icon.setImageDrawable(uiUtilities.getIcon(profileIconRes, iconColor.getColor(nightMode)));
|
||||
break;
|
||||
case QUICK_ACTIONS:
|
||||
title.setText(((QuickAction) currentItem).getName(app.getApplicationContext()));
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(((QuickAction) currentItem).getIconRes(), nightMode));
|
||||
setupIcon(icon, ((QuickAction) currentItem).getIconRes(), itemSelected);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
case POI_TYPES:
|
||||
title.setText(((PoiUIFilter) currentItem).getName());
|
||||
int iconRes = RenderingIcons.getBigIconResourceId(((PoiUIFilter) currentItem).getIconId());
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(iconRes != 0 ? iconRes : R.drawable.ic_person, profileColor));
|
||||
setupIcon(icon, iconRes != 0 ? iconRes : R.drawable.ic_person, itemSelected);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
case MAP_SOURCES:
|
||||
title.setText(((ITileSource) currentItem).getName());
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_map, nightMode));
|
||||
setupIcon(icon, R.drawable.ic_map, itemSelected);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
case CUSTOM_RENDER_STYLE:
|
||||
String renderName = ((File) currentItem).getName();
|
||||
renderName = renderName.replace('_', ' ').replaceAll(IndexConstants.RENDERER_INDEX_EXT, "");
|
||||
title.setText(renderName);
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_map_style, nightMode));
|
||||
setupIcon(icon, R.drawable.ic_action_map_style, itemSelected);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
case CUSTOM_ROUTING:
|
||||
String routingName = ((File) currentItem).getName();
|
||||
routingName = routingName.replace('_', ' ').replaceAll(".xml", "");
|
||||
title.setText(routingName);
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_route_distance, nightMode));
|
||||
setupIcon(icon, R.drawable.ic_action_route_distance, itemSelected);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
case AVOID_ROADS:
|
||||
AvoidRoadInfo avoidRoadInfo = (AvoidRoadInfo) currentItem;
|
||||
title.setText(avoidRoadInfo.name);
|
||||
icon.setImageDrawable(app.getUIUtilities().getIcon(R.drawable.ic_action_alert, nightMode));
|
||||
setupIcon(icon, R.drawable.ic_action_alert, itemSelected);
|
||||
subText.setVisibility(View.GONE);
|
||||
break;
|
||||
default:
|
||||
|
@ -277,6 +284,14 @@ class ExportImportSettingsAdapter extends OsmandBaseExpandableListAdapter {
|
|||
}
|
||||
}
|
||||
|
||||
private void setupIcon(ImageView icon, int iconRes, boolean itemSelected) {
|
||||
if (itemSelected) {
|
||||
icon.setImageDrawable(uiUtilities.getIcon(iconRes, activeColorRes));
|
||||
} else {
|
||||
icon.setImageDrawable(uiUtilities.getIcon(iconRes, nightMode));
|
||||
}
|
||||
}
|
||||
|
||||
public void updateSettingsList(List<AdditionalDataWrapper> settingsList) {
|
||||
this.dataList = settingsList;
|
||||
notifyDataSetChanged();
|
||||
|
|
Loading…
Reference in a new issue