From dc552caf9037901da5c19f38ab370203b591dac9 Mon Sep 17 00:00:00 2001 From: Kevin Schildhorn Date: Sat, 16 Dec 2023 17:06:57 -0500 Subject: [PATCH 1/2] Creating Foto Dialog --- .../ui/compose/CommonPreviews.kt | 26 +++++++-- .../fotopresenter/ui/atoms/FotoColors.kt | 2 +- .../fotopresenter/ui/atoms/FotoTypography.kt | 6 +-- .../ui/screens/common/CommonAtoms.kt | 4 +- .../common/composables/ConfirmationDialog.kt | 53 ++++--------------- .../screens/common/composables/FotoDIalog.kt | 52 ++++++++++++++++++ .../ui/screens/directory/DirectoryScreen.kt | 6 +-- .../login/composables/LoginScreenForm.kt | 3 +- .../playlist/composables/PlaylistColumn.kt | 6 +-- .../composables/TextConfirmationDialog.kt | 37 +++++++++++++ 10 files changed, 132 insertions(+), 63 deletions(-) create mode 100644 shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt create mode 100644 shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt diff --git a/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt b/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt index 2929d8a8..4931bfce 100644 --- a/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt +++ b/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt @@ -9,6 +9,7 @@ import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ActionShe import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ButtonState import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ConfirmationDialog import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.PrimaryTextButton +import com.kevinschildhorn.fotopresenter.ui.screens.playlist.composables.TextConfirmationDialog @Preview @Composable @@ -37,14 +38,29 @@ fun ActionSheetPreview() { @Preview @Composable -fun ConfirmationDialogPreview(){ +fun ConfirmationDialogPreview() { ConfirmationDialog( + "Hello", + "World", { - },{ + }, + { }, - "Hello", - "World" ) -} \ No newline at end of file +} + +@Preview +@Composable +fun TextConfirmationDialogPreview() { + TextConfirmationDialog( + { + + }, + { + + }, + ) +} + diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoColors.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoColors.kt index a9e7dd87..06208c03 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoColors.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoColors.kt @@ -11,7 +11,7 @@ object FotoColors { val secondary = AtomikColor(0xFFD383) val secondaryText = AtomikColor(0xC1872E) val backgroundText = AtomikColor(0x25231F) - val surfaceText = AtomikColor(0xFFA500) + val surfaceText = AtomikColor(0xC2882E) val errorText = AtomikColor(0x9E1F1F) val disabled = AtomikColor(0xE0E0E0) diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoTypography.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoTypography.kt index f1a010f8..796af466 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoTypography.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/atoms/FotoTypography.kt @@ -12,11 +12,11 @@ object FotoTypography { val h1 = AtomikTypography(size = 96, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) val h2 = - AtomikTypography(size = 60, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) - val h3 = AtomikTypography(size = 48, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) + val h3 = + AtomikTypography(size = 36, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) val h4 = - AtomikTypography(size = 34, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) + AtomikTypography(size = 24, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) val subtitle = AtomikTypography(size = 16, weight = AtomikTypographyWeight.NORMAL, font = fontregularMoko) val button = diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/CommonAtoms.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/CommonAtoms.kt index 017f1b89..48ea6ff7 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/CommonAtoms.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/CommonAtoms.kt @@ -13,13 +13,13 @@ object CommonAtoms { ) val dialogMessage: SimpleTextAtom = SimpleTextAtom( - textColor = FotoColors.secondaryText, + textColor = FotoColors.surfaceText, typography = FotoTypography.body, fontFamily = null, ) val dialogButton: SimpleTextAtom = SimpleTextAtom( - textColor = FotoColors.primaryText, + textColor = FotoColors.surfaceText, typography = FotoTypography.button, fontFamily = null, ) diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/ConfirmationDialog.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/ConfirmationDialog.kt index 22c044da..0d098354 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/ConfirmationDialog.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/ConfirmationDialog.kt @@ -1,55 +1,20 @@ package com.kevinschildhorn.fotopresenter.ui.screens.common.composables -import androidx.compose.foundation.background -import androidx.compose.foundation.shape.RoundedCornerShape -import androidx.compose.material.AlertDialog -import androidx.compose.material.Text -import androidx.compose.material.TextButton import androidx.compose.runtime.Composable -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clip -import androidx.compose.ui.unit.dp -import com.kevinschildhorn.atomik.color.base.composeColor -import com.kevinschildhorn.fotopresenter.ui.atoms.FotoColors import com.kevinschildhorn.fotopresenter.ui.screens.common.CommonAtoms -import java.beans.Visibility @Composable fun ConfirmationDialog( - onDismissRequest: () -> Unit, - onConfirmation: () -> Unit, dialogTitle: String, dialogText: String, + onDismissRequest: () -> Unit, + onConfirmation: () -> Unit, ) { - AlertDialog( - modifier = Modifier.clip(RoundedCornerShape(10.dp)), - backgroundColor = FotoColors.secondary.composeColor, - title = { - AtomikText(text = dialogTitle, atom = CommonAtoms.dialogTitle) - }, - text = { - AtomikText(text = dialogText, atom = CommonAtoms.dialogMessage) - }, - onDismissRequest = { - onDismissRequest() - }, - confirmButton = { - TextButton( - onClick = { - onConfirmation() - } - ) { - AtomikText("Confirm", atom = CommonAtoms.dialogButton) - } - }, - dismissButton = { - TextButton( - onClick = { - onDismissRequest() - } - ) { - AtomikText("Dismiss", atom = CommonAtoms.dialogButton) - } - } - ) + FotoDialog( + dialogTitle = dialogTitle, + onDismissRequest = onDismissRequest, + onConfirmation = onConfirmation, + ) { + AtomikText(text = dialogText, atom = CommonAtoms.dialogMessage) + } } diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt new file mode 100644 index 00000000..b64762b1 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt @@ -0,0 +1,52 @@ +package com.kevinschildhorn.fotopresenter.ui.screens.common.composables + +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.AlertDialog +import androidx.compose.material.Button +import androidx.compose.material.ButtonDefaults +import androidx.compose.material.TextButton +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.unit.dp +import com.kevinschildhorn.atomik.color.base.composeColor +import com.kevinschildhorn.fotopresenter.ui.atoms.FotoColors +import com.kevinschildhorn.fotopresenter.ui.screens.common.CommonAtoms + +@Composable +fun FotoDialog( + dialogTitle: String, + onDismissRequest: () -> Unit, + onConfirmation: () -> Unit, + content: @Composable (() -> Unit)?, +) { + AlertDialog( + modifier = Modifier.clip(RoundedCornerShape(10.dp)), + backgroundColor = FotoColors.surface.composeColor, + title = { + AtomikText( + text = dialogTitle, + atom = CommonAtoms.dialogTitle + ) + }, + text = content, + onDismissRequest = { + onDismissRequest() + }, + confirmButton = { + PrimaryTextButton("Confirm"){ + onConfirmation() + } + }, + dismissButton = { + TextButton( + onClick = { + onDismissRequest() + } + ) { + AtomikText("Cancel", atom = CommonAtoms.dialogButton) + } + } + ) +} \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/directory/DirectoryScreen.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/directory/DirectoryScreen.kt index 8143c719..8d744447 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/directory/DirectoryScreen.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/directory/DirectoryScreen.kt @@ -168,8 +168,10 @@ fun DirectoryScreen( }, onPlaylists = onShowPlaylists, ) - if(overlayVisible == DirectoryOverlay.LOGOUT_CONFIRMATION) { + if (overlayVisible == DirectoryOverlay.LOGOUT_CONFIRMATION) { ConfirmationDialog( + "Log Out", + "Are you sure you want to logout?", onDismissRequest = { overlayVisible = DirectoryOverlay.NONE }, @@ -177,8 +179,6 @@ fun DirectoryScreen( viewModel.logout() overlayVisible = DirectoryOverlay.NONE }, - "Log Out", - "Are you sure you want to logout?" ) } } diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/login/composables/LoginScreenForm.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/login/composables/LoginScreenForm.kt index 2a31cb78..a964d852 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/login/composables/LoginScreenForm.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/login/composables/LoginScreenForm.kt @@ -8,6 +8,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.unit.dp import com.kevinschildhorn.fotopresenter.data.State import com.kevinschildhorn.fotopresenter.extension.required +import com.kevinschildhorn.fotopresenter.ui.UiState import com.kevinschildhorn.fotopresenter.ui.atoms.Padding import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ErrorView import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.FormColumn @@ -25,7 +26,7 @@ fun LoginScreenForm( loginButtonClicked: () -> Unit, ) { Column(modifier = Modifier.padding(horizontal = 20.dp)) { - (uiState.state as? State.ERROR)?.let { + (uiState.state as? UiState.ERROR)?.let { ErrorView( "Error Occurred! ${it.message}", ) diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/PlaylistColumn.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/PlaylistColumn.kt index 38a3e11c..34e72a33 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/PlaylistColumn.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/PlaylistColumn.kt @@ -13,6 +13,7 @@ import androidx.compose.ui.Modifier import com.kevinschildhorn.fotopresenter.ui.atoms.Padding import androidx.compose.foundation.lazy.items import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.Divider import androidx.compose.material.Text import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color @@ -59,10 +60,7 @@ fun PlaylistColumn( onDelete(it.id) } ) - Spacer( - Modifier.fillMaxWidth().height(1.dp) - .background(FotoColors.secondaryText.composeColor) - ) + Divider(startIndent = 0.dp, thickness = 1.dp, color = FotoColors.secondaryText.composeColor) } } PlaylistScreenCreateRow(onClick = onCreate) diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt new file mode 100644 index 00000000..53dc4799 --- /dev/null +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt @@ -0,0 +1,37 @@ +package com.kevinschildhorn.fotopresenter.ui.screens.playlist.composables + +import androidx.compose.foundation.layout.padding +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import androidx.compose.ui.Modifier +import com.kevinschildhorn.fotopresenter.ui.atoms.Padding +import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.FotoDialog +import com.kevinschildhorn.fotopresenter.ui.screens.login.composables.LoginTextField + +@Composable +fun TextConfirmationDialog( + onDismissRequest: () -> Unit, + onConfirmation: (String) -> Unit, +) { + var enteredValue:String by remember { mutableStateOf("") } + + FotoDialog( + dialogTitle = "Playlist Name", + onDismissRequest = onDismissRequest, + onConfirmation = { + onConfirmation(enteredValue) + }, + ) { + LoginTextField( + enteredValue, + onValueChange = { + enteredValue = it + }, + placeholder = "Name", + modifier = Modifier.padding(top = Padding.STANDARD.dp) + ) + } +} \ No newline at end of file From e0d19230f3635c813499e5eda7b5a8572469b30d Mon Sep 17 00:00:00 2001 From: Kevin Schildhorn Date: Sat, 16 Dec 2023 17:50:37 -0500 Subject: [PATCH 2/2] Adding creating playlists, only names for now --- .../ui/compose/CommonPreviews.kt | 4 +- .../data/datasources/PlaylistDataSource.kt | 4 +- .../data/repositories/PlaylistRepository.kt | 4 +- .../screens/common/composables/FotoDIalog.kt | 78 ++++++++++++------- .../ui/screens/playlist/PlaylistScreen.kt | 44 ++++++++++- .../screens/playlist/PlaylistScreenState.kt | 2 +- .../ui/screens/playlist/PlaylistViewModel.kt | 17 +++- ...nfirmationDialog.kt => TextEntryDialog.kt} | 2 +- .../kevinschildhorn/fotopresenter/Playlist.sq | 5 ++ .../datasources/PlaylistDataSourceTest.kt | 6 +- 10 files changed, 125 insertions(+), 41 deletions(-) rename shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/{TextConfirmationDialog.kt => TextEntryDialog.kt} (97%) diff --git a/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt b/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt index 4931bfce..87e6c7bc 100644 --- a/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt +++ b/shared/src/androidMain/kotlin/com/kevinschildhorn/fotopresenter/ui/compose/CommonPreviews.kt @@ -9,7 +9,7 @@ import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ActionShe import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ButtonState import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ConfirmationDialog import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.PrimaryTextButton -import com.kevinschildhorn.fotopresenter.ui.screens.playlist.composables.TextConfirmationDialog +import com.kevinschildhorn.fotopresenter.ui.screens.playlist.composables.TextEntryDialog @Preview @Composable @@ -54,7 +54,7 @@ fun ConfirmationDialogPreview() { @Preview @Composable fun TextConfirmationDialogPreview() { - TextConfirmationDialog( + TextEntryDialog( { }, diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSource.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSource.kt index 21cd4929..b27b1023 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSource.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSource.kt @@ -74,9 +74,9 @@ class PlaylistDataSource( } } - fun deletePlaylistByName(name: String): Boolean { + fun deletePlaylist(id: Long): Boolean { return try { - val playlist = database.playlistQueries.selectPlaylistByName(name).executeAsOne() + val playlist = database.playlistQueries.selectPlaylistById(id).executeAsOne() database.playlistQueries.deletePlaylist(playlist.name) database.imageDirectoryQueries.deletePlaylist(playlist.id) true diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/repositories/PlaylistRepository.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/repositories/PlaylistRepository.kt index f45f19a1..63a50b3d 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/repositories/PlaylistRepository.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/data/repositories/PlaylistRepository.kt @@ -24,6 +24,6 @@ class PlaylistRepository( fun getPlaylistImage(playlistId: Long, directoryPath: String): PlaylistImage? = playlistDataSource.getPlaylistImage(playlistId, directoryPath) - fun deletePlaylistByName(name: String): Boolean = - playlistDataSource.deletePlaylistByName(name) + fun deletePlaylist(id: Long): Boolean = + playlistDataSource.deletePlaylist(id) } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt index b64762b1..ee51ddf8 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/common/composables/FotoDIalog.kt @@ -1,17 +1,29 @@ package com.kevinschildhorn.fotopresenter.ui.screens.common.composables +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.ColumnScope +import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer +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.shape.RoundedCornerShape import androidx.compose.material.AlertDialog import androidx.compose.material.Button import androidx.compose.material.ButtonDefaults +import androidx.compose.material.Card import androidx.compose.material.TextButton import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.unit.dp +import androidx.compose.ui.window.Dialog import com.kevinschildhorn.atomik.color.base.composeColor import com.kevinschildhorn.fotopresenter.ui.atoms.FotoColors +import com.kevinschildhorn.fotopresenter.ui.atoms.Padding import com.kevinschildhorn.fotopresenter.ui.screens.common.CommonAtoms @Composable @@ -19,34 +31,48 @@ fun FotoDialog( dialogTitle: String, onDismissRequest: () -> Unit, onConfirmation: () -> Unit, - content: @Composable (() -> Unit)?, + content: @Composable ColumnScope.() -> Unit, ) { - AlertDialog( - modifier = Modifier.clip(RoundedCornerShape(10.dp)), - backgroundColor = FotoColors.surface.composeColor, - title = { - AtomikText( - text = dialogTitle, - atom = CommonAtoms.dialogTitle - ) - }, - text = content, - onDismissRequest = { - onDismissRequest() - }, - confirmButton = { - PrimaryTextButton("Confirm"){ - onConfirmation() - } - }, - dismissButton = { - TextButton( - onClick = { - onDismissRequest() - } + Dialog(onDismissRequest = { onDismissRequest() }) { + // Draw a rectangle shape with rounded corners inside the dialog + Card( + modifier = Modifier + .fillMaxWidth() + .padding(16.dp), + shape = RoundedCornerShape(16.dp), + ) { + Column( + modifier = Modifier + .fillMaxWidth().padding(Padding.STANDARD.dp), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.Start, ) { - AtomikText("Cancel", atom = CommonAtoms.dialogButton) + AtomikText( + text = dialogTitle, + atom = CommonAtoms.dialogTitle, + ) + Spacer(Modifier.size(Padding.MEDIUM.dp)) + content() + Row( + modifier = Modifier + .fillMaxWidth() + .padding(top = Padding.SMALL.dp), + horizontalArrangement = Arrangement.End, + verticalAlignment = Alignment.CenterVertically + ) { + TextButton( + onClick = { + onDismissRequest() + }, + modifier = Modifier.padding(Padding.SMALL.dp) + ) { + AtomikText("Cancel", atom = CommonAtoms.dialogButton) + } + PrimaryTextButton("Confirm") { + onConfirmation() + } + } } } - ) + } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreen.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreen.kt index 76bb8530..12cc70ad 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreen.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreen.kt @@ -5,14 +5,27 @@ import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.setValue +import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.ConfirmationDialog +import com.kevinschildhorn.fotopresenter.ui.screens.directory.DirectoryOverlay import com.kevinschildhorn.fotopresenter.ui.screens.playlist.composables.PlaylistOverlay +import com.kevinschildhorn.fotopresenter.ui.screens.playlist.composables.TextEntryDialog +enum class PlaylistDialog{ + NONE, + CREATE, + DELETE, + EDIT +} @Composable fun PlaylistScreen( viewModel: PlaylistViewModel, onLoginSuccess: () -> Unit, ) { val uiState by viewModel.uiState.collectAsState() + var dialogOpen by remember { mutableStateOf(PlaylistDialog.NONE) } LaunchedEffect(Unit) { viewModel.refreshPlaylists() @@ -23,10 +36,37 @@ fun PlaylistScreen( onClick = { }, onDelete = { - + dialogOpen = PlaylistDialog.DELETE + viewModel.setSelectedPlaylist(it) }, onEdit = { - + dialogOpen = PlaylistDialog.EDIT + viewModel.setSelectedPlaylist(it) }, onCreate = { + dialogOpen = PlaylistDialog.CREATE + } + ) + if (dialogOpen == PlaylistDialog.CREATE) { + TextEntryDialog({ + dialogOpen = PlaylistDialog.NONE + }, { + viewModel.createPlaylist(it) + dialogOpen = PlaylistDialog.NONE }) + } + if (dialogOpen == PlaylistDialog.DELETE) { + ConfirmationDialog( + "Delete Playlist", + "Are you sure you want to delete this playlist?", + onDismissRequest = { + dialogOpen = PlaylistDialog.NONE + viewModel.clearSelectedPlaylist() + }, + onConfirmation = { + viewModel.deletePlaylist() + dialogOpen = PlaylistDialog.NONE + viewModel.clearSelectedPlaylist() + }, + ) + } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreenState.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreenState.kt index d5fa1956..89a7a16e 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreenState.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistScreenState.kt @@ -6,6 +6,6 @@ import com.kevinschildhorn.fotopresenter.ui.screens.common.ScreenState data class PlaylistScreenState( val playlists: List = emptyList(), - val selectedId: Long = 0L, + val selectedId: Long? = null, override val state: UiState = UiState.IDLE, ) : ScreenState \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistViewModel.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistViewModel.kt index 66fc9d02..06acb56f 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistViewModel.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/PlaylistViewModel.kt @@ -26,11 +26,24 @@ class PlaylistViewModel( _uiState.update { it.copy(playlists = allPlaylists) } } + fun setSelectedPlaylist(id:Long){ + _uiState.update { it.copy(selectedId = id) } + } + + fun clearSelectedPlaylist(){ + _uiState.update { it.copy(selectedId = null) } + } + fun createPlaylist(name: String){ playlistRepository.createPlaylist(name) + refreshPlaylists() } - fun deletePlaylist(name: String){ - playlistRepository.deletePlaylistByName(name) + fun deletePlaylist(){ + _uiState.value.selectedId?.let { + playlistRepository.deletePlaylist(it) + } + refreshPlaylists() + clearSelectedPlaylist() } } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextEntryDialog.kt similarity index 97% rename from shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt rename to shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextEntryDialog.kt index 53dc4799..d11dc7b4 100644 --- a/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextConfirmationDialog.kt +++ b/shared/src/commonMain/kotlin/com/kevinschildhorn/fotopresenter/ui/screens/playlist/composables/TextEntryDialog.kt @@ -12,7 +12,7 @@ import com.kevinschildhorn.fotopresenter.ui.screens.common.composables.FotoDialo import com.kevinschildhorn.fotopresenter.ui.screens.login.composables.LoginTextField @Composable -fun TextConfirmationDialog( +fun TextEntryDialog( onDismissRequest: () -> Unit, onConfirmation: (String) -> Unit, ) { diff --git a/shared/src/commonMain/sqldelight/com/kevinschildhorn/fotopresenter/Playlist.sq b/shared/src/commonMain/sqldelight/com/kevinschildhorn/fotopresenter/Playlist.sq index 95dac8bc..bd86bc76 100644 --- a/shared/src/commonMain/sqldelight/com/kevinschildhorn/fotopresenter/Playlist.sq +++ b/shared/src/commonMain/sqldelight/com/kevinschildhorn/fotopresenter/Playlist.sq @@ -12,6 +12,11 @@ SELECT * FROM Playlist WHERE name = ?; +selectPlaylistById: +SELECT * +FROM Playlist +WHERE id = ?; + insertPlaylist: INSERT INTO Playlist(name) VALUES (?); diff --git a/shared/src/commonTest/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSourceTest.kt b/shared/src/commonTest/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSourceTest.kt index 2392b0ad..cff7320a 100644 --- a/shared/src/commonTest/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSourceTest.kt +++ b/shared/src/commonTest/kotlin/com/kevinschildhorn/fotopresenter/data/datasources/PlaylistDataSourceTest.kt @@ -150,15 +150,15 @@ class PlaylistDataSourceTest { val newPlaylist = dataSource.getPlaylistByName(playlistName) assertNotNull(newPlaylist) - val image = dataSource.getPlaylistImage(playlist?.id ?: 0L, imageDirectory.details.fullPath) + val image = dataSource.getPlaylistImage(playlist.id, imageDirectory.details.fullPath) assertNotNull(image) - val result = dataSource.deletePlaylistByName(playlistName) + val result = dataSource.deletePlaylist(playlist.id) assertTrue(result) val deletedPlaylist = dataSource.getPlaylistByName(playlistName) assertNull(deletedPlaylist) - val deletedImage = dataSource.getPlaylistImage(playlist?.id ?: 0L, imageDirectory.details.fullPath) + val deletedImage = dataSource.getPlaylistImage(playlist.id, imageDirectory.details.fullPath) assertNull(deletedImage) }