selected icon colors, refactor list item with icon

This commit is contained in:
veliymolfar 2020-04-23 12:15:16 +03:00
parent c35722aa3a
commit 76d56578e4
3 changed files with 91 additions and 87 deletions

View file

@ -1,96 +1,101 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="?attr/bg_color" android:background="?attr/bg_color"
android:gravity="center_vertical"
android:minHeight="60dp" android:minHeight="60dp"
android:orientation="horizontal"
tools:layout_height="60dp"> tools:layout_height="60dp">
<androidx.appcompat.widget.AppCompatImageView <androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon" android:id="@+id/icon"
android:layout_width="24dp" android:layout_width="24dp"
android:layout_height="24dp" android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
tools:src="@drawable/ic_action_gabout_dark"/> android:layout_marginLeft="16dp"
tools:src="@drawable/ic_action_gabout_dark" />
<LinearLayout <LinearLayout
android:id="@+id/text_wrapper"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_toEndOf="@+id/icon" android:layout_marginLeft="16dp"
android:layout_toLeftOf="@+id/secondary_icon" android:gravity="center_vertical"
android:layout_toRightOf="@+id/icon"
android:layout_toStartOf="@+id/secondary_icon"
android:minHeight="60dp"
android:orientation="vertical"> android:orientation="vertical">
<View <LinearLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.ListItemTitle" android:orientation="horizontal">
tools:text="Some title text"/>
<androidx.appcompat.widget.AppCompatTextView <LinearLayout
android:id="@+id/description" android:id="@+id/text_wrapper"
android:layout_width="match_parent" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:ellipsize="end" android:layout_gravity="center_vertical"
android:lines="1" android:layout_weight="1"
android:textSize="@dimen/default_desc_text_size" android:gravity="center_vertical"
tools:text="Some very long subtitle text, that won't fit into one line"/> android:minHeight="60dp"
android:orientation="vertical">
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some title text" />
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:lines="1"
android:textSize="@dimen/default_desc_text_size"
tools:text="Some very long subtitle text, that won't fit into one line" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/secondary_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="16dp"
tools:src="@drawable/ic_action_gabout_dark" />
<View
android:id="@+id/divider_vertical"
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/content_padding_small"
android:background="?attr/dashboard_divider"
android:visibility="gone"
tools:visibility="visible" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/toggle_item"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:focusable="false" />
</LinearLayout>
<View <View
android:layout_width="0dp" android:id="@+id/divider"
android:layout_height="0dp" android:layout_width="wrap_content"
android:layout_weight="1"/> android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
</LinearLayout> </LinearLayout>
<androidx.appcompat.widget.AppCompatImageView </LinearLayout>
android:id="@+id/secondary_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_margin="16dp"
android:layout_toLeftOf="@+id/toggle_item"
android:layout_toStartOf="@+id/toggle_item"
tools:src="@drawable/ic_action_gabout_dark"/>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/toggle_item"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:focusable="false"/>
<View
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_alignLeft="@+id/text_wrapper"
android:layout_alignParentBottom="true"
android:layout_alignStart="@+id/text_wrapper"
android:background="?attr/dashboard_divider"/>
</RelativeLayout>

View file

@ -288,8 +288,7 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
PoiCategory category = getItem(position); PoiCategory category = getItem(position);
if (category != null) { if (category != null) {
AppCompatImageView iconView = (AppCompatImageView) row.findViewById(R.id.icon); AppCompatImageView iconView = (AppCompatImageView) row.findViewById(R.id.icon);
AppCompatImageView secondaryIconView = (AppCompatImageView) row row.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
.findViewById(R.id.secondary_icon);
AppCompatTextView titleView = (AppCompatTextView) row.findViewById(R.id.title); AppCompatTextView titleView = (AppCompatTextView) row.findViewById(R.id.title);
AppCompatTextView descView = (AppCompatTextView) row.findViewById(R.id.description); AppCompatTextView descView = (AppCompatTextView) row.findViewById(R.id.description);
SwitchCompat check = (SwitchCompat) row.findViewById(R.id.toggle_item); SwitchCompat check = (SwitchCompat) row.findViewById(R.id.toggle_item);
@ -298,18 +297,14 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
boolean categorySelected = filter.isTypeAccepted(category); boolean categorySelected = filter.isTypeAccepted(category);
UiUtilities ic = app.getUIUtilities(); UiUtilities ic = app.getUIUtilities();
int iconId = getIconId(category); int iconId = getIconId(category);
if (iconId != 0) { if (iconId == 0) {
if (categorySelected) { iconId = R.drawable.ic_action_categories_search;
iconView.setImageDrawable(ic.getIcon(iconId, R.color.osmand_orange)); }
} else { if (categorySelected) {
iconView.setImageDrawable(ic.getThemedIcon(iconId)); iconView.setImageDrawable(ic.getIcon(iconId, R.color.osmand_orange));
} } else {
} else { iconView.setImageDrawable(ic.getThemedIcon(iconId));
iconView.setImageDrawable(null);
} }
secondaryIconView.setImageDrawable(
ic.getIcon(R.drawable.ic_action_additional_option, nightMode
? R.color.icon_color_default_dark : R.color.icon_color_default_light));
check.setOnCheckedChangeListener(null); check.setOnCheckedChangeListener(null);
check.setChecked(filter.isTypeAccepted(category)); check.setChecked(filter.isTypeAccepted(category));
String textString = category.getTranslation(); String textString = category.getTranslation();
@ -332,8 +327,8 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
} else { } else {
descView.setVisibility(View.GONE); descView.setVisibility(View.GONE);
} }
row.findViewById(R.id.divider) row.findViewById(R.id.divider).setVisibility(View.GONE);
.setVisibility(position == getCount() - 1 ? View.GONE : View.VISIBLE); row.findViewById(R.id.divider_vertical).setVisibility(View.VISIBLE);
addRowListener(category, check); addRowListener(category, check);
} }
return (row); return (row);
@ -411,7 +406,6 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
subCategoriesAdapter.notifyDataSetChanged(); subCategoriesAdapter.notifyDataSetChanged();
removeAllHeaders(); removeAllHeaders();
listView.addHeaderView(headerShadow, null, false); listView.addHeaderView(headerShadow, null, false);
setupAddButton();
} }
} else { } else {
for (PoiCategory category : poiCategoryList) { for (PoiCategory category : poiCategoryList) {
@ -427,8 +421,8 @@ public class QuickSearchCustomPoiFragment extends DialogFragment {
subCategoriesAdapter.notifyDataSetChanged(); subCategoriesAdapter.notifyDataSetChanged();
removeAllHeaders(); removeAllHeaders();
listView.addHeaderView(headerShadow, null, false); listView.addHeaderView(headerShadow, null, false);
setupAddButton();
} }
setupAddButton();
} }
private void removeAllHeaders() { private void removeAllHeaders() {

View file

@ -32,6 +32,7 @@ public class SubCategoriesAdapter extends ArrayAdapter<PoiType> {
private boolean showCategory; private boolean showCategory;
private int activeColorRes; private int activeColorRes;
private int secondaryColorRes; private int secondaryColorRes;
private int activeIconColorRes;
private List<PoiType> selectedItems; private List<PoiType> selectedItems;
private List<PoiType> items; private List<PoiType> items;
@ -47,6 +48,9 @@ public class SubCategoriesAdapter extends ArrayAdapter<PoiType> {
selectedItems = new ArrayList<>(); selectedItems = new ArrayList<>();
uiUtilities = app.getUIUtilities(); uiUtilities = app.getUIUtilities();
nightMode = !app.getSettings().isLightContent(); nightMode = !app.getSettings().isLightContent();
activeIconColorRes = nightMode
? R.color.icon_color_osmand_dark
: R.color.icon_color_osmand_light;
activeColorRes = nightMode activeColorRes = nightMode
? R.color.icon_color_active_dark ? R.color.icon_color_active_dark
: R.color.icon_color_active_light; : R.color.icon_color_active_light;
@ -65,6 +69,7 @@ public class SubCategoriesAdapter extends ArrayAdapter<PoiType> {
final PoiType poiType = getItem(position); final PoiType poiType = getItem(position);
final boolean selected = selectedItems.contains(poiType); final boolean selected = selectedItems.contains(poiType);
int tintColorRes = selected ? activeColorRes : secondaryColorRes; int tintColorRes = selected ? activeColorRes : secondaryColorRes;
int tintIconColorRes = selected ? activeIconColorRes : secondaryColorRes;
if (poiType != null) { if (poiType != null) {
TextView title = convertView.findViewById(R.id.title_tv); TextView title = convertView.findViewById(R.id.title_tv);
title.setText(poiType.getTranslation()); title.setText(poiType.getTranslation());
@ -101,7 +106,7 @@ public class SubCategoriesAdapter extends ArrayAdapter<PoiType> {
iconRes = R.drawable.ic_action_categories_search; iconRes = R.drawable.ic_action_categories_search;
} }
} }
icon.setImageDrawable(uiUtilities.getIcon(iconRes, tintColorRes)); icon.setImageDrawable(uiUtilities.getIcon(iconRes, tintIconColorRes));
} }
return convertView; return convertView;
} }