Skip to content

Commit

Permalink
draft Add watch provider filter view.
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Jan 26, 2024
1 parent 9833566 commit 4e2b1ae
Show file tree
Hide file tree
Showing 3 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.ListAdapter
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.battlelancer.seriesguide.databinding.ItemWatchProviderBinding
import com.battlelancer.seriesguide.streaming.SgWatchProvider

class WatchProviderFilterAdapter :
ListAdapter<SgWatchProvider, WatchProviderViewHolder>(WatchProviderDiffCallback) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WatchProviderViewHolder {
return WatchProviderViewHolder.create(parent)
}

override fun onBindViewHolder(holder: WatchProviderViewHolder, position: Int) {
holder.bind(getItem(position))
}
}

class WatchProviderViewHolder(private val binding: ItemWatchProviderBinding) :
ViewHolder(binding.root) {

fun bind(watchProvider: SgWatchProvider) {
TODO()
}

companion object {
fun create(parent: ViewGroup): WatchProviderViewHolder =
WatchProviderViewHolder(
ItemWatchProviderBinding.inflate(
LayoutInflater.from(parent.context),
parent,
false
)
)
}
}

object WatchProviderDiffCallback : DiffUtil.ItemCallback<SgWatchProvider>() {
override fun areItemsTheSame(oldItem: SgWatchProvider, newItem: SgWatchProvider): Boolean {
TODO("Not yet implemented")
}

override fun areContentsTheSame(oldItem: SgWatchProvider, newItem: SgWatchProvider): Boolean {
TODO("Not yet implemented")
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2024 Uwe Trottmann

package com.battlelancer.seriesguide.shows

import android.content.Context
import android.util.AttributeSet
import android.view.LayoutInflater
import android.widget.LinearLayout
import androidx.recyclerview.widget.LinearLayoutManager
import com.battlelancer.seriesguide.databinding.ViewFilterWatchProvidersBinding
import com.battlelancer.seriesguide.streaming.SgWatchProvider

class WatchProviderFilterView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {

private val binding: ViewFilterWatchProvidersBinding
private val adapter: WatchProviderFilterAdapter

init {
orientation = VERTICAL

// can't do in onFinishInflate as that is only called when inflating from XML
binding = ViewFilterWatchProvidersBinding.inflate(LayoutInflater.from(context), this)

adapter = WatchProviderFilterAdapter()
binding.recyclerViewProviderFilter.also {
it.layoutManager = LinearLayoutManager(context)
it.adapter = adapter
}
}

fun setWatchProviders(watchProviders: List<SgWatchProvider>) {
adapter.submitList(watchProviders)
}

}
16 changes: 16 additions & 0 deletions app/src/main/res/layout/view_filter_watch_providers.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>

<!-- SPDX-License-Identifier: Apache-2.0 -->
<!-- Copyright 2024 Uwe Trottmann -->

<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:orientation="vertical"
tools:parentTag="android.widget.LinearLayout">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerViewProviderFilter"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</merge>

0 comments on commit 4e2b1ae

Please sign in to comment.