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(
|
class MultiSearchListModel(
|
||||||
val source: MangaSource,
|
val source: MangaSource,
|
||||||
|
val hasMore: Boolean,
|
||||||
val list: List<MangaItemModel>,
|
val list: List<MangaItemModel>,
|
||||||
) : ListModel {
|
) : ListModel {
|
||||||
|
|
||||||
@@ -16,6 +17,7 @@ class MultiSearchListModel(
|
|||||||
other as MultiSearchListModel
|
other as MultiSearchListModel
|
||||||
|
|
||||||
if (source != other.source) return false
|
if (source != other.source) return false
|
||||||
|
if (hasMore != other.hasMore) return false
|
||||||
if (list != other.list) return false
|
if (list != other.list) return false
|
||||||
|
|
||||||
return true
|
return true
|
||||||
@@ -23,6 +25,7 @@ class MultiSearchListModel(
|
|||||||
|
|
||||||
override fun hashCode(): Int {
|
override fun hashCode(): Int {
|
||||||
var result = source.hashCode()
|
var result = source.hashCode()
|
||||||
|
result = 31 * result + hasMore.hashCode()
|
||||||
result = 31 * result + list.hashCode()
|
result = 31 * result + list.hashCode()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import org.koitharu.kotatsu.utils.ext.asLiveDataDistinct
|
|||||||
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
import org.koitharu.kotatsu.utils.ext.printStackTraceDebug
|
||||||
|
|
||||||
private const val MAX_PARALLELISM = 4
|
private const val MAX_PARALLELISM = 4
|
||||||
|
private const val MIN_HAS_MORE_ITEMS = 8
|
||||||
|
|
||||||
class MultiSearchViewModel(
|
class MultiSearchViewModel(
|
||||||
initialQuery: String,
|
initialQuery: String,
|
||||||
@@ -98,7 +99,7 @@ class MultiSearchViewModel(
|
|||||||
val list = MangaRepository(source).getList(offset = 0, query = q)
|
val list = MangaRepository(source).getList(offset = 0, query = q)
|
||||||
.toUi(ListMode.GRID)
|
.toUi(ListMode.GRID)
|
||||||
if (list.isNotEmpty()) {
|
if (list.isNotEmpty()) {
|
||||||
MultiSearchListModel(source, list)
|
MultiSearchListModel(source, list.size > MIN_HAS_MORE_ITEMS, list)
|
||||||
} else {
|
} else {
|
||||||
null
|
null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.koitharu.kotatsu.search.ui.multi.adapter
|
package org.koitharu.kotatsu.search.ui.multi.adapter
|
||||||
|
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.lifecycle.LifecycleOwner
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool
|
import androidx.recyclerview.widget.RecyclerView.RecycledViewPool
|
||||||
import coil.ImageLoader
|
import coil.ImageLoader
|
||||||
@@ -37,11 +38,12 @@ fun searchResultsAD(
|
|||||||
val spacing = context.resources.getDimensionPixelOffset(R.dimen.grid_spacing)
|
val spacing = context.resources.getDimensionPixelOffset(R.dimen.grid_spacing)
|
||||||
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
binding.recyclerView.addItemDecoration(SpacingItemDecoration(spacing))
|
||||||
val eventListener = AdapterDelegateClickListenerAdapter(this, itemClickListener)
|
val eventListener = AdapterDelegateClickListenerAdapter(this, itemClickListener)
|
||||||
itemView.setOnClickListener(eventListener)
|
binding.buttonMore.setOnClickListener(eventListener)
|
||||||
|
|
||||||
bind {
|
bind {
|
||||||
binding.textViewTitle.text = item.source.title
|
binding.textViewTitle.text = item.source.title
|
||||||
adapter.items = item.list
|
binding.buttonMore.isVisible = item.hasMore
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
adapter.items = item.list
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,32 +1,49 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout
|
<RelativeLayout
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
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_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="?selectableItemBackground"
|
android:clipChildren="false"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingVertical="@dimen/grid_spacing_outer">
|
android:paddingBottom="@dimen/grid_spacing_outer">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/textView_title"
|
android:id="@+id/textView_title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignWithParentIfMissing="true"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_alignParentTop="true"
|
||||||
android:layout_marginHorizontal="@dimen/grid_spacing"
|
android:layout_marginHorizontal="@dimen/grid_spacing"
|
||||||
|
android:layout_marginTop="@dimen/grid_spacing_outer"
|
||||||
|
android:layout_toStartOf="@id/button_more"
|
||||||
android:gravity="center_vertical|start"
|
android:gravity="center_vertical|start"
|
||||||
android:padding="@dimen/grid_spacing"
|
android:padding="@dimen/grid_spacing"
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextAppearance.Kotatsu.SectionHeader"
|
android:textAppearance="@style/TextAppearance.Kotatsu.SectionHeader"
|
||||||
tools:text="@tools:sample/lorem[2]" />
|
tools:text="@tools:sample/lorem[2]" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/button_more"
|
||||||
|
style="@style/Widget.Material3.Button.TextButton"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignBaseline="@id/textView_title"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_marginEnd="@dimen/grid_spacing"
|
||||||
|
android:text="@string/show_all" />
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/recyclerView"
|
android:id="@+id/recyclerView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/textView_title"
|
||||||
|
android:layout_alignParentStart="true"
|
||||||
android:clipToPadding="false"
|
android:clipToPadding="false"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:paddingHorizontal="@dimen/grid_spacing"
|
android:paddingHorizontal="@dimen/grid_spacing"
|
||||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||||
|
|
||||||
</LinearLayout>
|
</RelativeLayout>
|
||||||
@@ -319,4 +319,5 @@
|
|||||||
<string name="show_reading_indicators_summary">Show percentage read in history and favourites</string>
|
<string name="show_reading_indicators_summary">Show percentage read in history and favourites</string>
|
||||||
<string name="exclude_nsfw_from_history_summary">Manga marked as NSFW will never added to the history and your progress will not be saved</string>
|
<string name="exclude_nsfw_from_history_summary">Manga marked as NSFW will never added to the history and your progress will not be saved</string>
|
||||||
<string name="clear_cookies_summary">Can help in case of some issues. All authorizations will be invalidated</string>
|
<string name="clear_cookies_summary">Can help in case of some issues. All authorizations will be invalidated</string>
|
||||||
|
<string name="show_all">Show all</string>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user