pull/1284/head
parent
afd1a82259
commit
4066608c26
@ -1,67 +0,0 @@ |
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
|
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import androidx.fragment.app.Fragment |
||||
|
||||
typealias AlertBuilderFactory<D> = (Context) -> AlertBuilder<D> |
||||
|
||||
inline fun <D : DialogInterface> Fragment.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
title: String? = null, |
||||
message: String? = null, |
||||
noinline init: (AlertBuilder<D>.() -> Unit)? = null |
||||
) = activity?.alert(factory, title, message, init) |
||||
|
||||
fun <D : DialogInterface> Context.alert( |
||||
factory: AlertBuilderFactory<D>, |
||||
title: String? = null, |
||||
message: String? = null, |
||||
init: (AlertBuilder<D>.() -> Unit)? = null |
||||
): AlertBuilder<D> { |
||||
return factory(this).apply { |
||||
if (title != null) { |
||||
this.setTitle(title) |
||||
} |
||||
if (message != null) { |
||||
this.setMessage(message) |
||||
} |
||||
if (init != null) init() |
||||
} |
||||
} |
||||
|
||||
inline fun <D : DialogInterface> Fragment.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
noinline init: (AlertBuilder<D>.() -> Unit)? = null |
||||
) = requireActivity().alert(factory, titleResource, messageResource, init) |
||||
|
||||
fun <D : DialogInterface> Context.alert( |
||||
factory: AlertBuilderFactory<D>, |
||||
titleResource: Int? = null, |
||||
messageResource: Int? = null, |
||||
init: (AlertBuilder<D>.() -> Unit)? = null |
||||
): AlertBuilder<D> { |
||||
return factory(this).apply { |
||||
if (titleResource != null) { |
||||
this.setTitle(titleResource) |
||||
} |
||||
if (messageResource != null) { |
||||
this.setMessage(messageResource) |
||||
} |
||||
if (init != null) init() |
||||
} |
||||
} |
||||
|
||||
inline fun <D : DialogInterface> Fragment.alert( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
noinline init: AlertBuilder<D>.() -> Unit |
||||
) = requireActivity().alert(factory, init) |
||||
|
||||
fun <D : DialogInterface> Context.alert( |
||||
factory: AlertBuilderFactory<D>, |
||||
init: AlertBuilder<D>.() -> Unit |
||||
): AlertBuilder<D> = factory(this).apply { init() } |
@ -0,0 +1,17 @@ |
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.os.Parcelable |
||||
import kotlinx.parcelize.Parcelize |
||||
|
||||
@Suppress("unused") |
||||
@Parcelize |
||||
data class SelectItem( |
||||
val title: String, |
||||
val id: Int |
||||
) : Parcelable { |
||||
|
||||
override fun toString(): String { |
||||
return title |
||||
} |
||||
|
||||
} |
@ -1,29 +0,0 @@ |
||||
@file:Suppress("NOTHING_TO_INLINE", "unused") |
||||
|
||||
package io.legado.app.lib.dialogs |
||||
|
||||
import android.content.Context |
||||
import android.content.DialogInterface |
||||
import androidx.fragment.app.Fragment |
||||
|
||||
inline fun <D : DialogInterface> Fragment.selector( |
||||
noinline factory: AlertBuilderFactory<D>, |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
noinline onClick: (DialogInterface, CharSequence, Int) -> Unit |
||||
) = requireActivity().selector(factory, title, items, onClick) |
||||
|
||||
fun <D : DialogInterface> Context.selector( |
||||
factory: AlertBuilderFactory<D>, |
||||
title: CharSequence? = null, |
||||
items: List<CharSequence>, |
||||
onClick: (DialogInterface, CharSequence, Int) -> Unit |
||||
) { |
||||
with(factory(this)) { |
||||
if (title != null) { |
||||
this.setTitle(title) |
||||
} |
||||
items(items, onClick) |
||||
show() |
||||
} |
||||
} |
Loading…
Reference in new issue