Skip to content

Commit

Permalink
Discover filter: use check boxes instead of switches.
Browse files Browse the repository at this point in the history
Also unify layout with manage list dialog.
  • Loading branch information
UweTrottmann committed Feb 16, 2024
1 parent d758c1f commit caaa79a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ class ManageListsDialogFragment : AppCompatDialogFragment() {
}

private val onItemClickListener = object : ListsWithItemAdapter.ItemClickListener {
override fun onItemClick(v: View, listId: String, isChecked: Boolean) {
model.setIsItemOnList(listId, !isChecked)
override fun onItemClick(v: View, listItem: ListWithItem) {
model.setIsItemOnList(listItem.listId, !listItem.isItemOnList)
}
}

Expand All @@ -129,7 +129,7 @@ class ManageListsDialogFragment : AppCompatDialogFragment() {
) {

interface ItemClickListener {
fun onItemClick(v: View, listId: String, isChecked: Boolean)
fun onItemClick(v: View, listItem: ListWithItem)
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ListWithItemViewHolder =
Expand All @@ -145,21 +145,17 @@ class ManageListsDialogFragment : AppCompatDialogFragment() {
private var listWithItem: ListWithItem? = null

init {
binding.checkedTextViewList.setOnClickListener { view ->
binding.root.setOnClickListener { view ->
listWithItem?.also {
itemClickListener.onItemClick(
view,
it.listId,
binding.checkedTextViewList.isChecked
)
itemClickListener.onItemClick(view, it)
}
}
}

fun bindTo(listWithItem: ListWithItem?) {
this.listWithItem = listWithItem
binding.checkedTextViewList.text = listWithItem?.listName ?: ""
binding.checkedTextViewList.isChecked = listWithItem?.isItemOnList ?: false
binding.textViewListItem.text = listWithItem?.listName ?: ""
binding.checkBoxListItem.isChecked = listWithItem?.isItemOnList ?: false
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import android.view.ViewGroup
import androidx.paging.PagingDataAdapter
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import com.battlelancer.seriesguide.databinding.ItemWatchProviderBinding
import com.battlelancer.seriesguide.databinding.ItemListCheckedBinding
import com.battlelancer.seriesguide.streaming.SgWatchProvider

class ShowsDiscoverFilterAdapter(
Expand All @@ -22,7 +22,7 @@ class ShowsDiscoverFilterAdapter(

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): SgWatchProviderViewHolder {
return SgWatchProviderViewHolder(
ItemWatchProviderBinding.inflate(
ItemListCheckedBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
Expand All @@ -45,14 +45,14 @@ object SgWatchProviderDiffCallback : DiffUtil.ItemCallback<SgWatchProvider>() {
}

class SgWatchProviderViewHolder(
private val binding: ItemWatchProviderBinding,
private val binding: ItemListCheckedBinding,
clickListener: ShowsDiscoverFilterAdapter.ClickListener
) : RecyclerView.ViewHolder(binding.root) {

private var watchProvider: SgWatchProvider? = null

init {
binding.switchWatchProvider.setOnClickListener {
binding.root.setOnClickListener {
watchProvider?.let {
clickListener.onClick(it)
}
Expand All @@ -62,14 +62,14 @@ class SgWatchProviderViewHolder(
fun bindTo(watchProvider: SgWatchProvider?) {
this.watchProvider = watchProvider
if (watchProvider == null) {
binding.switchWatchProvider.apply {
text = null
binding.textViewListItem.text = null
binding.checkBoxListItem.apply {
isChecked = false
isEnabled = false
}
} else {
binding.switchWatchProvider.apply {
text = watchProvider.provider_name
binding.textViewListItem.text = watchProvider.provider_name
binding.checkBoxListItem.apply {
isChecked = watchProvider.enabled
isEnabled = true
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_shows_discover_filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
tools:listitem="@layout/item_watch_provider" />
tools:listitem="@layout/item_list_checked" />

<Button
android:id="@+id/buttonDisableAllProviders"
Expand Down
46 changes: 31 additions & 15 deletions app/src/main/res/layout/item_list_checked.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- UnusedAttribute: foreground only available on API 23+, that's fine. -->
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"

<!-- Not using CheckedTextView, it does not use Material theming -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/checkedTextViewList"
style="@style/Widget.SeriesGuide.TextView.SingleLine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:checkMark="?android:attr/listChoiceIndicatorMultiple"
android:ellipsize="end"
android:foreground="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:background="?attr/selectableItemBackground"
android:minHeight="48dp"
android:paddingLeft="@dimen/larger_padding"
android:paddingTop="@dimen/default_padding"
android:paddingRight="@dimen/larger_padding"
android:paddingBottom="@dimen/default_padding"
android:textAppearance="@style/TextAppearance.SeriesGuide.Subtitle1"
tools:text="Example List"
tools:ignore="UnusedAttribute" />
android:orientation="horizontal">

<TextView
android:id="@+id/textViewListItem"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:paddingStart="24dp"
android:paddingTop="16dp"
android:paddingEnd="16dp"
android:paddingBottom="16dp"
android:textAppearance="@style/TextAppearance.SeriesGuide.Body1"
tools:text="Streaming service" />

<!-- Prevent changing state from box, only via parent. Remove ripple effect. -->
<CheckBox
android:id="@+id/checkBoxListItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:paddingEnd="24dp" />

</LinearLayout>
12 changes: 0 additions & 12 deletions app/src/main/res/layout/item_watch_provider.xml

This file was deleted.

0 comments on commit caaa79a

Please sign in to comment.