Simplified snackbar
This commit is contained in:
1 parent
1338ec8e64
commit
7ccac9eb2d
4 files changed
+41
-19
No files matched your search
@@ -1,5 +1,7 @@
|
||||
package com.v2ray.ang.compose
|
||||
|
||||
import android.content.Context
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
@@ -7,7 +9,6 @@ import androidx.compose.foundation.layout.BoxWithConstraints
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
@@ -91,11 +92,7 @@ class AppSnackbarController(
|
||||
val hostState: SnackbarHostState,
|
||||
private val scope: CoroutineScope,
|
||||
) {
|
||||
fun show(
|
||||
message: CharSequence,
|
||||
type: ToastType = ToastType.NORMAL,
|
||||
long: Boolean = false,
|
||||
) {
|
||||
fun show(message: CharSequence, type: ToastType = ToastType.NORMAL, long: Boolean = false, ) {
|
||||
scope.launch {
|
||||
hostState.currentSnackbarData?.dismiss()
|
||||
hostState.showSnackbar(
|
||||
@@ -106,6 +103,33 @@ class AppSnackbarController(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fun showInfo(context: Context, @StringRes messageRes: Int, long: Boolean = false, ) {
|
||||
show(context.getString(messageRes), ToastType.NORMAL, long)
|
||||
}
|
||||
|
||||
|
||||
fun showInfo(message: CharSequence, long: Boolean = false, ) {
|
||||
show(message, ToastType.NORMAL, long)
|
||||
}
|
||||
|
||||
|
||||
fun showSuccess(context: Context, @StringRes messageRes: Int, long: Boolean = false, ) {
|
||||
show(context.getString(messageRes), ToastType.SUCCESS, long)
|
||||
}
|
||||
|
||||
|
||||
fun showSuccess(message: CharSequence, long: Boolean = false, ) {
|
||||
show(message, ToastType.SUCCESS, long)
|
||||
}
|
||||
|
||||
fun showError(context: Context, @StringRes messageRes: Int, long: Boolean = false, ) {
|
||||
show(context.getString(messageRes), ToastType.ERROR, long)
|
||||
}
|
||||
|
||||
fun showError(message: CharSequence, long: Boolean = false, ) {
|
||||
show(message, ToastType.ERROR, long)
|
||||
}
|
||||
}
|
||||
|
||||
val LocalAppSnackbar = staticCompositionLocalOf<AppSnackbarController> {
|
||||
|
||||
@@ -71,7 +71,7 @@ fun CheckUpdateScreen(onBackClick: () -> Unit) {
|
||||
val versionText = "v${BuildConfig.VERSION_NAME} (${CoreNativeManager.getLibVersion()})"
|
||||
|
||||
fun checkForUpdates(includePreRelease: Boolean) {
|
||||
snackbar.show(context.getString(R.string.update_checking_for_update))
|
||||
snackbar.showInfo(context, (R.string.update_checking_for_update))
|
||||
isLoading = true
|
||||
scope.launch {
|
||||
try {
|
||||
@@ -80,17 +80,15 @@ fun CheckUpdateScreen(onBackClick: () -> Unit) {
|
||||
updateResult = result
|
||||
showUpdateDialog = true
|
||||
} else {
|
||||
snackbar.show(
|
||||
message = context.getString(R.string.update_already_latest_version),
|
||||
type = ToastType.SUCCESS
|
||||
)
|
||||
snackbar.showSuccess(context, R.string.update_already_latest_version)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
LogUtil.e(AppConfig.TAG, "Failed to check for updates: ${e.message}")
|
||||
snackbar.show(
|
||||
message = e.message ?: context.getString(R.string.toast_failure),
|
||||
type = ToastType.ERROR
|
||||
)
|
||||
if (e.message == null) {
|
||||
snackbar.showError(context, R.string.toast_failure)
|
||||
} else {
|
||||
snackbar.showError(e.message.orEmpty())
|
||||
}
|
||||
} finally {
|
||||
isLoading = false
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ fun LogcatScreen(
|
||||
|
||||
val snackbar = LocalAppSnackbar.current
|
||||
LaunchedEffect(Unit) {
|
||||
snackbar.show(context.getString(R.string.pull_down_to_refresh))
|
||||
snackbar.showInfo(context,R.string.pull_down_to_refresh)
|
||||
}
|
||||
val listState = rememberLazyListState()
|
||||
|
||||
@@ -163,7 +163,7 @@ fun LogcatScreen(
|
||||
if (!showSearch) {
|
||||
IconButton(onClick = { showSearch = true }) {
|
||||
Icon(
|
||||
painterResource(R.drawable.ic_outline_filter_alt_24),
|
||||
painterResource(R.drawable.ic_search_24dp),
|
||||
contentDescription = "filter"
|
||||
)
|
||||
}
|
||||
@@ -179,7 +179,7 @@ fun LogcatScreen(
|
||||
IconButton(onClick = {
|
||||
val all = viewModel.filteredLogs.value.joinToString("\n")
|
||||
Utils.setClipboard(context, all)
|
||||
context.toast(context.getString(R.string.toast_success))
|
||||
snackbar.showInfo(context,R.string.toast_success)
|
||||
}) {
|
||||
Icon(
|
||||
painterResource(R.drawable.ic_copy),
|
||||
|
||||
@@ -1148,7 +1148,7 @@ fun MainScreen(
|
||||
if (!showSearch) {
|
||||
IconButton(onClick = { showSearch = true }) {
|
||||
Icon(
|
||||
painterResource(R.drawable.ic_outline_filter_alt_24),
|
||||
painterResource(R.drawable.ic_search_24dp),
|
||||
contentDescription = "filter"
|
||||
)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user