fix clear database setting (again)

This commit is contained in:
jmir1 2022-06-15 09:59:58 +02:00
parent af6e51926a
commit 25df12ff94
4 changed files with 24 additions and 70 deletions

View file

@ -4,42 +4,18 @@ import androidx.recyclerview.widget.RecyclerView
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.animesource.AnimeSource
import eu.kanade.tachiyomi.animesource.AnimeSourceManager
import eu.kanade.tachiyomi.animesource.LocalAnimeSource
import eu.kanade.tachiyomi.animesource.icon
import eu.kanade.tachiyomi.databinding.ClearDatabaseSourceItemBinding
data class ClearDatabaseAnimeSourceItem(val source: AnimeSource, private val mangaCount: Long) : AbstractFlexibleItem<ClearDatabaseAnimeSourceItem.Holder>() {
data class ClearDatabaseAnimeSourceItem(val source: AnimeSource, private val mangaCount: Long) : AbstractFlexibleItem<ClearDatabaseItemHolder>() {
override fun getLayoutRes(): Int {
return R.layout.clear_database_source_item
}
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder {
return Holder(view, adapter)
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): ClearDatabaseItemHolder {
return ClearDatabaseItemHolder(view, adapter)
}
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, holder: Holder?, position: Int, payloads: MutableList<Any>?) {
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, holder: ClearDatabaseItemHolder?, position: Int, payloads: MutableList<Any>?) {
holder?.bind(source, mangaCount)
}
class Holder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter) {
private val binding = ClearDatabaseSourceItemBinding.bind(view)
fun bind(source: AnimeSource, count: Long) {
binding.title.text = source.toString()
binding.description.text = itemView.context.resources
.getQuantityString(R.plurals.clear_database_source_item_count, count.toInt())
itemView.post {
when {
source.id == LocalAnimeSource.ID -> binding.thumbnail.setImageResource(R.mipmap.ic_local_source)
source is AnimeSourceManager.StubSource -> binding.thumbnail.setImageDrawable(null)
source.icon() != null -> binding.thumbnail.setImageDrawable(source.icon())
}
}
binding.checkbox.isChecked = (bindingAdapter as FlexibleAdapter<*>).isSelected(bindingAdapterPosition)
}
}
}

View file

@ -17,9 +17,10 @@ import eu.kanade.tachiyomi.source.icon
class ClearDatabaseItemHolder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter) {
private val binding = ClearDatabaseSourceItemBinding.bind(view)
fun bind(source: Source, count: Int) {
fun bind(source: Source, count: Long) {
binding.title.text = source.toString()
binding.description.text = itemView.context.resources.getQuantityString(R.plurals.clear_database_source_item_count, count, count)
binding.description.text = itemView.context.resources
.getQuantityString(R.plurals.clear_database_source_item_count, count.toInt(), count.toInt())
itemView.post {
when {
@ -28,13 +29,13 @@ class ClearDatabaseItemHolder(view: View, adapter: FlexibleAdapter<*>) : Flexibl
source.icon() != null -> binding.thumbnail.setImageDrawable(source.icon())
}
}
binding.checkbox.isChecked = (bindingAdapter as FlexibleAdapter<*>).isSelected(bindingAdapterPosition)
}
fun bind(source: AnimeSource, count: Int) {
fun bind(source: AnimeSource, count: Long) {
binding.title.text = source.toString()
binding.description.text = itemView.context.resources.getQuantityString(R.plurals.clear_database_source_item_count, count, count)
binding.description.text = itemView.context.resources
.getQuantityString(R.plurals.clear_database_source_item_count, count.toInt(), count.toInt())
itemView.post {
when {
@ -43,7 +44,6 @@ class ClearDatabaseItemHolder(view: View, adapter: FlexibleAdapter<*>) : Flexibl
source.icon() != null -> binding.thumbnail.setImageDrawable(source.icon())
}
}
binding.checkbox.isChecked = (bindingAdapter as FlexibleAdapter<*>).isSelected(bindingAdapterPosition)
}
}

View file

@ -23,20 +23,22 @@ class ClearDatabasePresenter(
super.onCreate(savedState)
presenterScope.launchIO {
getSourcesWithNonLibraryManga.subscribe()
.collectLatest { list ->
val items = list
.map { (source, count) -> ClearDatabaseSourceItem(source, count) }
.sortedBy { it.source.name }
withUIContext { view?.setItems(items) }
}
getAnimeSourcesWithNonLibraryAnime.subscribe()
.collectLatest { list ->
val items = list
.map { (source, count) -> ClearDatabaseAnimeSourceItem(source, count) }
.sortedBy { it.source.name }
withUIContext { view?.setItemsAnime(items) }
}
}
presenterScope.launchIO {
getSourcesWithNonLibraryManga.subscribe()
.collectLatest { list ->
val items = list
.map { (source, count) -> ClearDatabaseSourceItem(source, count) }
.sortedBy { it.source.name }
withUIContext { view?.setItems(items) }
}
}

View file

@ -4,42 +4,18 @@ import androidx.recyclerview.widget.RecyclerView
import eu.davidea.flexibleadapter.FlexibleAdapter
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
import eu.davidea.flexibleadapter.items.IFlexible
import eu.davidea.viewholders.FlexibleViewHolder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.ClearDatabaseSourceItemBinding
import eu.kanade.tachiyomi.source.LocalSource
import eu.kanade.tachiyomi.source.Source
import eu.kanade.tachiyomi.source.SourceManager
import eu.kanade.tachiyomi.source.icon
data class ClearDatabaseSourceItem(val source: Source, private val mangaCount: Long) : AbstractFlexibleItem<ClearDatabaseSourceItem.Holder>() {
data class ClearDatabaseSourceItem(val source: Source, private val mangaCount: Long) : AbstractFlexibleItem<ClearDatabaseItemHolder>() {
override fun getLayoutRes(): Int {
return R.layout.clear_database_source_item
}
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): Holder {
return Holder(view, adapter)
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): ClearDatabaseItemHolder {
return ClearDatabaseItemHolder(view, adapter)
}
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, holder: Holder?, position: Int, payloads: MutableList<Any>?) {
override fun bindViewHolder(adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>?, holder: ClearDatabaseItemHolder?, position: Int, payloads: MutableList<Any>?) {
holder?.bind(source, mangaCount)
}
class Holder(view: View, adapter: FlexibleAdapter<*>) : FlexibleViewHolder(view, adapter) {
private val binding = ClearDatabaseSourceItemBinding.bind(view)
fun bind(source: Source, count: Long) {
binding.title.text = source.toString()
binding.description.text = itemView.context.resources
.getQuantityString(R.plurals.clear_database_source_item_count, count.toInt())
itemView.post {
when {
source.id == LocalSource.ID -> binding.thumbnail.setImageResource(R.mipmap.ic_local_source)
source is SourceManager.StubSource -> binding.thumbnail.setImageDrawable(null)
source.icon() != null -> binding.thumbnail.setImageDrawable(source.icon())
}
}
binding.checkbox.isChecked = (bindingAdapter as FlexibleAdapter<*>).isSelected(bindingAdapterPosition)
}
}
}