From 849cb4208f74b9dc4a8764b478c9e65e0f2eb058 Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 4 Mar 2020 19:06:24 -0500 Subject: [PATCH] Change catalogue hiding dialog to accommodate more options in the future --- .../ui/catalogue/CatalogueController.kt | 23 +++++++++----- .../ui/catalogue/HideCatalogueDialog.kt | 31 ------------------- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 17 insertions(+), 39 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/HideCatalogueDialog.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt index 630e678f3d..26f467197a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt @@ -10,6 +10,9 @@ import android.view.MenuItem import android.view.View import android.view.ViewGroup import androidx.appcompat.widget.SearchView +import androidx.recyclerview.widget.LinearLayoutManager +import com.afollestad.materialdialogs.MaterialDialog +import com.afollestad.materialdialogs.list.listItems import com.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.RouterTransaction @@ -60,8 +63,7 @@ class CatalogueController : NucleusController(), CatalogueAdapter.OnBrowseClickListener, RootSearchInterface, BottomSheetController, - CatalogueAdapter.OnLatestClickListener, - HideCatalogueDialog.Listener { + CatalogueAdapter.OnLatestClickListener { /** * Application preferences. @@ -254,15 +256,22 @@ class CatalogueController : NucleusController(), } override fun onItemLongClick(position: Int) { + val activity = activity ?: return val item = adapter?.getItem(position) as? SourceItem ?: return - val source = item.source - val dialog = HideCatalogueDialog(source) - dialog.targetController = this@CatalogueController - dialog.showDialog(router) + MaterialDialog(activity) + .title(text = item.source.name) + .listItems(items = listOf(activity.getString(R.string.hide)), + waitForPositiveButton = false, selection = { _, index, _ -> + when (index) { + 0 -> { + hideCatalogue(item.source) + } + } + }).show() } - override fun hideCatalogueDialogClosed(source: Source) { + private fun hideCatalogue(source: Source) { val current = preferences.hiddenCatalogues().getOrDefault() preferences.hiddenCatalogues().set(current + source.id.toString()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/HideCatalogueDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/HideCatalogueDialog.kt deleted file mode 100644 index cdc13f39df..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/HideCatalogueDialog.kt +++ /dev/null @@ -1,31 +0,0 @@ -package eu.kanade.tachiyomi.ui.catalogue - -import android.app.Dialog -import android.os.Bundle -import com.afollestad.materialdialogs.MaterialDialog -import eu.kanade.tachiyomi.R -import eu.kanade.tachiyomi.source.Source -import eu.kanade.tachiyomi.source.SourceManager -import eu.kanade.tachiyomi.ui.base.controller.DialogController -import uy.kohesive.injekt.Injekt -import uy.kohesive.injekt.api.get - -class HideCatalogueDialog(bundle: Bundle? = null) : DialogController(bundle) { - - private val source = Injekt.get().get(args.getLong("key"))!! - - constructor(source: Source) : this(Bundle().apply { putLong("key", source.id) }) - - override fun onCreateDialog(savedViewState: Bundle?): Dialog { - return MaterialDialog(activity!!) - .title(text = activity!!.getString(R.string.hide_question, source.name)) - .positiveButton(android.R.string.ok) { - (targetController as? Listener)?.hideCatalogueDialogClosed(source) - } - .negativeButton(android.R.string.cancel) - } - - interface Listener { - fun hideCatalogueDialogClosed(source: Source) - } -} diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 48ef52feaa..82cb30eb81 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -630,7 +630,7 @@ Filter Forward Free - Hide %1$s? + Hide Ignore Install Left