Simplify HomeItem diff checking with ids
This commit is contained in:
parent
26fc2b23d7
commit
e9aca103d8
3 changed files with 21 additions and 7 deletions
|
@ -51,8 +51,7 @@ class ViewListAdapter(
|
|||
|
||||
companion object DiffCallback : DiffUtil.ItemCallback<HomeItem>() {
|
||||
override fun areItemsTheSame(oldItem: HomeItem, newItem: HomeItem): Boolean {
|
||||
return oldItem.ids.size == newItem.ids.size
|
||||
&& oldItem.ids.mapIndexed { i, old -> old == newItem.ids[i] }.all { it }
|
||||
return oldItem.id == newItem.id
|
||||
}
|
||||
|
||||
override fun areContentsTheSame(oldItem: HomeItem, newItem: HomeItem): Boolean {
|
||||
|
@ -107,12 +106,12 @@ class ViewListAdapter(
|
|||
|
||||
sealed class HomeItem {
|
||||
data class Section(val homeSection: HomeSection) : HomeItem() {
|
||||
override val ids = homeSection.items.map { it.id }
|
||||
override val id = homeSection.id
|
||||
}
|
||||
|
||||
data class ViewItem(val view: View) : HomeItem() {
|
||||
override val ids = view.items?.map { it.id }.orEmpty()
|
||||
override val id = view.id
|
||||
}
|
||||
|
||||
abstract val ids: List<UUID>
|
||||
abstract val id: UUID
|
||||
}
|
|
@ -1,8 +1,10 @@
|
|||
package dev.jdtech.jellyfin.models
|
||||
|
||||
import org.jellyfin.sdk.model.api.BaseItemDto
|
||||
import java.util.*
|
||||
|
||||
data class HomeSection(
|
||||
val id: UUID,
|
||||
val name: String,
|
||||
var items: List<BaseItemDto>
|
||||
)
|
|
@ -19,6 +19,7 @@ import kotlinx.coroutines.flow.MutableStateFlow
|
|||
import kotlinx.coroutines.flow.collect
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
|
@ -68,11 +69,23 @@ class HomeViewModel @Inject internal constructor(
|
|||
|
||||
val items = mutableListOf<HomeSection>()
|
||||
if (resumeItems.isNotEmpty()) {
|
||||
items.add(HomeSection(application.resources.getString(R.string.continue_watching), resumeItems))
|
||||
items.add(
|
||||
HomeSection(
|
||||
UUID.fromString("44845958-8326-4e83-beb4-c4f42e9eeb95"),
|
||||
application.resources.getString(R.string.continue_watching),
|
||||
resumeItems
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
if (nextUpItems.isNotEmpty()) {
|
||||
items.add(HomeSection(application.resources.getString(R.string.next_up), nextUpItems))
|
||||
items.add(
|
||||
HomeSection(
|
||||
UUID.fromString("18bfced5-f237-4d42-aa72-d9d7fed19279"),
|
||||
application.resources.getString(R.string.next_up),
|
||||
nextUpItems
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
items.map { Section(it) }
|
||||
|
|
Loading…
Reference in a new issue