Skip to content

Commit

Permalink
Make toggle state persistent across library searches
Browse files Browse the repository at this point in the history
  • Loading branch information
h-hyuuga committed Aug 22, 2022
1 parent f70ec39 commit 0fb0b25
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ class PreferencesHelper(val context: Context) {

fun showAllCategories() = flowPrefs.getBoolean("show_all_categories", true)

fun showAllCategoriesWhenSearchingSingleCategory() = flowPrefs.getBoolean("show_all_categories_when_searching_single_category", false)

fun hopperGravity() = flowPrefs.getInt("hopper_gravity", 1)

fun filterOrder() = flowPrefs.getString("filter_order", FilterBottomSheet.Filters.DEFAULT_ORDER)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1351,17 +1351,22 @@ class LibraryController(
}

fun search(query: String?): Boolean {
if (query.isNullOrBlank() && this.query.isNotBlank() && presenter.forceShowAllCategories) {
val isShowAllCategoriesSet = preferences.showAllCategories().get()
if (!query.isNullOrBlank() && this.query.isBlank() && !isShowAllCategoriesSet) {
presenter.forceShowAllCategories = preferences.showAllCategoriesWhenSearchingSingleCategory().get()
presenter.getLibrary()
} else if (query.isNullOrBlank() && this.query.isNotBlank() && !isShowAllCategoriesSet) {
preferences.showAllCategoriesWhenSearchingSingleCategory().set(presenter.forceShowAllCategories)
presenter.forceShowAllCategories = false
presenter.getLibrary()
showAllCategoriesView?.isSelected = presenter.forceShowAllCategories
}

if (query != this.query && !query.isNullOrBlank()) {
binding.libraryGridRecycler.recycler.scrollToPosition(0)
}
this.query = query ?: ""
showAllCategoriesView?.isGone = presenter.showAllCategories || presenter.groupType != BY_DEFAULT || this.query.isBlank()
showAllCategoriesView?.isGone = isShowAllCategoriesSet || presenter.groupType != BY_DEFAULT || this.query.isBlank()
showAllCategoriesView?.isSelected = presenter.forceShowAllCategories
if (this.query.isNotBlank()) {
searchItem.string = this.query
if (adapter.scrollableHeaders.isEmpty()) { adapter.addScrollableHeader(searchItem) }
Expand Down

0 comments on commit 0fb0b25

Please sign in to comment.