Saved searches internal improvements, lag is now fixed
This commit is contained in:
parent
9e52f4e8cc
commit
7ce36f25ce
@ -0,0 +1,32 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import com.google.android.material.chip.Chip
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
|
import eu.kanade.tachiyomi.databinding.SourceFilterSheetSavedSearchesBinding
|
||||||
|
import eu.kanade.tachiyomi.ui.base.holder.BaseFlexibleViewHolder
|
||||||
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
|
import eu.kanade.tachiyomi.util.view.visible
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
|
class SavedSearchesHolder(
|
||||||
|
view: View,
|
||||||
|
adapter: FlexibleAdapter<SavedSearchesItem>
|
||||||
|
) : BaseFlexibleViewHolder(view, adapter) {
|
||||||
|
|
||||||
|
var binding: SourceFilterSheetSavedSearchesBinding = SourceFilterSheetSavedSearchesBinding.bind(itemView)
|
||||||
|
|
||||||
|
fun setChips(chips: List<Chip> = emptyList()) {
|
||||||
|
Timber.d("Chips set")
|
||||||
|
binding.savedSearches.removeAllViews()
|
||||||
|
if (chips.isEmpty()) {
|
||||||
|
binding.savedSearchesTitle.gone()
|
||||||
|
} else {
|
||||||
|
binding.savedSearchesTitle.visible()
|
||||||
|
}
|
||||||
|
chips.forEach {
|
||||||
|
Timber.d(it.text.toString())
|
||||||
|
binding.savedSearches.addView(it)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
package eu.kanade.tachiyomi.ui.browse.source.browse
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
|
import eu.davidea.flexibleadapter.items.AbstractFlexibleItem
|
||||||
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
|
import eu.kanade.tachiyomi.R
|
||||||
|
|
||||||
|
class SavedSearchesItem :
|
||||||
|
AbstractFlexibleItem<SavedSearchesHolder>() {
|
||||||
|
|
||||||
|
override fun getLayoutRes(): Int {
|
||||||
|
return R.layout.source_filter_sheet_saved_searches
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSelectable(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isSwipeable(): Boolean {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun createViewHolder(view: View, adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>): SavedSearchesHolder {
|
||||||
|
return SavedSearchesHolder(view, adapter as FlexibleAdapter<SavedSearchesItem>)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun bindViewHolder(
|
||||||
|
adapter: FlexibleAdapter<IFlexible<RecyclerView.ViewHolder>>,
|
||||||
|
holder: SavedSearchesHolder,
|
||||||
|
position: Int,
|
||||||
|
payloads: MutableList<Any?>?
|
||||||
|
) {}
|
||||||
|
|
||||||
|
override fun equals(other: Any?): Boolean {
|
||||||
|
return (this === other)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun hashCode(): Int {
|
||||||
|
return this.hashCode()
|
||||||
|
}
|
||||||
|
}
|
@ -3,9 +3,9 @@ package eu.kanade.tachiyomi.ui.browse.source.browse
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.TypedValue
|
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.MergeAdapter
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import eu.davidea.flexibleadapter.FlexibleAdapter
|
import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
@ -13,14 +13,11 @@ import eu.davidea.flexibleadapter.items.IFlexible
|
|||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.util.view.gone
|
import eu.kanade.tachiyomi.util.view.gone
|
||||||
import eu.kanade.tachiyomi.util.view.inflate
|
import eu.kanade.tachiyomi.util.view.inflate
|
||||||
import eu.kanade.tachiyomi.util.view.visible
|
|
||||||
import eu.kanade.tachiyomi.widget.SimpleNavigationView
|
import eu.kanade.tachiyomi.widget.SimpleNavigationView
|
||||||
import exh.EXHSavedSearch
|
import exh.EXHSavedSearch
|
||||||
import kotlinx.android.synthetic.main.source_filter_sheet.view.filter_btn
|
import kotlinx.android.synthetic.main.source_filter_sheet.view.filter_btn
|
||||||
import kotlinx.android.synthetic.main.source_filter_sheet.view.reset_btn
|
import kotlinx.android.synthetic.main.source_filter_sheet.view.reset_btn
|
||||||
import kotlinx.android.synthetic.main.source_filter_sheet.view.save_search_btn
|
import kotlinx.android.synthetic.main.source_filter_sheet.view.save_search_btn
|
||||||
import kotlinx.android.synthetic.main.source_filter_sheet.view.saved_searches
|
|
||||||
import kotlinx.android.synthetic.main.source_filter_sheet.view.saved_searches_title
|
|
||||||
|
|
||||||
class SourceFilterSheet(
|
class SourceFilterSheet(
|
||||||
activity: Activity,
|
activity: Activity,
|
||||||
@ -71,28 +68,31 @@ class SourceFilterSheet(
|
|||||||
class FilterNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
class FilterNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
SimpleNavigationView(context, attrs) {
|
SimpleNavigationView(context, attrs) {
|
||||||
|
|
||||||
// EXH -->
|
var onFilterClicked = {}
|
||||||
|
var onResetClicked = {}
|
||||||
|
|
||||||
|
// SY -->
|
||||||
var onSaveClicked = {}
|
var onSaveClicked = {}
|
||||||
|
|
||||||
var onSavedSearchClicked: (Int) -> Unit = {}
|
var onSavedSearchClicked: (Int) -> Unit = {}
|
||||||
|
|
||||||
var onSavedSearchDeleteClicked: (Int, String) -> Unit = { _, _ -> }
|
var onSavedSearchDeleteClicked: (Int, String) -> Unit = { _, _ -> }
|
||||||
// EXH <--
|
|
||||||
|
|
||||||
var onFilterClicked = {}
|
var savedSearchesItem = SavedSearchesItem()
|
||||||
var onResetClicked = {}
|
var savedSearchesAdapter: FlexibleAdapter<SavedSearchesItem> = FlexibleAdapter<SavedSearchesItem>(listOf(savedSearchesItem))
|
||||||
|
// SY <--
|
||||||
|
|
||||||
val adapter: FlexibleAdapter<IFlexible<*>> = FlexibleAdapter<IFlexible<*>>(null)
|
val adapter: FlexibleAdapter<IFlexible<*>> = FlexibleAdapter<IFlexible<*>>(null)
|
||||||
.setDisplayHeadersAtStartUp(true)
|
.setDisplayHeadersAtStartUp(true)
|
||||||
.setStickyHeaders(true)
|
.setStickyHeaders(true)
|
||||||
|
|
||||||
init {
|
init {
|
||||||
recycler.adapter = adapter
|
// SY -->
|
||||||
|
recycler.adapter = MergeAdapter(savedSearchesAdapter, adapter)
|
||||||
|
// SY <--
|
||||||
recycler.setHasFixedSize(true)
|
recycler.setHasFixedSize(true)
|
||||||
val view = inflate(R.layout.source_filter_sheet)
|
val view = inflate(R.layout.source_filter_sheet)
|
||||||
// SY -->
|
((view as ViewGroup).getChildAt(1) as ViewGroup).addView(recycler)
|
||||||
((view as ViewGroup).findViewById(R.id.source_filter_content) as ViewGroup).addView(recycler)
|
|
||||||
// SY <--
|
|
||||||
addView(view)
|
addView(view)
|
||||||
// SY -->
|
// SY -->
|
||||||
save_search_btn.setOnClickListener { onSaveClicked() }
|
save_search_btn.setOnClickListener { onSaveClicked() }
|
||||||
@ -103,20 +103,10 @@ class SourceFilterSheet(
|
|||||||
|
|
||||||
// EXH -->
|
// EXH -->
|
||||||
fun setSavedSearches(searches: List<EXHSavedSearch>) {
|
fun setSavedSearches(searches: List<EXHSavedSearch>) {
|
||||||
saved_searches.removeAllViews()
|
|
||||||
|
|
||||||
val outValue = TypedValue()
|
|
||||||
context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true)
|
|
||||||
|
|
||||||
save_search_btn.visibility = if (searches.size < MAX_SAVED_SEARCHES) View.VISIBLE else View.GONE
|
save_search_btn.visibility = if (searches.size < MAX_SAVED_SEARCHES) View.VISIBLE else View.GONE
|
||||||
|
val chips: MutableList<Chip> = mutableListOf()
|
||||||
|
|
||||||
if (searches.isEmpty()) {
|
searches.withIndex().sortedBy { it.value.name.toLowerCase() }.forEach { (index, search) ->
|
||||||
saved_searches_title.gone()
|
|
||||||
} else {
|
|
||||||
saved_searches_title.visible()
|
|
||||||
}
|
|
||||||
|
|
||||||
searches.withIndex().sortedBy { it.value.name }.forEach { (index, search) ->
|
|
||||||
val chip = Chip(context).apply {
|
val chip = Chip(context).apply {
|
||||||
text = search.name
|
text = search.name
|
||||||
setOnClickListener { onSavedSearchClicked(index) }
|
setOnClickListener { onSavedSearchClicked(index) }
|
||||||
@ -125,7 +115,11 @@ class SourceFilterSheet(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
saved_searches.addView(chip)
|
chips += chip
|
||||||
|
}
|
||||||
|
savedSearchesAdapter.recyclerView.post {
|
||||||
|
(recycler.findViewHolderForAdapterPosition(0) as? SavedSearchesHolder)?.setChips(chips)
|
||||||
|
savedSearchesAdapter.expand(0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<LinearLayout 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"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
@ -65,38 +64,7 @@
|
|||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
|
|
||||||
<androidx.core.widget.NestedScrollView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent"
|
|
||||||
android:orientation="vertical">
|
|
||||||
|
|
||||||
<com.google.android.material.textview.MaterialTextView
|
|
||||||
android:id="@+id/saved_searches_title"
|
|
||||||
style="@style/Theme.Widget.Chip"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="14dp"
|
|
||||||
android:layout_marginTop="8dp"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:visibility="gone"
|
|
||||||
|
|
||||||
android:text="@string/eh_saved_searches" />
|
|
||||||
|
|
||||||
<com.google.android.material.chip.ChipGroup
|
|
||||||
android:id="@+id/saved_searches"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:layout_marginEnd="16dp"
|
|
||||||
app:chipSpacingHorizontal="4dp" />
|
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:id="@+id/source_filter_content"
|
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
android:layout_gravity="top"
|
android:layout_gravity="top"
|
||||||
@ -104,7 +72,3 @@
|
|||||||
android:paddingBottom="8dp" />
|
android:paddingBottom="8dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</androidx.core.widget.NestedScrollView>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
<com.google.android.material.textview.MaterialTextView
|
||||||
|
android:id="@+id/saved_searches_title"
|
||||||
|
style="@style/Theme.Widget.Chip"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="14dp"
|
||||||
|
android:layout_marginTop="8dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:visibility="visible"
|
||||||
|
android:text="@string/eh_saved_searches" />
|
||||||
|
|
||||||
|
<com.google.android.material.chip.ChipGroup
|
||||||
|
android:id="@+id/saved_searches"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
|
android:layout_marginEnd="16dp"
|
||||||
|
app:chipSpacingHorizontal="4dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
x
Reference in New Issue
Block a user