From 52bd3a473105302cd846a1678a49a88a436d8068 Mon Sep 17 00:00:00 2001 From: Administrator <1760316362@qq.com> Date: Thu, 1 Aug 2019 11:47:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/lib/dialogs/AlertBuilder.kt | 27 ++++++++++--------- .../app/lib/dialogs/AndroidAlertBuilder.kt | 24 ++++++++--------- .../ui/main/bookshelf/BookshelfFragment.kt | 2 +- 3 files changed, 27 insertions(+), 26 deletions(-) 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 4617e99f1..0ab0db154 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 @@ -15,6 +15,7 @@ */ @file:Suppress("NOTHING_TO_INLINE", "unused") + package io.legado.app.lib.dialogs import android.annotation.SuppressLint @@ -52,7 +53,7 @@ interface AlertBuilder { @setparam:DrawableRes var iconResource: Int @Deprecated(NO_GETTER, level = ERROR) get - + var customTitle: View @Deprecated(NO_GETTER, level = ERROR) get @@ -62,18 +63,18 @@ interface AlertBuilder { var isCancelable: Boolean @Deprecated(NO_GETTER, level = ERROR) get - fun onCancelled(handler: (dialog: DialogInterface) -> Unit) + fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) + fun positiveButton(@StringRes buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)? = null) - fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) + fun negativeButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) + fun negativeButton(@StringRes buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)?=null) - fun positiveButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) - fun positiveButton(@StringRes buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) + fun neutralButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)? = null) + fun neutralButton(@StringRes buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)? = null) - fun negativeButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) - fun negativeButton(@StringRes buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) + fun onCancelled(handler: (dialog: DialogInterface) -> Unit) - fun neutralPressed(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) - fun neutralPressed(@StringRes buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) + fun onKeyPressed(handler: (dialog: DialogInterface, keyCode: Int, e: KeyEvent) -> Boolean) fun items(items: List, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) fun items(items: List, onItemSelected: (dialog: DialogInterface, item: T, index: Int) -> Unit) @@ -90,14 +91,14 @@ fun AlertBuilder<*>.customView(view: () -> View) { customView = view() } -inline fun AlertBuilder<*>.okButton(noinline handler: (dialog: DialogInterface) -> Unit) = +inline fun AlertBuilder<*>.okButton(noinline handler: ((dialog: DialogInterface) -> Unit)? = null) = positiveButton(android.R.string.ok, handler) -inline fun AlertBuilder<*>.cancelButton(noinline handler: (dialog: DialogInterface) -> Unit) = +inline fun AlertBuilder<*>.cancelButton(noinline handler: ((dialog: DialogInterface) -> Unit)? = null) = negativeButton(android.R.string.cancel, handler) -inline fun AlertBuilder<*>.yesButton(noinline handler: (dialog: DialogInterface) -> Unit) = +inline fun AlertBuilder<*>.yesButton(noinline handler: ((dialog: DialogInterface) -> Unit)? = null) = positiveButton(android.R.string.yes, handler) -inline fun AlertBuilder<*>.noButton(noinline handler: (dialog: DialogInterface) -> Unit) = +inline fun AlertBuilder<*>.noButton(noinline handler: ((dialog: DialogInterface) -> Unit)? = null) = negativeButton(android.R.string.no, handler) \ No newline at end of file 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 38e03d573..52711a17a 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 @@ -75,28 +75,28 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder Unit) { - builder.setPositiveButton(buttonText) { dialog, _ -> onClicked(dialog) } + override fun positiveButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)?) { + builder.setPositiveButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun positiveButton(buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) { - builder.setPositiveButton(buttonTextResource) { dialog, _ -> onClicked(dialog) } + override fun positiveButton(buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)?) { + builder.setPositiveButton(buttonTextResource) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun negativeButton(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) { - builder.setNegativeButton(buttonText) { dialog, _ -> onClicked(dialog) } + override fun negativeButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)?) { + builder.setNegativeButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun negativeButton(buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) { - builder.setNegativeButton(buttonTextResource) { dialog, _ -> onClicked(dialog) } + override fun negativeButton(buttonTextResource: Int, onClicked: ((dialog: DialogInterface) -> Unit)?) { + builder.setNegativeButton(buttonTextResource) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun neutralPressed(buttonText: String, onClicked: (dialog: DialogInterface) -> Unit) { - builder.setNeutralButton(buttonText) { dialog, _ -> onClicked(dialog) } + override fun neutralButton(buttonText: String, onClicked: ((dialog: DialogInterface) -> Unit)?) { + builder.setNeutralButton(buttonText) { dialog, _ -> onClicked?.invoke(dialog) } } - override fun neutralPressed(buttonTextResource: Int, onClicked: (dialog: DialogInterface) -> Unit) { - builder.setNeutralButton(buttonTextResource) { dialog, _ -> onClicked(dialog) } + 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) { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index ec4b22c5c..a0aa86e4e 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -128,7 +128,7 @@ class BookshelfFragment : VMBaseFragment(R.layout.fragment_b viewModel.saveBookGroup(editText?.text?.toString()) } - noButton { } + noButton() }.show().applyTint().requestInputMethod() }