mirror of
https://github.com/gedoor/legado.git
synced 2024-09-01 09:34:25 +08:00
commit
c69766abe2
53
app/src/main/java/io/legado/app/utils/AnkoExtensions.kt
Normal file
53
app/src/main/java/io/legado/app/utils/AnkoExtensions.kt
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package io.legado.app.utils
|
||||||
|
|
||||||
|
import android.view.View
|
||||||
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
|
import com.google.android.material.snackbar.Snackbar
|
||||||
|
import org.jetbrains.anko.dip
|
||||||
|
import org.jetbrains.anko.longToast
|
||||||
|
import org.jetbrains.anko.toast
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the Snackbar with the [Snackbar.LENGTH_SHORT] duration.
|
||||||
|
*
|
||||||
|
* @param message the message text resource.
|
||||||
|
*/
|
||||||
|
@JvmName("snackbar2")
|
||||||
|
fun View.snackbar(@StringRes message: Int) = Snackbar
|
||||||
|
.make(this, message, Snackbar.LENGTH_SHORT)
|
||||||
|
.apply { show() }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration.
|
||||||
|
*
|
||||||
|
* @param message the message text resource.
|
||||||
|
*/
|
||||||
|
@JvmName("longSnackbar2")
|
||||||
|
fun View.longSnackbar(@StringRes message: Int) = Snackbar
|
||||||
|
.make(this, message, Snackbar.LENGTH_LONG)
|
||||||
|
.apply { show() }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display Snackbar with the [Snackbar.LENGTH_LONG] duration.
|
||||||
|
*
|
||||||
|
* @param message the message text resource.
|
||||||
|
*/
|
||||||
|
@JvmName("longSnackbar2")
|
||||||
|
fun View.longSnackbar(@StringRes message: Int, @StringRes actionText: Int, action: (View) -> Unit) = Snackbar
|
||||||
|
.make(this, message, Snackbar.LENGTH_LONG)
|
||||||
|
.setAction(actionText, action)
|
||||||
|
.apply { show() }
|
||||||
|
|
||||||
|
fun Fragment.toast(textResource: Int) = requireActivity().toast(textResource)
|
||||||
|
|
||||||
|
fun Fragment.toast(text: CharSequence) = requireActivity().toast(text)
|
||||||
|
|
||||||
|
fun Fragment.longToast(textResource: Int) = requireActivity().longToast(textResource)
|
||||||
|
|
||||||
|
fun Fragment.longToast(text: CharSequence) = requireActivity().longToast(text)
|
||||||
|
|
||||||
|
fun Fragment.dip(value: Int): Int = requireActivity().dip(value)
|
||||||
|
|
||||||
|
fun Fragment.dip(value: Float): Int = requireActivity().dip(value)
|
Loading…
Reference in New Issue
Block a user