-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #387 from Assocify-Team/sk/create-select-errors
Error messages in create and select association
- Loading branch information
Showing
6 changed files
with
113 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 45 additions & 41 deletions
86
app/src/main/java/com/github/se/assocify/ui/util/SnackbarSystem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,45 @@ | ||
package com.github.se.assocify.ui.util | ||
|
||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.SnackbarResult | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
/** A system to show snackbars in the app. */ | ||
class SnackbarSystem(private val snackbarHostState: SnackbarHostState) { | ||
/** | ||
* Shows a snackbar with the given message. | ||
* | ||
* Note : Persistent snackbars with no action will have a cross to dismiss them even if dismiss is | ||
* false | ||
* | ||
* @param message the message to show | ||
* @param actionLabel the label for the action button | ||
* @param actionHandler the handler for the action button | ||
* @param dismiss whether the snackbar should have a cross to dismiss it | ||
* @param persistent whether the snackbar should remain until explicitely dismissed (otherwise, | ||
* times out on its own) | ||
*/ | ||
fun showSnackbar( | ||
message: String, | ||
actionLabel: String? = null, | ||
actionHandler: (() -> Unit) = {}, | ||
dismiss: Boolean = false, | ||
persistent: Boolean = false, | ||
) { | ||
|
||
CoroutineScope(Dispatchers.Main).launch { | ||
val result = | ||
snackbarHostState.showSnackbar( | ||
message, actionLabel, dismiss || (persistent && actionLabel == null)) | ||
if (result == SnackbarResult.ActionPerformed) { | ||
actionHandler() | ||
} | ||
} | ||
} | ||
} | ||
package com.github.se.assocify.ui.util | ||
|
||
import androidx.compose.material3.SnackbarDuration | ||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.material3.SnackbarResult | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
|
||
/** A system to show snackbars in the app. */ | ||
class SnackbarSystem(private val snackbarHostState: SnackbarHostState) { | ||
/** | ||
* Shows a snackbar with the given message. | ||
* | ||
* Note : Persistent snackbars with no action will have a cross to dismiss them even if dismiss is | ||
* false | ||
* | ||
* @param message the message to show | ||
* @param actionLabel the label for the action button | ||
* @param actionHandler the handler for the action button | ||
* @param dismiss whether the snackbar should have a cross to dismiss it | ||
* @param persistent whether the snackbar should remain until explicitely dismissed (otherwise, | ||
* times out on its own) | ||
*/ | ||
fun showSnackbar( | ||
message: String, | ||
actionLabel: String? = null, | ||
actionHandler: (() -> Unit) = {}, | ||
dismiss: Boolean = false, | ||
persistent: Boolean = false, | ||
) { | ||
|
||
CoroutineScope(Dispatchers.Main).launch { | ||
val result = | ||
snackbarHostState.showSnackbar( | ||
message, | ||
actionLabel, | ||
dismiss || (persistent && actionLabel == null), | ||
if (persistent) SnackbarDuration.Indefinite else SnackbarDuration.Short) | ||
if (result == SnackbarResult.ActionPerformed) { | ||
actionHandler() | ||
} | ||
} | ||
} | ||
} |