Basic implementation of hiding catalogue by long pressing
This commit is contained in:
parent
9eb441ac44
commit
a29f33020d
3 changed files with 55 additions and 4 deletions
|
@ -18,7 +18,9 @@ import eu.davidea.flexibleadapter.FlexibleAdapter
|
||||||
import eu.davidea.flexibleadapter.items.IFlexible
|
import eu.davidea.flexibleadapter.items.IFlexible
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
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.CatalogueSource
|
||||||
|
import eu.kanade.tachiyomi.source.Source
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe
|
import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe
|
||||||
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction
|
||||||
|
@ -38,8 +40,10 @@ import uy.kohesive.injekt.api.get
|
||||||
*/
|
*/
|
||||||
class CatalogueController : NucleusController<CataloguePresenter>(),
|
class CatalogueController : NucleusController<CataloguePresenter>(),
|
||||||
FlexibleAdapter.OnItemClickListener,
|
FlexibleAdapter.OnItemClickListener,
|
||||||
|
FlexibleAdapter.OnItemLongClickListener,
|
||||||
CatalogueAdapter.OnBrowseClickListener,
|
CatalogueAdapter.OnBrowseClickListener,
|
||||||
CatalogueAdapter.OnLatestClickListener {
|
CatalogueAdapter.OnLatestClickListener,
|
||||||
|
HideCatalogueDialog.Listener {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application preferences.
|
* Application preferences.
|
||||||
|
@ -118,9 +122,6 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when item is clicked
|
|
||||||
*/
|
|
||||||
override fun onItemClick(view: View, position: Int): Boolean {
|
override fun onItemClick(view: View, position: Int): Boolean {
|
||||||
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
val item = adapter?.getItem(position) as? SourceItem ?: return false
|
||||||
val source = item.source
|
val source = item.source
|
||||||
|
@ -128,6 +129,22 @@ class CatalogueController : NucleusController<CataloguePresenter>(),
|
||||||
return false
|
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]
|
* Called when browse is clicked in [CatalogueAdapter]
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -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<SourceManager>().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)
|
||||||
|
}
|
||||||
|
}
|
|
@ -367,6 +367,7 @@
|
||||||
<string name="action_global_search_hint">Global search…</string>
|
<string name="action_global_search_hint">Global search…</string>
|
||||||
<string name="latest">Latest</string>
|
<string name="latest">Latest</string>
|
||||||
<string name="browse">Browse</string>
|
<string name="browse">Browse</string>
|
||||||
|
<string name="hide_catalogue">Hide %1$s?</string>
|
||||||
|
|
||||||
<!-- Manga activity -->
|
<!-- Manga activity -->
|
||||||
<string name="manga_not_in_db">This manga has been removed from the database.</string>
|
<string name="manga_not_in_db">This manga has been removed from the database.</string>
|
||||||
|
|
Reference in a new issue