pull/32/head
Administrator 5 years ago
parent e2ec71be05
commit 52bd3a4731
  1. 27
      app/src/main/java/io/legado/app/lib/dialogs/AlertBuilder.kt
  2. 24
      app/src/main/java/io/legado/app/lib/dialogs/AndroidAlertBuilder.kt
  3. 2
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.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<out D : DialogInterface> {
@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<out D : DialogInterface> {
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<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit)
fun <T> items(items: List<T>, 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)

@ -75,28 +75,28 @@ internal class AndroidAlertBuilder(override val ctx: Context) : AlertBuilder<Ale
builder.setOnKeyListener(handler)
}
override fun positiveButton(buttonText: String, onClicked: (dialog: DialogInterface) -> 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<CharSequence>, onItemSelected: (dialog: DialogInterface, index: Int) -> Unit) {

@ -128,7 +128,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
viewModel.saveBookGroup(editText?.text?.toString())
}
noButton { }
noButton()
}.show().applyTint().requestInputMethod()
}

Loading…
Cancel
Save