refactor: remove databinding from favorite_section, next_up_section and view_item
This commit is contained in:
parent
6ffc761972
commit
f8e6453ec3
6 changed files with 88 additions and 140 deletions
|
@ -4,10 +4,7 @@ import android.view.View
|
||||||
import android.widget.ImageView
|
import android.widget.ImageView
|
||||||
import androidx.annotation.DrawableRes
|
import androidx.annotation.DrawableRes
|
||||||
import androidx.databinding.BindingAdapter
|
import androidx.databinding.BindingAdapter
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
|
||||||
import coil.load
|
import coil.load
|
||||||
import dev.jdtech.jellyfin.adapters.HomeEpisodeListAdapter
|
|
||||||
import dev.jdtech.jellyfin.adapters.ViewItemListAdapter
|
|
||||||
import dev.jdtech.jellyfin.api.JellyfinApi
|
import dev.jdtech.jellyfin.api.JellyfinApi
|
||||||
import dev.jdtech.jellyfin.models.FindroidEpisode
|
import dev.jdtech.jellyfin.models.FindroidEpisode
|
||||||
import dev.jdtech.jellyfin.models.FindroidItem
|
import dev.jdtech.jellyfin.models.FindroidItem
|
||||||
|
@ -20,12 +17,6 @@ import org.jellyfin.sdk.model.api.ImageType
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
import dev.jdtech.jellyfin.core.R as CoreR
|
import dev.jdtech.jellyfin.core.R as CoreR
|
||||||
|
|
||||||
@BindingAdapter("items")
|
|
||||||
fun bindItems(recyclerView: RecyclerView, data: List<FindroidItem>?) {
|
|
||||||
val adapter = recyclerView.adapter as ViewItemListAdapter
|
|
||||||
adapter.submitList(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
@BindingAdapter("itemImage")
|
@BindingAdapter("itemImage")
|
||||||
fun bindItemImage(imageView: ImageView, item: BaseItemDto) {
|
fun bindItemImage(imageView: ImageView, item: BaseItemDto) {
|
||||||
val itemId =
|
val itemId =
|
||||||
|
@ -69,12 +60,6 @@ fun bindPersonImage(imageView: ImageView, person: BaseItemPerson) {
|
||||||
.posterDescription(person.name)
|
.posterDescription(person.name)
|
||||||
}
|
}
|
||||||
|
|
||||||
@BindingAdapter("homeEpisodes")
|
|
||||||
fun bindHomeEpisodes(recyclerView: RecyclerView, data: List<FindroidItem>?) {
|
|
||||||
val adapter = recyclerView.adapter as HomeEpisodeListAdapter
|
|
||||||
adapter.submitList(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
@BindingAdapter("cardItemImage")
|
@BindingAdapter("cardItemImage")
|
||||||
fun bindCardItemImage(imageView: ImageView, item: FindroidItem) {
|
fun bindCardItemImage(imageView: ImageView, item: FindroidItem) {
|
||||||
val imageType = when (item) {
|
val imageType = when (item) {
|
||||||
|
|
|
@ -20,7 +20,6 @@ class FavoritesListAdapter(
|
||||||
onClickListener: ViewItemListAdapter.OnClickListener,
|
onClickListener: ViewItemListAdapter.OnClickListener,
|
||||||
onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener,
|
onEpisodeClickListener: HomeEpisodeListAdapter.OnClickListener,
|
||||||
) {
|
) {
|
||||||
binding.section = section
|
|
||||||
if (section.id == Constants.FAVORITE_TYPE_MOVIES || section.id == Constants.FAVORITE_TYPE_SHOWS) {
|
if (section.id == Constants.FAVORITE_TYPE_MOVIES || section.id == Constants.FAVORITE_TYPE_SHOWS) {
|
||||||
binding.itemsRecyclerView.adapter =
|
binding.itemsRecyclerView.adapter =
|
||||||
ViewItemListAdapter(onClickListener, fixedWidth = true)
|
ViewItemListAdapter(onClickListener, fixedWidth = true)
|
||||||
|
@ -31,7 +30,6 @@ class FavoritesListAdapter(
|
||||||
(binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.items)
|
(binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.items)
|
||||||
}
|
}
|
||||||
binding.sectionName.text = section.name.asString(binding.root.resources)
|
binding.sectionName.text = section.name.asString(binding.root.resources)
|
||||||
binding.executePendingBindings()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,24 +31,22 @@ class ViewListAdapter(
|
||||||
onItemClickListener: ViewItemListAdapter.OnClickListener,
|
onItemClickListener: ViewItemListAdapter.OnClickListener,
|
||||||
) {
|
) {
|
||||||
val view = dataItem.view
|
val view = dataItem.view
|
||||||
binding.view = view
|
|
||||||
binding.viewName.text = binding.viewName.context.resources.getString(CoreR.string.latest_library, view.name)
|
binding.viewName.text = binding.viewName.context.resources.getString(CoreR.string.latest_library, view.name)
|
||||||
binding.itemsRecyclerView.adapter =
|
binding.itemsRecyclerView.adapter =
|
||||||
ViewItemListAdapter(onItemClickListener, fixedWidth = true)
|
ViewItemListAdapter(onItemClickListener, fixedWidth = true)
|
||||||
|
(binding.itemsRecyclerView.adapter as ViewItemListAdapter).submitList(view.items)
|
||||||
binding.viewAll.setOnClickListener {
|
binding.viewAll.setOnClickListener {
|
||||||
onClickListener.onClick(view)
|
onClickListener.onClick(view)
|
||||||
}
|
}
|
||||||
binding.executePendingBindings()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class NextUpViewHolder(private var binding: NextUpSectionBinding) :
|
class NextUpViewHolder(private var binding: NextUpSectionBinding) :
|
||||||
RecyclerView.ViewHolder(binding.root) {
|
RecyclerView.ViewHolder(binding.root) {
|
||||||
fun bind(section: HomeItem.Section, onClickListener: HomeEpisodeListAdapter.OnClickListener) {
|
fun bind(section: HomeItem.Section, onClickListener: HomeEpisodeListAdapter.OnClickListener) {
|
||||||
binding.section = section.homeSection
|
|
||||||
binding.sectionName.text = section.homeSection.name.asString(binding.sectionName.context.resources)
|
binding.sectionName.text = section.homeSection.name.asString(binding.sectionName.context.resources)
|
||||||
binding.itemsRecyclerView.adapter = HomeEpisodeListAdapter(onClickListener)
|
binding.itemsRecyclerView.adapter = HomeEpisodeListAdapter(onClickListener)
|
||||||
binding.executePendingBindings()
|
(binding.itemsRecyclerView.adapter as HomeEpisodeListAdapter).submitList(section.homeSection.items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,39 +1,29 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<data>
|
<TextView
|
||||||
|
android:id="@+id/section_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||||
|
android:textSize="18sp"
|
||||||
|
tools:text="Movies" />
|
||||||
|
|
||||||
<variable
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
name="section"
|
android:id="@+id/items_recycler_view"
|
||||||
type="dev.jdtech.jellyfin.models.FavoriteSection" />
|
|
||||||
</data>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:clipToPadding="false"
|
||||||
android:layout_marginBottom="12dp">
|
android:orientation="horizontal"
|
||||||
|
android:paddingHorizontal="12dp"
|
||||||
<TextView
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
android:id="@+id/section_name"
|
tools:listitem="@layout/home_episode_item" />
|
||||||
android:layout_width="wrap_content"
|
</LinearLayout>
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginBottom="12dp"
|
|
||||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
|
||||||
android:textSize="18sp"
|
|
||||||
tools:text="Movies" />
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/items_recycler_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingHorizontal="12dp"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
|
||||||
tools:listitem="@layout/home_episode_item" />
|
|
||||||
</LinearLayout>
|
|
||||||
</layout>
|
|
|
@ -1,40 +1,29 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<data>
|
<TextView
|
||||||
|
android:id="@+id/section_name"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="24dp"
|
||||||
|
android:layout_marginBottom="12dp"
|
||||||
|
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||||
|
android:textSize="18sp"
|
||||||
|
tools:text="Next Up" />
|
||||||
|
|
||||||
<variable
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
name="section"
|
android:id="@+id/items_recycler_view"
|
||||||
type="dev.jdtech.jellyfin.models.HomeSection" />
|
|
||||||
</data>
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="vertical"
|
android:clipToPadding="false"
|
||||||
android:layout_marginBottom="12dp">
|
android:orientation="horizontal"
|
||||||
|
android:paddingHorizontal="12dp"
|
||||||
<TextView
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
android:id="@+id/section_name"
|
tools:listitem="@layout/home_episode_item" />
|
||||||
android:layout_width="wrap_content"
|
</LinearLayout>
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="24dp"
|
|
||||||
android:layout_marginBottom="12dp"
|
|
||||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
|
||||||
android:textSize="18sp"
|
|
||||||
tools:text="Next Up" />
|
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
|
||||||
android:id="@+id/items_recycler_view"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingHorizontal="12dp"
|
|
||||||
app:homeEpisodes="@{section.items}"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
|
||||||
tools:listitem="@layout/home_episode_item" />
|
|
||||||
</LinearLayout>
|
|
||||||
</layout>
|
|
|
@ -1,58 +1,46 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="12dp">
|
||||||
|
|
||||||
<data>
|
<TextView
|
||||||
|
android:id="@+id/view_name"
|
||||||
<variable
|
android:layout_width="0dp"
|
||||||
name="view"
|
|
||||||
type="dev.jdtech.jellyfin.models.View" />
|
|
||||||
</data>
|
|
||||||
|
|
||||||
<androidx.constraintlayout.widget.ConstraintLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginBottom="12dp">
|
android:layout_marginStart="24dp"
|
||||||
|
android:ellipsize="end"
|
||||||
|
android:maxLines="1"
|
||||||
|
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
||||||
|
android:textSize="18sp"
|
||||||
|
app:layout_constraintBaseline_toBaselineOf="@id/view_all"
|
||||||
|
app:layout_constraintEnd_toStartOf="@id/view_all"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
tools:text="Movies" />
|
||||||
|
|
||||||
<TextView
|
<Button
|
||||||
android:id="@+id/view_name"
|
android:id="@+id/view_all"
|
||||||
android:layout_width="0dp"
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
android:layout_height="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_marginStart="24dp"
|
android:layout_height="wrap_content"
|
||||||
android:ellipsize="end"
|
android:layout_marginEnd="24dp"
|
||||||
android:maxLines="1"
|
android:text="@string/view_all"
|
||||||
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
android:textSize="18sp"
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
app:layout_constraintBaseline_toBaselineOf="@id/view_all"
|
|
||||||
app:layout_constraintEnd_toStartOf="@id/view_all"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
tools:text="Movies" />
|
|
||||||
|
|
||||||
<Button
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/view_all"
|
android:id="@+id/items_recycler_view"
|
||||||
style="@style/Widget.Material3.Button.TextButton"
|
android:layout_width="0dp"
|
||||||
android:layout_width="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_marginTop="16dp"
|
||||||
android:layout_marginEnd="24dp"
|
android:clipToPadding="false"
|
||||||
android:text="@string/view_all"
|
android:orientation="horizontal"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
android:paddingHorizontal="12dp"
|
||||||
app:layout_constraintTop_toTopOf="parent" />
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
||||||
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
android:id="@+id/items_recycler_view"
|
app:layout_constraintTop_toBottomOf="@id/view_name"
|
||||||
android:layout_width="0dp"
|
tools:listitem="@layout/base_item" />
|
||||||
android:layout_height="wrap_content"
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
android:layout_marginTop="16dp"
|
|
||||||
android:clipToPadding="false"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:paddingHorizontal="12dp"
|
|
||||||
app:items="@{view.items}"
|
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
|
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/view_name"
|
|
||||||
tools:listitem="@layout/base_item" />
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
|
||||||
|
|
||||||
</layout>
|
|
Loading…
Reference in a new issue