Add support for passing UiText to showSnackbar

This commit is contained in:
Luna712 2024-07-19 10:24:23 -06:00 committed by GitHub
parent c861cf9e42
commit 0319557683
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 20 additions and 6 deletions

View file

@ -1230,9 +1230,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener, BiometricCa
this@MainActivity,
R.string.jsdelivr_enabled,
Snackbar.LENGTH_LONG,
getString(R.string.revert)) {
setKey(getString(R.string.jsdelivr_proxy_key), false)
}
R.string.revert
) { setKey(getString(R.string.jsdelivr_proxy_key), false) }
}
}
}

View file

@ -8,6 +8,7 @@ import com.google.android.material.snackbar.Snackbar
import com.lagradost.api.Log
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.ui.result.UiText
import com.lagradost.cloudstream3.utils.UIHelper.colorFromAttribute
object SnackbarHelper {
@ -18,13 +19,27 @@ object SnackbarHelper {
@MainThread
fun showSnackbar(
act: Activity?,
@StringRes message: Int,
message: UiText,
duration: Int = Snackbar.LENGTH_SHORT,
actionText: String? = null,
actionText: UiText? = null,
actionCallback: (() -> Unit)? = null
) {
if (act == null) return
showSnackbar(act, act.getString(message), duration, actionText, actionCallback)
showSnackbar(act, message.asString(act), duration,
actionText?.asString(act), actionCallback)
}
@MainThread
fun showSnackbar(
act: Activity?,
@StringRes message: Int,
duration: Int = Snackbar.LENGTH_SHORT,
@StringRes actionText: Int? = null,
actionCallback: (() -> Unit)? = null
) {
if (act == null) return
showSnackbar(act, act.getString(message), duration,
actionText?.let { act.getString(it) }, actionCallback)
}
@MainThread