From 4c10b9844b339fd1c337377194dbdbfe25a4cd3f 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 | 21 ++++++++---- .../ui/catalogue/HideCatalogueDialog.kt | 33 ------------------- app/src/main/res/values/strings.xml | 2 +- 3 files changed, 15 insertions(+), 41 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 3e3ef0e48b..57f1b13ff3 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 @@ -9,6 +9,7 @@ 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.bluelinelabs.conductor.ControllerChangeHandler import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.RouterTransaction @@ -42,8 +43,7 @@ class CatalogueController : NucleusController(), FlexibleAdapter.OnItemClickListener, FlexibleAdapter.OnItemLongClickListener, CatalogueAdapter.OnBrowseClickListener, - CatalogueAdapter.OnLatestClickListener, - HideCatalogueDialog.Listener { + CatalogueAdapter.OnLatestClickListener { /** * Application preferences. @@ -130,15 +130,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.Builder(activity) + .title(item.source.name) + .items(activity.getString(R.string.action_hide)) + .itemsCallback { _, _, which, _ -> + when (which) { + 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 44b1e5d47c..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/HideCatalogueDialog.kt +++ /dev/null @@ -1,33 +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.Builder(activity!!) - .title(activity!!.getString(R.string.hide_catalogue, source.name)) - .positiveText(android.R.string.ok) - .onPositive { _, _ -> - (targetController as? Listener)?.hideCatalogueDialogClosed(source) - } - .negativeText(android.R.string.cancel) - .build() - } - - 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 0560ad965a..a163c9ebd2 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -83,6 +83,7 @@ Grid List Download badges + Hide Set filter Cancel Cancel all @@ -368,7 +369,6 @@ Global search… Latest Browse - Hide %1$s? This manga has been removed from the database.