-
-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate UI-specific state from view model
- Loading branch information
Showing
7 changed files
with
110 additions
and
43 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
23 changes: 23 additions & 0 deletions
23
app/src/main/java/app/grapheneos/camera/ui/composable/component/SnackBarMessageHandler.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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package app.grapheneos.camera.ui.composable.component | ||
|
||
import androidx.compose.material3.SnackbarHostState | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import app.grapheneos.camera.ktx.dismissSnackBarIfVisible | ||
import app.grapheneos.camera.ktx.showOrReplaceSnackbar | ||
import app.grapheneos.camera.ui.composable.model.NoDataSnackBarMessage | ||
import app.grapheneos.camera.ui.composable.model.SnackBarMessage | ||
|
||
@Composable | ||
fun SnackBarMessageHandler( | ||
snackBarHostState: SnackbarHostState, | ||
snackBarMessage: SnackBarMessage | ||
) { | ||
LaunchedEffect(snackBarMessage) { | ||
if (snackBarMessage == NoDataSnackBarMessage) { | ||
snackBarHostState.dismissSnackBarIfVisible() | ||
} else { | ||
snackBarHostState.showOrReplaceSnackbar(snackBarMessage.message) | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/app/grapheneos/camera/ui/composable/model/SnackBarMessage.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 |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package app.grapheneos.camera.ui.composable.model | ||
|
||
import java.util.UUID | ||
|
||
data class SnackBarMessage( | ||
val message: String, | ||
val id: UUID = UUID.randomUUID() | ||
) | ||
|
||
val NoDataSnackBarMessage = SnackBarMessage("") |
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