diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt b/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt index 3c640f384..9c48fa090 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt @@ -47,19 +47,34 @@ interface AlertBuilder { @Deprecated(NO_GETTER, level = ERROR) get fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) - fun positiveButton(@StringRes buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)? = null) + fun positiveButton( + @StringRes buttonTextResource: Int, + onClicked: ((dialog: DialogInterface) -> Unit)? = null + ) fun negativeButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) - fun negativeButton(@StringRes buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)? = null) + fun negativeButton( + @StringRes buttonTextResource: Int, + onClicked: ((dialog: DialogInterface) -> Unit)? = null + ) fun neutralButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) - fun neutralButton(@StringRes buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)? = null) + fun neutralButton( + @StringRes buttonTextResource: Int, + onClicked: ((dialog: DialogInterface) -> Unit)? = null + ) fun onCancelled(handler: (dialog: DialogInterface) -> Unit) fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) - fun items(items: List, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) + fun onDismiss(handler: (dialog: DialogInterface) -> Unit) + + fun items( + items: List, + onItemSelected: (dialog: DialogInterface, index: Int) -> Unit + ) + fun items( items: List, onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit diff --git a/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt b/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt index b03fe17f6..cf53eac12 100644 --- a/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt +++ b/app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt @@ -74,15 +74,28 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder onClicked?.invoke(dialog) } } - override fun neutralButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)?) { + override fun neutralButton( + buttonText: String, + onClicked: ((dialog: DialogInterface) -> Unit)? + ) { builder.setNeutralButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun neutralButton(buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)?) { + override fun neutralButton( + buttonTextResource: Int, + onClicked: ((dialog: DialogInterface) -> Unit)? + ) { builder.setNeutralButton(buttonTextResource) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun items(items: List, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) { + override fun onDismiss(handler: (dialog: DialogInterface) -> Unit) { + builder.setOnDismissListener(handler) + } + + override fun items( + items: List, + onItemSelected: (dialog: DialogInterface, index: Int) -> Unit + ) { builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which -> onItemSelected(dialog, which) } diff --git a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt index 383673e94..fea9c0082 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt @@ -73,9 +73,10 @@ class ImportBookSourceActivity : VMBaseActivity( private fun errorDialog(msg: String) { alert(getString(R.string.error), msg) { okButton { } - }.show().setOnDismissListener { - finish() - } + onDismiss { + finish() + } + }.show() } private fun successDialog() { diff --git a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt index a7683b010..04d6426fb 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt @@ -75,9 +75,10 @@ class ImportReplaceRuleActivity : VMBaseActivity( private fun errorDialog(msg: String) { alert("导入出错", msg) { okButton { } - }.show().setOnDismissListener { - finish() - } + onDismiss { + finish() + } + }.show() } private fun successDialog(allSource: ArrayList) { @@ -88,8 +89,9 @@ class ImportReplaceRuleActivity : VMBaseActivity( noButton { } - }.show().setOnDismissListener { - finish() - } + onDismiss { + finish() + } + }.show() } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt index 5e2c448d5..fbb54ba1e 100644 --- a/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt +++ b/app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt @@ -72,9 +72,10 @@ class ImportRssSourceActivity : VMBaseActivity( private fun errorDialog(msg: String) { alert(getString(R.string.error), msg) { okButton { } - }.show().setOnDismissListener { - finish() - } + onDismiss { + finish() + } + }.show() } private fun successDialog() { diff --git a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt index bc5257cef..33b708d59 100644 --- a/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt +++ b/app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt @@ -153,9 +153,10 @@ class BackupConfigFragment : BasePreferenceFragment(), multiChoiceItems(Restore.ignoreTitle, checkedItems) { _, which, isChecked -> Restore.ignoreConfig[Restore.ignoreKeys[which]] = isChecked } - }.show().setOnDismissListener { - Restore.saveIgnoreConfig() - } + onDismiss { + Restore.saveIgnoreConfig() + } + }.show() } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {