pull/475/head
gedoor 4 years ago
parent 0e43e6ce43
commit b556dad280
  1. 23
      app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt
  2. 19
      app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt
  3. 7
      app/src/main/java/io/legado/app/ui/association/ImportBookSourceActivity.kt
  4. 14
      app/src/main/java/io/legado/app/ui/association/ImportReplaceRuleActivity.kt
  5. 7
      app/src/main/java/io/legado/app/ui/association/ImportRssSourceActivity.kt
  6. 7
      app/src/main/java/io/legado/app/ui/config/BackupConfigFragment.kt

@ -47,19 +47,34 @@ interface AlertBuilder<out D : DialogInterface> {
@Deprecated(NO_GETTER, level = ERROR) get @Deprecated(NO_GETTER, level = ERROR) get
fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) 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(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(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 onCancelled(handler: (dialog: DialogInterface) -> Unit)
fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean)
fun items(items: List<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) fun onDismiss(handler: (dialog: DialogInterface) -> Unit)
fun items(
items: List<CharSequence>,
onItemSelected: (dialog: DialogInterface, index: Int) -> Unit
)
fun <T> items( fun <T> items(
items: List<T>, items: List<T>,
onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit

@ -74,15 +74,28 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
builder.setNegativeButton(buttonTextResource) { dialog, _ -> onClicked?.invoke(dialog) } builder.setNegativeButton(buttonTextResource) { dialog, _ -> 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) } 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) } builder.setNeutralButton(buttonTextResource) { dialog, _ -> onClicked?.invoke(dialog) }
} }
override fun items(items: List<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) { override fun onDismiss(handler: (dialog: DialogInterface) -> Unit) {
builder.setOnDismissListener(handler)
}
override fun items(
items: List<CharSequence>,
onItemSelected: (dialog: DialogInterface, index: Int) -> Unit
) {
builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which -> builder.setItems(Array(items.size) { i -> items[i].toString() }) { dialog, which ->
onItemSelected(dialog, which) onItemSelected(dialog, which)
} }

@ -73,9 +73,10 @@ class ImportBookSourceActivity : VMBaseActivity<ImportBookSourceViewModel>(
private fun errorDialog(msg: String) { private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) { alert(getString(R.string.error), msg) {
okButton { } okButton { }
}.show().setOnDismissListener { onDismiss {
finish() finish()
} }
}.show()
} }
private fun successDialog() { private fun successDialog() {

@ -75,9 +75,10 @@ class ImportReplaceRuleActivity : VMBaseActivity<ImportReplaceRuleViewModel>(
private fun errorDialog(msg: String) { private fun errorDialog(msg: String) {
alert("导入出错", msg) { alert("导入出错", msg) {
okButton { } okButton { }
}.show().setOnDismissListener { onDismiss {
finish() finish()
} }
}.show()
} }
private fun successDialog(allSource: ArrayList<ReplaceRule>) { private fun successDialog(allSource: ArrayList<ReplaceRule>) {
@ -88,8 +89,9 @@ class ImportReplaceRuleActivity : VMBaseActivity<ImportReplaceRuleViewModel>(
noButton { noButton {
} }
}.show().setOnDismissListener { onDismiss {
finish() finish()
} }
}.show()
} }
} }

@ -72,9 +72,10 @@ class ImportRssSourceActivity : VMBaseActivity<ImportRssSourceViewModel>(
private fun errorDialog(msg: String) { private fun errorDialog(msg: String) {
alert(getString(R.string.error), msg) { alert(getString(R.string.error), msg) {
okButton { } okButton { }
}.show().setOnDismissListener { onDismiss {
finish() finish()
} }
}.show()
} }
private fun successDialog() { private fun successDialog() {

@ -153,9 +153,10 @@ class BackupConfigFragment : BasePreferenceFragment(),
multiChoiceItems(Restore.ignoreTitle, checkedItems) { _, which, isChecked -> multiChoiceItems(Restore.ignoreTitle, checkedItems) { _, which, isChecked ->
Restore.ignoreConfig[Restore.ignoreKeys[which]] = isChecked Restore.ignoreConfig[Restore.ignoreKeys[which]] = isChecked
} }
}.show().setOnDismissListener { onDismiss {
Restore.saveIgnoreConfig() Restore.saveIgnoreConfig()
} }
}.show()
} }
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

Loading…
Cancel
Save