Added album name change functionality
This commit is contained in:
1 parent
7e8ed5c5ab
commit
7cb0424c02
6 files changed
+149
-10
No files matched your search
+3
-1
@@ -1,6 +1,5 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation
|
||||
|
||||
import androidx.compose.animation.AnimatedContentTransitionScope
|
||||
import androidx.compose.animation.core.LinearEasing
|
||||
import androidx.compose.animation.core.tween
|
||||
import androidx.compose.animation.fadeIn
|
||||
@@ -200,6 +199,9 @@ fun PaperizeApp(
|
||||
onDeleteAlbum = {
|
||||
albumsViewModel.onEvent(AlbumsEvent.DeleteAlbumWithWallpapers(albumWithWallpaper))
|
||||
navController.navigateUp()
|
||||
},
|
||||
onTitleChange = { title, originalAlbumWithWallpaper ->
|
||||
albumsViewModel.onEvent(AlbumsEvent.ChangeAlbumName(title, originalAlbumWithWallpaper))
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
+5
@@ -8,4 +8,9 @@ sealed class AlbumsEvent {
|
||||
data class DeleteAlbumWithWallpapers(
|
||||
val albumWithWallpaper: AlbumWithWallpaper
|
||||
): AlbumsEvent()
|
||||
|
||||
data class ChangeAlbumName(
|
||||
val title: String,
|
||||
val albumWithWallpaper: AlbumWithWallpaper
|
||||
): AlbumsEvent()
|
||||
}
|
||||
+10
-1
@@ -57,6 +57,15 @@ class AlbumsViewModel @Inject constructor (
|
||||
refreshAlbums()
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.ChangeAlbumName -> {
|
||||
viewModelScope.launch {
|
||||
if (!(_state.value.albumWithWallpapers.any { it.album.displayedAlbumName == event.title })) {
|
||||
repository.updateAlbum(
|
||||
event.albumWithWallpaper.album.copy(displayedAlbumName = event.title)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
is AlbumsEvent.RefreshAlbums -> {
|
||||
viewModelScope.launch {
|
||||
updateAlbums()
|
||||
@@ -89,7 +98,7 @@ class AlbumsViewModel @Inject constructor (
|
||||
repository.deleteFolder(folder)
|
||||
} else {
|
||||
val wallpapers = getWallpaperFromFolder(folder.folderUri, context)
|
||||
var folderCover: String? = null
|
||||
val folderCover: String?
|
||||
if (folder.coverUri != null) {
|
||||
val folderCoverFile = DocumentFile.fromSingleUri(context, folder.coverUri.toUri())
|
||||
if (folderCoverFile == null || !folderCoverFile.exists()) {
|
||||
|
||||
+5
-2
@@ -24,7 +24,9 @@ fun AlbumViewScreen(
|
||||
onBackClick: () -> Unit,
|
||||
onShowWallpaperView: (String) -> Unit,
|
||||
onShowFolderView: (String, String?, List<String>) -> Unit,
|
||||
onDeleteAlbum: () -> Unit
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onTitleChange: (String, AlbumWithWallpaper) -> Unit
|
||||
|
||||
) {
|
||||
val lazyListState = rememberLazyStaggeredGridState()
|
||||
BackHandler { onBackClick() }
|
||||
@@ -33,7 +35,8 @@ fun AlbumViewScreen(
|
||||
AlbumViewTopBar(
|
||||
title = albumWithWallpaper.album.displayedAlbumName,
|
||||
onBackClick = { onBackClick() },
|
||||
onDeleteAlbum = onDeleteAlbum
|
||||
onDeleteAlbum = onDeleteAlbum,
|
||||
onTitleChange = { onTitleChange(it, albumWithWallpaper) }
|
||||
)
|
||||
},
|
||||
content = {
|
||||
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
package com.anthonyla.paperize.feature.wallpaper.presentation.album_view_screen.components
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.Card
|
||||
import androidx.compose.material3.CardDefaults
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.OutlinedTextField
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextButton
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.saveable.rememberSaveable
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.focus.FocusRequester
|
||||
import androidx.compose.ui.focus.focusRequester
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardType
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import com.anthonyla.paperize.R
|
||||
import kotlinx.coroutines.android.awaitFrame
|
||||
|
||||
@Composable
|
||||
fun AlbumNameDialog(
|
||||
onDismissRequest: () -> Unit,
|
||||
onConfirmation: (String) -> Unit
|
||||
) {
|
||||
val focusRequester = remember { FocusRequester() }
|
||||
var albumName by rememberSaveable { mutableStateOf("") }
|
||||
Dialog(onDismissRequest = onDismissRequest) {
|
||||
Card(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(24.dp),
|
||||
shape = RoundedCornerShape(16.dp),
|
||||
colors = CardDefaults.cardColors(
|
||||
containerColor = MaterialTheme.colorScheme.surface,
|
||||
contentColor = MaterialTheme.colorScheme.onSurface
|
||||
)
|
||||
) {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.Top,
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
LaunchedEffect(focusRequester) {
|
||||
awaitFrame()
|
||||
focusRequester.requestFocus()
|
||||
}
|
||||
Spacer(modifier = Modifier.padding(10.dp))
|
||||
OutlinedTextField(
|
||||
value = albumName,
|
||||
onValueChange = { albumName = it },
|
||||
label = { Text(stringResource(R.string.album_name)) },
|
||||
modifier = Modifier
|
||||
.padding(vertical = 12.dp, horizontal = 32.dp)
|
||||
.focusRequester(focusRequester),
|
||||
singleLine = true,
|
||||
shape = RoundedCornerShape(8.dp),
|
||||
keyboardOptions = KeyboardOptions(
|
||||
keyboardType = KeyboardType.Text,
|
||||
imeAction = ImeAction.Done,
|
||||
),
|
||||
keyboardActions = KeyboardActions(
|
||||
onDone = {
|
||||
if (albumName.isNotEmpty()) {
|
||||
onConfirmation(albumName)
|
||||
onDismissRequest()
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
horizontalArrangement = Arrangement.Center,
|
||||
) {
|
||||
TextButton(
|
||||
onClick = { onDismissRequest() },
|
||||
modifier = Modifier.padding(8.dp),
|
||||
) {
|
||||
Text(stringResource(R.string.cancel))
|
||||
}
|
||||
TextButton(
|
||||
modifier = Modifier.padding(8.dp),
|
||||
onClick = {
|
||||
if (albumName.isNotEmpty()) {
|
||||
onConfirmation(albumName)
|
||||
onDismissRequest()
|
||||
}
|
||||
}
|
||||
) {
|
||||
Text(stringResource(R.string.save))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+15
-6
@@ -25,7 +25,6 @@ import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.anthonyla.paperize.R
|
||||
import com.anthonyla.paperize.feature.wallpaper.presentation.add_album_screen.components.DeleteImagesAlertDialog
|
||||
|
||||
@OptIn(ExperimentalMaterial3Api::class)
|
||||
@Composable
|
||||
@@ -33,9 +32,11 @@ fun AlbumViewTopBar(
|
||||
title: String,
|
||||
onBackClick: () -> Unit,
|
||||
onDeleteAlbum: () -> Unit,
|
||||
onTitleChange: (String) -> Unit,
|
||||
modifier: Modifier = Modifier
|
||||
) {
|
||||
var showAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showDeleteAlertDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var showNameChangeDialog by rememberSaveable { mutableStateOf(false) }
|
||||
var menuExpanded by rememberSaveable { mutableStateOf(false) }
|
||||
|
||||
TopAppBar(
|
||||
@@ -55,13 +56,20 @@ fun AlbumViewTopBar(
|
||||
}
|
||||
},
|
||||
actions = {
|
||||
if (showAlertDialog) DeleteAlbumAlertDialog (
|
||||
onDismissRequest = { showAlertDialog = false },
|
||||
if (showDeleteAlertDialog) DeleteAlbumAlertDialog (
|
||||
onDismissRequest = { showDeleteAlertDialog = false },
|
||||
onConfirmation = {
|
||||
showAlertDialog = false
|
||||
showDeleteAlertDialog = false
|
||||
onDeleteAlbum()
|
||||
}
|
||||
)
|
||||
if (showNameChangeDialog) AlbumNameDialog (
|
||||
onDismissRequest = { showNameChangeDialog = false },
|
||||
onConfirmation = {
|
||||
showNameChangeDialog = false
|
||||
onTitleChange(it)
|
||||
}
|
||||
)
|
||||
IconButton(onClick = { menuExpanded = true }) {
|
||||
Icon(
|
||||
imageVector = Icons.Filled.MoreVert,
|
||||
@@ -79,13 +87,14 @@ fun AlbumViewTopBar(
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.delete_album)) },
|
||||
onClick = {
|
||||
showAlertDialog = true
|
||||
showDeleteAlertDialog = true
|
||||
menuExpanded = false
|
||||
}
|
||||
)
|
||||
DropdownMenuItem(
|
||||
text = { Text(stringResource(R.string.change_name)) },
|
||||
onClick = {
|
||||
showNameChangeDialog = true
|
||||
menuExpanded = false
|
||||
}
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user