#3673 Removed redundant snack function

This commit is contained in:
Sagar 2024-01-19 09:08:16 +00:00
parent 59dd343a24
commit c85bac1bd4

View File

@ -25,33 +25,19 @@ import androidx.annotation.ColorInt
import com.google.android.material.snackbar.BaseTransientBottomBar import com.google.android.material.snackbar.BaseTransientBottomBar
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
@SuppressLint("ShowToast")
fun View.snack(
stringId: Int,
actionStringId: Int? = null,
actionClick: (() -> Unit)? = null,
) {
Snackbar.make(
this, stringId, Snackbar.LENGTH_LONG
).apply {
actionStringId?.let { setAction(it) { actionClick?.invoke() } }
show()
}
}
@SuppressLint("ShowToast") @SuppressLint("ShowToast")
fun View.snack( fun View.snack(
stringId: Int, stringId: Int,
anchor: View? = null, anchor: View? = null,
actionStringId: Int? = null, actionStringId: Int? = null,
actionClick: (() -> Unit)? = null, actionClick: (() -> Unit)? = null,
@ColorInt actionTextColor: Int = Color.WHITE @ColorInt actionTextColor: Int? = null
) { ) {
Snackbar.make( Snackbar.make(
this, stringId, Snackbar.LENGTH_LONG this, stringId, Snackbar.LENGTH_LONG
).apply { ).apply {
actionStringId?.let { setAction(it) { actionClick?.invoke() } } actionStringId?.let { setAction(it) { actionClick?.invoke() } }
setActionTextColor(actionTextColor) actionTextColor?.let(::setActionTextColor)
anchor?.let { anchor?.let {
anchorView = anchor anchorView = anchor
addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() { addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
@ -69,13 +55,13 @@ fun View.snack(
anchor: View, anchor: View,
actionStringId: Int? = null, actionStringId: Int? = null,
actionClick: (() -> Unit)? = null, actionClick: (() -> Unit)? = null,
@ColorInt actionTextColor: Int = Color.WHITE @ColorInt actionTextColor: Int? = null
) { ) {
Snackbar.make( Snackbar.make(
this, message, Snackbar.LENGTH_LONG this, message, Snackbar.LENGTH_LONG
).apply { ).apply {
actionStringId?.let { setAction(it) { actionClick?.invoke() } } actionStringId?.let { setAction(it) { actionClick?.invoke() } }
setActionTextColor(actionTextColor) actionTextColor?.let(::setActionTextColor)
anchorView = anchor anchorView = anchor
addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() { addCallback(object : BaseTransientBottomBar.BaseCallback<Snackbar>() {
override fun onDismissed(transientBottomBar: Snackbar?, event: Int) { override fun onDismissed(transientBottomBar: Snackbar?, event: Int) {