Saved searches now work

This commit is contained in:
Jobobby04 2020-05-06 15:19:37 -04:00
parent 5e5f2b0f1a
commit 35c4d0bf4e
3 changed files with 81 additions and 42 deletions

View File

@ -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.withFadeTransaction
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.main.offsetFabAppbarHeight
import eu.kanade.tachiyomi.ui.manga.MangaController
@ -168,6 +169,7 @@ open class BrowseSourceController(bundle: Bundle) :
presenter.sourceFilters = newFilters
filterSheet?.setFilters(presenter.filterItems)
},
// EXH -->
onSaveClicked = {
filterSheet?.context?.let {
MaterialDialog(it)
@ -175,7 +177,7 @@ open class BrowseSourceController(bundle: Bundle) :
.input("My search name", hintRes = null) { _, searchName ->
val oldSavedSearches = presenter.loadSearches()
if (searchName.isNotBlank() &&
oldSavedSearches.size < SourceFilterSheet.MAX_SAVED_SEARCHES
oldSavedSearches.size < MAX_SAVED_SEARCHES
) {
val newSearches = oldSavedSearches + EXHSavedSearch(
searchName.toString().trim(),
@ -247,7 +249,7 @@ open class BrowseSourceController(bundle: Bundle) :
index != indexToDelete
}
presenter.saveSearches(newSearches)
filterSheet!!.setSavedSearches(newSearches)
filterSheet?.setSavedSearches(newSearches)
}
.cancelable(true)
.cancelOnTouchOutside(true)
@ -256,6 +258,10 @@ open class BrowseSourceController(bundle: Bundle) :
}
// EXH <--
)
// EXH -->
filterSheet?.setSavedSearches(presenter.loadSearches())
// EXH <--
filterSheet?.setFilters(presenter.filterItems)
// TODO: [ExtendedFloatingActionButton] hide/show methods don't work properly

View File

@ -17,8 +17,6 @@ import eu.kanade.tachiyomi.util.system.dpToPx
import eu.kanade.tachiyomi.util.view.inflate
import eu.kanade.tachiyomi.widget.SimpleNavigationView
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.reset_btn
import kotlinx.android.synthetic.main.source_filter_sheet.view.save_search_btn
@ -49,6 +47,14 @@ class SourceFilterSheet(
filterNavView.onSaveClicked = onSaveClicked
// EXH <--
// EXH -->
filterNavView.onSavedSearchClicked = onSavedSearchClicked
// EXH <--
// EXH -->
filterNavView.onSavedSearchDeleteClicked = onSavedSearchDeleteClicked
// EXH <--
setContentView(filterNavView)
}
@ -56,6 +62,10 @@ class SourceFilterSheet(
filterNavView.adapter.updateDataSet(items)
}
fun setSavedSearches(searches: List<EXHSavedSearch>) {
filterNavView.setSavedSearches(searches)
}
class FilterNavigationView @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null) :
SimpleNavigationView(context, attrs) {
@ -63,6 +73,14 @@ class SourceFilterSheet(
var onSaveClicked = {}
// EXH <--
// EXH -->
var onSavedSearchClicked: (Int) -> Unit = {}
// EXH <--
// EXH -->
var onSavedSearchDeleteClicked: (Int, String) -> Unit = { _, _ -> }
// EXH <--
var onFilterClicked = {}
var onResetClicked = {}
@ -74,43 +92,43 @@ class SourceFilterSheet(
recycler.adapter = adapter
recycler.setHasFixedSize(true)
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)
save_search_btn.setOnClickListener { onSaveClicked() }
filter_btn.setOnClickListener { onFilterClicked() }
reset_btn.setOnClickListener { onResetClicked() }
}
}
// EXH -->
fun setSavedSearches(searches: List<EXHSavedSearch>) {
saved_searches.removeAllViews()
// EXH -->
fun setSavedSearches(searches: List<EXHSavedSearch>) {
saved_searches.removeAllViews()
val outValue = TypedValue()
context.theme.resolveAttribute(android.R.attr.selectableItemBackground, outValue, true)
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
searches.withIndex().sortedBy { it.value.name }.forEach { (index, search) ->
val restoreBtn = TextView(context)
restoreBtn.text = search.name
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
params.gravity = Gravity.CENTER
restoreBtn.layoutParams = params
restoreBtn.gravity = Gravity.CENTER
restoreBtn.setBackgroundResource(outValue.resourceId)
restoreBtn.setPadding(8.dpToPx, 8.dpToPx, 8.dpToPx, 8.dpToPx)
restoreBtn.setOnClickListener { onSavedSearchClicked(index) }
restoreBtn.setOnLongClickListener { onSavedSearchDeleteClicked(index, search.name); true }
saved_searches.addView(restoreBtn)
searches.withIndex().sortedBy { it.value.name }.forEach { (index, search) ->
val restoreBtn = TextView(context)
restoreBtn.text = search.name
val params = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
params.gravity = Gravity.CENTER
restoreBtn.layoutParams = params
restoreBtn.gravity = Gravity.CENTER
restoreBtn.setBackgroundResource(outValue.resourceId)
restoreBtn.setPadding(8.dpToPx, 8.dpToPx, 8.dpToPx, 8.dpToPx)
restoreBtn.setOnClickListener { onSavedSearchClicked(index) }
restoreBtn.setOnLongClickListener { onSavedSearchDeleteClicked(index, search.name); true }
saved_searches.addView(restoreBtn)
}
}
}
companion object {
const val MAX_SAVED_SEARCHES = 5
companion object {
const val MAX_SAVED_SEARCHES = 500 // if you want more than this, fuck you, i guess
}
// EXH <--
}
// EXH <--
}

View File

@ -64,18 +64,33 @@
</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_height="0dp"
android:layout_gravity="top"
android:layout_weight="1"
android:paddingBottom="8dp" />
android:layout_height="wrap_content">
<LinearLayout
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>