Add "Show all" button to search results
This commit is contained in:
@@ -6,6 +6,7 @@ import org.koitharu.kotatsu.parsers.model.MangaSource
|
||||
|
||||
class MultiSearchListModel(
|
||||
val source: MangaSource,
|
||||
val hasMore: Boolean,
|
||||
val list: List<MangaItemModel>,
|
||||
) : ListModel {
|
||||
|
||||
@@ -16,6 +17,7 @@ class MultiSearchListModel(
|
||||
other as MultiSearchListModel
|
||||
|
||||
if (source != other.source) return false
|
||||
if (hasMore != other.hasMore) return false
|
||||
if (list != other.list) return false
|
||||
|
||||
return true
|
||||
@@ -23,6 +25,7 @@ class MultiSearchListModel(
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = source.hashCode()
|
||||
result = 31 * result + hasMore.hashCode()
|
||||
result = 31 * result + list.hashCode()
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||
|
||||
private const val MAX_PARALLELISM = 4
|
||||
private const val MIN_HAS_MORE_ITEMS = 8
|
||||
|
||||
class MultiSearchViewModel(
|
||||
initialQuery: String,
|
||||
@@ -98,7 +99,7 @@ class MultiSearchViewModel(
|
||||
val list = MangaRepository(source).getList(offset = 0, query = q)
|
||||
.toUi(ListMode.GRID)
|
||||
if (list.isNotEmpty()) {
|
||||
MultiSearchListModel(source, list)
|
||||
MultiSearchListModel(source, list.size > MIN_HAS_MORE_ITEMS, list)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.koitharu.kotatsu.search.ui.multi.adapter
|
||||
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool
|
||||
import coil.ImageLoader
|
||||
@@ -37,11 +38,12 @@ fun searchResultsAD(
|
||||
val spacing = context.resources.getDimensionPixelOffset(R.dimen.grid_spacing)
|
||||
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
||||
val eventListener = AdapterDelegateClickListenerAdapter(this, itemClickListener)
|
||||
itemView.setOnClickListener(eventListener)
|
||||
binding.buttonMore.setOnClickListener(eventListener)
|
||||
|
||||
bind {
|
||||
binding.textViewTitle.text = item.source.title
|
||||
adapter.items = item.list
|
||||
binding.buttonMore.isVisible = item.hasMore
|
||||
adapter.notifyDataSetChanged()
|
||||
adapter.items = item.list
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user