From d6c9197c5ddd90b143ac0ed8926733fc7b3a7f13 Mon Sep 17 00:00:00 2001 From: pabloscloud <93644977+pabloscloud@users.noreply.github.com> Date: Sat, 13 Apr 2024 23:31:21 +0200 Subject: [PATCH] - adds delete category screen --- .../cloud/pablos/overload/ui/OverloadApp.kt | 1 + .../OverloadNavigationComponents.kt | 4 +- .../ui/screens/category/CategoryScreen.kt | 3 + .../category/CategoryScreenBottomAppBar.kt | 57 +++++++++++- .../CategoryScreenDeleteCategoryDialog.kt | 92 +++++++++++++++++++ .../tabs/configurations/ConfigurationsTab.kt | 82 ----------------- 6 files changed, 155 insertions(+), 84 deletions(-) create mode 100644 app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenDeleteCategoryDialog.kt diff --git a/app/src/main/java/cloud/pablos/overload/ui/OverloadApp.kt b/app/src/main/java/cloud/pablos/overload/ui/OverloadApp.kt index 54e86b4..ab4dcde 100644 --- a/app/src/main/java/cloud/pablos/overload/ui/OverloadApp.kt +++ b/app/src/main/java/cloud/pablos/overload/ui/OverloadApp.kt @@ -319,6 +319,7 @@ fun OverloadAppContent( selectedDestination = selectedDestination, navigateToTopLevelDestination = navigateToTopLevelDestination, categoryState = categoryState, + categoryEvent = categoryEvent, itemState = itemState, itemEvent = itemEvent, navController = navController, diff --git a/app/src/main/java/cloud/pablos/overload/ui/navigation/OverloadNavigationComponents.kt b/app/src/main/java/cloud/pablos/overload/ui/navigation/OverloadNavigationComponents.kt index 4daabca..ac17f40 100644 --- a/app/src/main/java/cloud/pablos/overload/ui/navigation/OverloadNavigationComponents.kt +++ b/app/src/main/java/cloud/pablos/overload/ui/navigation/OverloadNavigationComponents.kt @@ -208,11 +208,13 @@ class BottomBarState private constructor() { } } +@RequiresApi(Build.VERSION_CODES.S) @Composable fun OverloadBottomNavigationBar( selectedDestination: String, navigateToTopLevelDestination: (OverloadTopLevelDestination) -> Unit, categoryState: CategoryState, + categoryEvent: (CategoryEvent) -> Unit, itemState: ItemState, itemEvent: (ItemEvent) -> Unit, navController: NavHostController, @@ -319,7 +321,7 @@ fun OverloadBottomNavigationBar( } BottomBarState.Category -> { - CategoryScreenBottomAppBar(navController) + CategoryScreenBottomAppBar(categoryState, categoryEvent, itemState, itemEvent, navController) } BottomBarState.Day -> { diff --git a/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreen.kt b/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreen.kt index 7856d73..4b6c548 100644 --- a/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreen.kt +++ b/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreen.kt @@ -15,6 +15,7 @@ import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.DarkMode import androidx.compose.material3.Icon @@ -35,6 +36,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource import androidx.compose.ui.semantics.clearAndSetSemantics import androidx.compose.ui.semantics.contentDescription +import androidx.compose.ui.text.input.KeyboardCapitalization import androidx.compose.ui.text.input.TextFieldValue import androidx.compose.ui.unit.dp import cloud.pablos.overload.R @@ -135,6 +137,7 @@ fun CategoryScreen( ) }, ), + keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Sentences), modifier = Modifier.fillMaxWidth(), ) } diff --git a/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenBottomAppBar.kt b/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenBottomAppBar.kt index 0dcfefd..5fc0a92 100644 --- a/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenBottomAppBar.kt +++ b/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenBottomAppBar.kt @@ -1,16 +1,40 @@ package cloud.pablos.overload.ui.screens.day +import android.os.Build +import androidx.annotation.RequiresApi import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.outlined.KeyboardArrowLeft +import androidx.compose.material.icons.filled.DeleteForever import androidx.compose.material3.BottomAppBar +import androidx.compose.material3.FloatingActionButton import androidx.compose.material3.Icon import androidx.compose.material3.IconButton +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.ui.res.stringResource import androidx.navigation.NavHostController +import cloud.pablos.overload.R +import cloud.pablos.overload.data.category.CategoryEvent +import cloud.pablos.overload.data.category.CategoryState +import cloud.pablos.overload.data.item.ItemEvent +import cloud.pablos.overload.data.item.ItemState import cloud.pablos.overload.ui.navigation.OverloadRoute +import cloud.pablos.overload.ui.screens.category.CategoryScreenDeleteCategoryDialog +@RequiresApi(Build.VERSION_CODES.S) @Composable -fun CategoryScreenBottomAppBar(navController: NavHostController) { +fun CategoryScreenBottomAppBar( + categoryState: CategoryState, + categoryEvent: (CategoryEvent) -> Unit, + itemState: ItemState, + itemEvent: (ItemEvent) -> Unit, + navController: NavHostController, +) { + val selectedCategory = categoryState.categories.find { it.id == categoryState.selectedCategoryConfigurations } + val deleteCategoryDialog = remember { mutableStateOf(false) } + BottomAppBar( actions = { IconButton(onClick = { navController.navigate(OverloadRoute.CONFIGURATIONS) }) { @@ -20,5 +44,36 @@ fun CategoryScreenBottomAppBar(navController: NavHostController) { ) } }, + floatingActionButton = { + FloatingActionButton( + onClick = { deleteCategoryDialog.value = true }, + containerColor = MaterialTheme.colorScheme.errorContainer, + contentColor = MaterialTheme.colorScheme.onErrorContainer, + ) { + Icon( + Icons.Filled.DeleteForever, + contentDescription = stringResource(id = R.string.delete_items_forever), + ) + } + }, ) + + if (deleteCategoryDialog.value && selectedCategory != null) { + CategoryScreenDeleteCategoryDialog( + onDismiss = { deleteCategoryDialog.value = false }, + onConfirm = { + categoryEvent(CategoryEvent.DeleteCategory(selectedCategory)) + + val items = + itemState.items.filter { item -> + selectedCategory.id == item.categoryId + } + itemEvent(ItemEvent.DeleteItems(items)) + + deleteCategoryDialog.value = false + navController.navigate(OverloadRoute.CONFIGURATIONS) + }, + category = selectedCategory, + ) + } } diff --git a/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenDeleteCategoryDialog.kt b/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenDeleteCategoryDialog.kt new file mode 100644 index 0000000..14c4573 --- /dev/null +++ b/app/src/main/java/cloud/pablos/overload/ui/screens/category/CategoryScreenDeleteCategoryDialog.kt @@ -0,0 +1,92 @@ +package cloud.pablos.overload.ui.screens.category + +import android.os.Build +import androidx.annotation.RequiresApi +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.rounded.Dangerous +import androidx.compose.material3.AlertDialog +import androidx.compose.material3.Button +import androidx.compose.material3.ButtonDefaults +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.Modifier +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.style.TextAlign +import androidx.compose.ui.text.style.TextOverflow +import androidx.compose.ui.unit.dp +import cloud.pablos.overload.R +import cloud.pablos.overload.data.category.Category +import cloud.pablos.overload.ui.views.TextView + +@RequiresApi(Build.VERSION_CODES.S) +@Composable +fun CategoryScreenDeleteCategoryDialog( + onDismiss: () -> Unit, + onConfirm: () -> Unit, + category: Category, +) { + AlertDialog( + onDismissRequest = onDismiss, + icon = { + Icon( + imageVector = Icons.Rounded.Dangerous, + contentDescription = "Delete Category", + tint = MaterialTheme.colorScheme.error, + ) + }, + title = { + TextView( + text = "Delete Category", + fontWeight = FontWeight.Bold, + align = TextAlign.Center, + maxLines = 2, + modifier = Modifier.fillMaxWidth(), + ) + }, + text = { + Column { + Text( + text = "Are you sure you want to delete" + " " + category.name + "?", + textAlign = TextAlign.Center, + modifier = Modifier.fillMaxWidth(), + overflow = TextOverflow.Ellipsis, + ) + } + }, + confirmButton = { + Button( + onClick = { + onConfirm() + }, + colors = + ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.errorContainer, + contentColor = MaterialTheme.colorScheme.onErrorContainer, + ), + ) { + TextView(stringResource(R.string.yes)) + } + }, + dismissButton = { + Button( + onClick = { + onDismiss() + }, + colors = + ButtonDefaults.buttonColors( + containerColor = MaterialTheme.colorScheme.secondaryContainer, + contentColor = MaterialTheme.colorScheme.onSecondaryContainer, + ), + ) { + TextView(stringResource(R.string.no)) + } + }, + modifier = Modifier.padding(16.dp), + ) +} diff --git a/app/src/main/java/cloud/pablos/overload/ui/tabs/configurations/ConfigurationsTab.kt b/app/src/main/java/cloud/pablos/overload/ui/tabs/configurations/ConfigurationsTab.kt index c425568..b4a6561 100644 --- a/app/src/main/java/cloud/pablos/overload/ui/tabs/configurations/ConfigurationsTab.kt +++ b/app/src/main/java/cloud/pablos/overload/ui/tabs/configurations/ConfigurationsTab.kt @@ -119,88 +119,6 @@ fun ConfigurationsTab( .padding(horizontal = 16.dp), verticalArrangement = Arrangement.spacedBy(6.dp), ) { - /* - // Goals Title - item { - ConfigurationsTabItem(title = stringResource(id = R.string.goals)) - } - - // Work Goal - item { - val itemLabel = - stringResource(id = R.string.work) + ": " + stringResource(id = R.string.work_goal_descr) - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = - Modifier - .clickable { - workGoalDialogState.value = true - } - .clearAndSetSemantics { - contentDescription = itemLabel - }, - ) { - Icon( - imageVector = Icons.Rounded.Work, - contentDescription = stringResource(id = R.string.work), - tint = MaterialTheme.colorScheme.primary, - modifier = Modifier.padding(horizontal = 8.dp), - ) - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth(), - ) { - Column { - ConfigurationTitle(stringResource(id = R.string.work)) - ConfigurationDescription(stringResource(id = R.string.work_goal_descr)) - } - } - } - } - - // Pause Goal - item { - val itemLabel = - stringResource(id = R.string.pause) + ": " + stringResource(id = R.string.pause_goal_descr) - - Row( - verticalAlignment = Alignment.CenterVertically, - modifier = - Modifier - .clickable { - pauseGoalDialogState.value = true - } - .clearAndSetSemantics { - contentDescription = itemLabel - }, - ) { - Icon( - imageVector = Icons.Filled.DarkMode, - contentDescription = stringResource(id = R.string.pause), - tint = MaterialTheme.colorScheme.primary, - modifier = Modifier.padding(horizontal = 8.dp), - ) - Row( - verticalAlignment = Alignment.CenterVertically, - horizontalArrangement = Arrangement.SpaceBetween, - modifier = Modifier.fillMaxWidth(), - ) { - Column { - ConfigurationTitle(stringResource(id = R.string.pause)) - ConfigurationDescription(stringResource(id = R.string.pause_goal_descr)) - } - } - } - } - - // Goals Divider - item { - Row { - HorizontalDivider() - } - }*/ - // Categories Title item { ConfigurationsTabItem(title = stringResource(id = R.string.categories))