diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt index e9652dc57b..1dcee82f21 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/SourceController.kt @@ -1,6 +1,8 @@ package eu.kanade.tachiyomi.ui.browse.source import android.Manifest.permission.WRITE_EXTERNAL_STORAGE +import android.app.Dialog +import android.os.Bundle import android.view.LayoutInflater import android.view.Menu import android.view.MenuInflater @@ -23,6 +25,7 @@ import eu.kanade.tachiyomi.databinding.SourceMainControllerBinding import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.LocalSource import eu.kanade.tachiyomi.source.Source +import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.requestPermissionsSafe import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction @@ -137,19 +140,15 @@ class SourceController : ) ) if (item.source !is LocalSource) { - items.add(Pair(activity.getString(R.string.action_disable), { disableSource(item.source) })) + items.add( + Pair( + activity.getString(R.string.action_disable), + { disableSource(item.source) } + ) + ) } - MaterialDialog(activity) - .title(text = item.source.toString()) - .listItems( - items = items.map { it.first }, - waitForPositiveButton = false - ) { dialog, which, _ -> - items[which].second() - dialog.dismiss() - } - .show() + SourceOptionsDialog(item, items).showDialog(router) } private fun disableSource(source: Source) { @@ -267,4 +266,27 @@ class SourceController : adapter?.addScrollableHeader(LangItem(SourcePresenter.LAST_USED_KEY)) } } + + class SourceOptionsDialog(bundle: Bundle? = null) : DialogController(bundle) { + + private lateinit var item: SourceItem + private lateinit var items: List Unit>> + + constructor(item: SourceItem, items: List Unit>>) : this() { + this.item = item + this.items = items + } + + override fun onCreateDialog(savedViewState: Bundle?): Dialog { + return MaterialDialog(activity!!) + .title(text = item.source.toString()) + .listItems( + items = items.map { it.first }, + waitForPositiveButton = false + ) { dialog, which, _ -> + items[which].second() + dialog.dismiss() + } + } + } }