Skip to content

Change item background according to the theme #3480

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public RecyclerViewHolder(View view) {
@NonNull
@Override
public RecyclerViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View itemView = inflater.inflate(callback.isDarkTheme()?R.layout.nearby_search_list_item_dark:R.layout.nearby_search_list_item, parent, false);
View itemView = inflater.inflate(callback.isDarkTheme() ? R.layout.nearby_search_list_item_dark : R.layout.nearby_search_list_item, parent, false);
return new RecyclerViewHolder(itemView);
}

Expand All @@ -79,17 +79,20 @@ public void onBindViewHolder(@NonNull RecyclerViewHolder holder, int position) {
Label label = displayedLabels.get(position);
holder.placeTypeIcon.setImageResource(label.getIcon());
holder.placeTypeLabel.setText(label.toString());
holder.placeTypeLayout.setSelected(label.isSelected());

holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : callback.isDarkTheme()?Color.BLACK:Color.WHITE);
holder.placeTypeLayout.setOnClickListener(view -> {
callback.setCheckboxUnknown();

if (label.isSelected()) {
selectedLabels.remove(label);
} else {
selectedLabels.add(label);
}

label.setSelected(!label.isSelected());
holder.placeTypeLayout.setBackgroundColor(label.isSelected() ? ContextCompat.getColor(context, R.color.divider_grey) : Color.WHITE);
holder.placeTypeLayout.setSelected(label.isSelected());

callback.filterByMarkerType(selectedLabels, 0, false, false);
});
}
Expand Down Expand Up @@ -165,7 +168,7 @@ public void setRecyclerViewAdapterAllSelected() {
notifyDataSetChanged();
}

public interface Callback{
public interface Callback {

void setCheckboxUnknown();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@color/opak_middle_grey" />
<item android:drawable="@color/black" />
</selector>
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/linearlayout_color_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true"
android:drawable="@color/divider_grey" />
<item android:drawable="@color/white" />
</selector>
8 changes: 5 additions & 3 deletions app/src/main/res/layout/nearby_search_list_item.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/search_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="@dimen/tiny_margin">
android:padding="@dimen/tiny_margin"
android:background="@drawable/linearlayout_color_selector">

<ImageView
android:id="@+id/place_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/place_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"></TextView>
android:layout_height="wrap_content"/>
</LinearLayout>
7 changes: 4 additions & 3 deletions app/src/main/res/layout/nearby_search_list_item_dark.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/tiny_margin"
android:orientation="horizontal">
android:orientation="horizontal"
android:background="@drawable/linearlayout_color_dark_selector">

<ImageView
android:id="@+id/place_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"/>

<TextView
android:id="@+id/place_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/white"></TextView>
android:textColor="@color/white"/>
</LinearLayout>