Make source options dialog into a controller to retain state
This commit is contained in:
parent
b9488645d4
commit
01a837fde6
@ -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<Pair<String, () -> Unit>>
|
||||
|
||||
constructor(item: SourceItem, items: List<Pair<String, () -> 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()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user