Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create playlist #42

Merged
merged 2 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.TextEntryDialog

@Preview
@Composable
Expand Down Expand Up @@ -37,14 +38,29 @@ fun ActionSheetPreview() {

@Preview
@Composable
fun ConfirmationDialogPreview(){
fun ConfirmationDialogPreview() {
ConfirmationDialog(
"Hello",
"World",
{

},{
},
{

},
"Hello",
"World"
)
}
}

@Preview
@Composable
fun TextConfirmationDialogPreview() {
TextEntryDialog(
{

},
{

},
)
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
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
fun FotoDialog(
dialogTitle: String,
onDismissRequest: () -> Unit,
onConfirmation: () -> Unit,
content: @Composable ColumnScope.() -> Unit,
) {
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(
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()
}
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,17 +168,17 @@ 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
},
onConfirmation = {
viewModel.logout()
overlayVisible = DirectoryOverlay.NONE
},
"Log Out",
"Are you sure you want to logout?"
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
},
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import com.kevinschildhorn.fotopresenter.ui.screens.common.ScreenState

data class PlaylistScreenState(
val playlists: List<Playlist> = emptyList(),
val selectedId: Long = 0L,
val selectedId: Long? = null,
override val state: UiState = UiState.IDLE,
) : ScreenState
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Loading
Loading