Merge pull request #7 from gedoor/atbest

Added anko extensions
This commit is contained in:
atbest 2019-05-22 04:17:32 -04:00 committed by GitHub
commit c69766abe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View 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)