From a29f33020d6f802089e144188a9533ec74660860 Mon Sep 17 00:00:00 2001 From: arkon Date: Mon, 2 Mar 2020 22:49:48 -0500 Subject: [PATCH] Basic implementation of hiding catalogue by long pressing --- .../ui/catalogue/CatalogueController.kt | 25 +++++++++++--- .../ui/catalogue/HideCatalogueDialog.kt | 33 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 3 files changed, 55 insertions(+), 4 deletions(-) create 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 2b5ef6ded..3e3ef0e48 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 @@ -18,7 +18,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.CatalogueSource +import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction @@ -38,8 +40,10 @@ import uy.kohesive.injekt.api.get */ class CatalogueController : NucleusController(), FlexibleAdapter.OnItemClickListener, + FlexibleAdapter.OnItemLongClickListener, CatalogueAdapter.OnBrowseClickListener, - CatalogueAdapter.OnLatestClickListener { + CatalogueAdapter.OnLatestClickListener, + HideCatalogueDialog.Listener { /** * Application preferences. @@ -118,9 +122,6 @@ class CatalogueController : NucleusController(), } } - /** - * Called when item is clicked - */ override fun onItemClick(view: View, position: Int): Boolean { val item = adapter?.getItem(position) as? SourceItem ?: return false val source = item.source @@ -128,6 +129,22 @@ class CatalogueController : NucleusController(), return false } + override fun onItemLongClick(position: Int) { + val item = adapter?.getItem(position) as? SourceItem ?: return + val source = item.source + + val dialog = HideCatalogueDialog(source) + dialog.targetController = this@CatalogueController + dialog.showDialog(router) + } + + override fun hideCatalogueDialogClosed(source: Source) { + val current = preferences.hiddenCatalogues().getOrDefault() + preferences.hiddenCatalogues().set(current + source.id.toString()) + + presenter.updateSources() + } + /** * Called when browse is clicked in [CatalogueAdapter] */ 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 new file mode 100644 index 000000000..44b1e5d47 --- /dev/null +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/HideCatalogueDialog.kt @@ -0,0 +1,33 @@ +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 f53f59c48..1904d2c0e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -367,6 +367,7 @@ Global search… Latest Browse + Hide %1$s? This manga has been removed from the database.