Saved searches now work
This commit is contained in:
parent
5e5f2b0f1a
commit
35c4d0bf4e
@ -33,6 +33,7 @@ import eu.kanade.tachiyomi.source.online.HttpSource
|
|||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
import eu.kanade.tachiyomi.ui.browse.source.SourceController
|
import eu.kanade.tachiyomi.ui.browse.source.SourceController
|
||||||
|
import eu.kanade.tachiyomi.ui.browse.source.browse.SourceFilterSheet.FilterNavigationView.Companion.MAX_SAVED_SEARCHES
|
||||||
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
import eu.kanade.tachiyomi.ui.library.ChangeMangaCategoriesDialog
|
||||||
import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight
|
import eu.kanade.tachiyomi.ui.main.offsetFabAppbarHeight
|
||||||
import eu.kanade.tachiyomi.ui.manga.MangaController
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
@ -168,6 +169,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
presenter.sourceFilters = newFilters
|
presenter.sourceFilters = newFilters
|
||||||
filterSheet?.setFilters(presenter.filterItems)
|
filterSheet?.setFilters(presenter.filterItems)
|
||||||
},
|
},
|
||||||
|
// EXH -->
|
||||||
onSaveClicked = {
|
onSaveClicked = {
|
||||||
filterSheet?.context?.let {
|
filterSheet?.context?.let {
|
||||||
MaterialDialog(it)
|
MaterialDialog(it)
|
||||||
@ -175,7 +177,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
.input("My search name", hintRes = null) { _, searchName ->
|
.input("My search name", hintRes = null) { _, searchName ->
|
||||||
val oldSavedSearches = presenter.loadSearches()
|
val oldSavedSearches = presenter.loadSearches()
|
||||||
if (searchName.isNotBlank() &&
|
if (searchName.isNotBlank() &&
|
||||||
oldSavedSearches.size < SourceFilterSheet.MAX_SAVED_SEARCHES
|
oldSavedSearches.size < MAX_SAVED_SEARCHES
|
||||||
) {
|
) {
|
||||||
val newSearches = oldSavedSearches + EXHSavedSearch(
|
val newSearches = oldSavedSearches + EXHSavedSearch(
|
||||||
searchName.toString().trim(),
|
searchName.toString().trim(),
|
||||||
@ -247,7 +249,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
index != indexToDelete
|
index != indexToDelete
|
||||||
}
|
}
|
||||||
presenter.saveSearches(newSearches)
|
presenter.saveSearches(newSearches)
|
||||||
filterSheet!!.setSavedSearches(newSearches)
|
filterSheet?.setSavedSearches(newSearches)
|
||||||
}
|
}
|
||||||
.cancelable(true)
|
.cancelable(true)
|
||||||
.cancelOnTouchOutside(true)
|
.cancelOnTouchOutside(true)
|
||||||
@ -256,6 +258,10 @@ open class BrowseSourceController(bundle: Bundle) :
|
|||||||
}
|
}
|
||||||
// EXH <--
|
// EXH <--
|
||||||
)
|
)
|
||||||
|
// EXH -->
|
||||||
|
filterSheet?.setSavedSearches(presenter.loadSearches())
|
||||||
|
// EXH <--
|
||||||
|
|
||||||
filterSheet?.setFilters(presenter.filterItems)
|
filterSheet?.setFilters(presenter.filterItems)
|
||||||
|
|
||||||
// TODO: [ExtendedFloatingActionButton] hide/show methods don't work properly
|
// TODO: [ExtendedFloatingActionButton] hide/show methods don't work properly
|
||||||
|
@ -17,8 +17,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx
|
|||||||
import eu.kanade.tachiyomi.util.view.inflate
|
import eu.kanade.tachiyomi.util.view.inflate
|
||||||
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.save_search_btn
|
|
||||||
import kotlinx.android.synthetic.main.source_filter_sheet.saved_searches
|
|
||||||
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
|
||||||
@ -49,6 +47,14 @@ class SourceFilterSheet(
|
|||||||
filterNavView.onSaveClicked = onSaveClicked
|
filterNavView.onSaveClicked = onSaveClicked
|
||||||
// EXH <--
|
// EXH <--
|
||||||
|
|
||||||
|
// EXH -->
|
||||||
|
filterNavView.onSavedSearchClicked = onSavedSearchClicked
|
||||||
|
// EXH <--
|
||||||
|
|
||||||
|
// EXH -->
|
||||||
|
filterNavView.onSavedSearchDeleteClicked = onSavedSearchDeleteClicked
|
||||||
|
// EXH <--
|
||||||
|
|
||||||
setContentView(filterNavView)
|
setContentView(filterNavView)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +62,10 @@ class SourceFilterSheet(
|
|||||||
filterNavView.adapter.updateDataSet(items)
|
filterNavView.adapter.updateDataSet(items)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun setSavedSearches(searches: List<EXHSavedSearch>) {
|
||||||
|
filterNavView.setSavedSearches(searches)
|
||||||
|
}
|
||||||
|
|
||||||
class FilterNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
class FilterNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
|
||||||
SimpleNavigationView(context, attrs) {
|
SimpleNavigationView(context, attrs) {
|
||||||
|
|
||||||
@ -63,6 +73,14 @@ class SourceFilterSheet(
|
|||||||
var onSaveClicked = {}
|
var onSaveClicked = {}
|
||||||
// EXH <--
|
// EXH <--
|
||||||
|
|
||||||
|
// EXH -->
|
||||||
|
var onSavedSearchClicked: (Int) -> Unit = {}
|
||||||
|
// EXH <--
|
||||||
|
|
||||||
|
// EXH -->
|
||||||
|
var onSavedSearchDeleteClicked: (Int, String) -> Unit = { _, _ -> }
|
||||||
|
// EXH <--
|
||||||
|
|
||||||
var onFilterClicked = {}
|
var onFilterClicked = {}
|
||||||
var onResetClicked = {}
|
var onResetClicked = {}
|
||||||
|
|
||||||
@ -74,43 +92,43 @@ class SourceFilterSheet(
|
|||||||
recycler.adapter = adapter
|
recycler.adapter = adapter
|
||||||
recycler.setHasFixedSize(true)
|
recycler.setHasFixedSize(true)
|
||||||
val view = inflate(R.layout.source_filter_sheet)
|
val view = inflate(R.layout.source_filter_sheet)
|
||||||
((view as ViewGroup).getChildAt(1) as ViewGroup).addView(recycler)
|
((view as ViewGroup).findViewById(R.id.source_filter_content) as ViewGroup).addView(recycler)
|
||||||
addView(view)
|
addView(view)
|
||||||
save_search_btn.setOnClickListener { onSaveClicked() }
|
save_search_btn.setOnClickListener { onSaveClicked() }
|
||||||
filter_btn.setOnClickListener { onFilterClicked() }
|
filter_btn.setOnClickListener { onFilterClicked() }
|
||||||
reset_btn.setOnClickListener { onResetClicked() }
|
reset_btn.setOnClickListener { onResetClicked() }
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// EXH -->
|
// EXH -->
|
||||||
fun setSavedSearches(searches: List<EXHSavedSearch>) {
|
fun setSavedSearches(searches: List<EXHSavedSearch>) {
|
||||||
saved_searches.removeAllViews()
|
saved_searches.removeAllViews()
|
||||||
|
|
||||||
val outValue = TypedValue()
|
val outValue = TypedValue()
|
||||||
context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true)
|
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
|
||||||
|
|
||||||
searches.withIndex().sortedBy { it.value.name }.forEach { (index, search) ->
|
searches.withIndex().sortedBy { it.value.name }.forEach { (index, search) ->
|
||||||
val restoreBtn = TextView(context)
|
val restoreBtn = TextView(context)
|
||||||
restoreBtn.text = search.name
|
restoreBtn.text = search.name
|
||||||
val params = LinearLayout.LayoutParams(
|
val params = LinearLayout.LayoutParams(
|
||||||
ViewGroup.LayoutParams.MATCH_PARENT,
|
ViewGroup.LayoutParams.MATCH_PARENT,
|
||||||
ViewGroup.LayoutParams.WRAP_CONTENT
|
ViewGroup.LayoutParams.WRAP_CONTENT
|
||||||
)
|
)
|
||||||
params.gravity = Gravity.CENTER
|
params.gravity = Gravity.CENTER
|
||||||
restoreBtn.layoutParams = params
|
restoreBtn.layoutParams = params
|
||||||
restoreBtn.gravity = Gravity.CENTER
|
restoreBtn.gravity = Gravity.CENTER
|
||||||
restoreBtn.setBackgroundResource(outValue.resourceId)
|
restoreBtn.setBackgroundResource(outValue.resourceId)
|
||||||
restoreBtn.setPadding(8.dpToPx, 8.dpToPx, 8.dpToPx, 8.dpToPx)
|
restoreBtn.setPadding(8.dpToPx, 8.dpToPx, 8.dpToPx, 8.dpToPx)
|
||||||
restoreBtn.setOnClickListener { onSavedSearchClicked(index) }
|
restoreBtn.setOnClickListener { onSavedSearchClicked(index) }
|
||||||
restoreBtn.setOnLongClickListener { onSavedSearchDeleteClicked(index, search.name); true }
|
restoreBtn.setOnLongClickListener { onSavedSearchDeleteClicked(index, search.name); true }
|
||||||
saved_searches.addView(restoreBtn)
|
saved_searches.addView(restoreBtn)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val MAX_SAVED_SEARCHES = 5
|
const val MAX_SAVED_SEARCHES = 500 // if you want more than this, fuck you, i guess
|
||||||
|
}
|
||||||
|
// EXH <--
|
||||||
}
|
}
|
||||||
// EXH <--
|
|
||||||
}
|
}
|
||||||
|
@ -64,18 +64,33 @@
|
|||||||
|
|
||||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/saved_searches"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:animateLayoutChanges="true"
|
|
||||||
android:orientation="vertical" />
|
|
||||||
|
|
||||||
<FrameLayout
|
<androidx.core.widget.NestedScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="wrap_content">
|
||||||
android:layout_gravity="top"
|
|
||||||
android:layout_weight="1"
|
<LinearLayout
|
||||||
android:paddingBottom="8dp" />
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/saved_searches"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:animateLayoutChanges="true"
|
||||||
|
android:orientation="vertical" />
|
||||||
|
|
||||||
|
<FrameLayout
|
||||||
|
android:id="@+id/source_filter_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_gravity="top"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:paddingBottom="8dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</androidx.core.widget.NestedScrollView>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user