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"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:gravity="center_vertical"
android:minHeight="60dp"
android:orientation="horizontal"
tools:layout_height="60dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
tools:src="@drawable/ic_action_gabout_dark"/>
android:layout_marginLeft="16dp"
tools:src="@drawable/ic_action_gabout_dark" />
<LinearLayout
android:id="@+id/text_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center_vertical"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_toEndOf="@+id/icon"
android:layout_toLeftOf="@+id/secondary_icon"
android:layout_toRightOf="@+id/icon"
android:layout_toStartOf="@+id/secondary_icon"
android:minHeight="60dp"
android:layout_marginLeft="16dp"
android:gravity="center_vertical"
android:orientation="vertical">
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/title"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some title text"/>
android:orientation="horizontal">
<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
android:id="@+id/text_wrapper"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:gravity="center_vertical"
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
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"/>
android:id="@+id/divider"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
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>
</LinearLayout>

View file

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

View file

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