mirror of
https://github.com/msfjarvis/compose-lobsters
synced 2025-08-14 21:07:04 +05:30
fix(android): dismiss existing snackbars when showing a new one
This commit is contained in:
parent
7d491de86c
commit
2bb71238bc
1 changed files with 12 additions and 4 deletions
|
@ -55,13 +55,13 @@ private fun ImportOption(
|
||||||
val importAction =
|
val importAction =
|
||||||
rememberLauncherForActivityResult(GetContent()) { uri ->
|
rememberLauncherForActivityResult(GetContent()) { uri ->
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
coroutineScope.launch { snackbarHostState.showSnackbar("No file selected") }
|
coroutineScope.launch { snackbarHostState.showSnackbarDismissing("No file selected") }
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
context.contentResolver.openInputStream(uri)?.use { stream ->
|
context.contentResolver.openInputStream(uri)?.use { stream ->
|
||||||
dataTransferRepository.importPosts(stream)
|
dataTransferRepository.importPosts(stream)
|
||||||
snackbarHostState.showSnackbar("Successfully imported posts")
|
snackbarHostState.showSnackbarDismissing("Successfully imported posts")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -84,13 +84,13 @@ private fun ExportOption(
|
||||||
val exportAction =
|
val exportAction =
|
||||||
rememberLauncherForActivityResult(CreateDocument(MIME_TYPE)) { uri ->
|
rememberLauncherForActivityResult(CreateDocument(MIME_TYPE)) { uri ->
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
coroutineScope.launch { snackbarHostState.showSnackbar("No file selected") }
|
coroutineScope.launch { snackbarHostState.showSnackbarDismissing("No file selected") }
|
||||||
return@rememberLauncherForActivityResult
|
return@rememberLauncherForActivityResult
|
||||||
}
|
}
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
context.contentResolver.openOutputStream(uri)?.use { stream ->
|
context.contentResolver.openOutputStream(uri)?.use { stream ->
|
||||||
dataTransferRepository.exportPosts(stream)
|
dataTransferRepository.exportPosts(stream)
|
||||||
snackbarHostState.showSnackbar("Successfully exported posts")
|
snackbarHostState.showSnackbarDismissing("Successfully exported posts")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -126,3 +126,11 @@ private fun SettingsActionItem(
|
||||||
modifier = modifier.clickable { onClick?.invoke() },
|
modifier = modifier.clickable { onClick?.invoke() },
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Shows a Snackbar but dismisses any existing ones first. */
|
||||||
|
private suspend fun SnackbarHostState.showSnackbarDismissing(
|
||||||
|
text: String,
|
||||||
|
) {
|
||||||
|
currentSnackbarData?.dismiss()
|
||||||
|
showSnackbar(text)
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue