mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Saved searches now work
This commit is contained in:
		| @@ -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 | ||||
|   | ||||
| @@ -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 <-- | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user