Skip to content

Commit

Permalink
- adds delete category screen
Browse files Browse the repository at this point in the history
  • Loading branch information
pablo03v committed Apr 13, 2024
1 parent 7e8d3e2 commit d6c9197
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 84 deletions.
1 change: 1 addition & 0 deletions app/src/main/java/cloud/pablos/overload/ui/OverloadApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ fun OverloadAppContent(
selectedDestination = selectedDestination,
navigateToTopLevelDestination = navigateToTopLevelDestination,
categoryState = categoryState,
categoryEvent = categoryEvent,
itemState = itemState,
itemEvent = itemEvent,
navController = navController,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -319,7 +321,7 @@ fun OverloadBottomNavigationBar(
}

BottomBarState.Category -> {
CategoryScreenBottomAppBar(navController)
CategoryScreenBottomAppBar(categoryState, categoryEvent, itemState, itemEvent, navController)
}

BottomBarState.Day -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -135,6 +137,7 @@ fun CategoryScreen(
)
},
),
keyboardOptions = KeyboardOptions(capitalization = KeyboardCapitalization.Sentences),
modifier = Modifier.fillMaxWidth(),
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) }) {
Expand All @@ -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,
)
}
}
Original file line number Diff line number Diff line change
@@ -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),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit d6c9197

Please sign in to comment.