From 36d84c532de11a5167d01e40e7ee2b6c330bdf40 Mon Sep 17 00:00:00 2001 From: Nickolas Date: Thu, 25 Apr 2024 03:51:55 -0700 Subject: [PATCH] Mission Page plus dropdown --- .../com/example/belindas_closet/Routes.kt | 1 + .../components/DropdownNavList.kt.kt | 48 ++++++++++ .../example/belindas_closet/screen/Home.kt | 11 +++ .../screen/IndividualProduct.kt | 3 +- .../screen/IndividualProductUpdate.kt | 3 +- .../example/belindas_closet/screen/Mission.kt | 94 +++++++++++++++++++ .../belindas_closet/screen/ProductDetail.kt | 26 +---- .../belindas_closet/screen/ScreenMain.kt | 4 + .../example/belindas_closet/screen/Update.kt | 3 +- 9 files changed, 166 insertions(+), 27 deletions(-) create mode 100644 app/src/main/java/com/example/belindas_closet/components/DropdownNavList.kt.kt create mode 100644 app/src/main/java/com/example/belindas_closet/screen/Mission.kt diff --git a/app/src/main/java/com/example/belindas_closet/Routes.kt b/app/src/main/java/com/example/belindas_closet/Routes.kt index f0e0e877..9c271a11 100644 --- a/app/src/main/java/com/example/belindas_closet/Routes.kt +++ b/app/src/main/java/com/example/belindas_closet/Routes.kt @@ -15,4 +15,5 @@ sealed class Routes (val route: String) { object CreatorView: Routes("Creator_View") object EditUserRole: Routes("Edit User Role") object DonationInfo: Routes("Donation_Info") + object Mission: Routes("Mission") } \ No newline at end of file diff --git a/app/src/main/java/com/example/belindas_closet/components/DropdownNavList.kt.kt b/app/src/main/java/com/example/belindas_closet/components/DropdownNavList.kt.kt new file mode 100644 index 00000000..2171380c --- /dev/null +++ b/app/src/main/java/com/example/belindas_closet/components/DropdownNavList.kt.kt @@ -0,0 +1,48 @@ +package com.example.belindas_closet.components + +import androidx.compose.foundation.layout.padding +import androidx.compose.material3.DrawerValue +import androidx.compose.material3.DropdownMenu +import androidx.compose.material3.DropdownMenuItem +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Text +import androidx.compose.runtime.Composable +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.Modifier +import androidx.compose.ui.unit.dp +import androidx.navigation.NavController +import com.example.belindas_closet.MainActivity +import com.example.belindas_closet.Routes +import com.example.belindas_closet.model.ProductType + +@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) +@Composable +fun DropdownNavList(drawerState: DrawerValue, navController: NavController, onDismissRequest: () -> Unit = {}) { + DropdownMenu( + drawerState == DrawerValue.Open, + onDismissRequest = onDismissRequest, + modifier = Modifier + .padding(8.dp) + ) { + DropdownMenuItem( + text = { Text(text = "Mission") }, + onClick = { + onDismissRequest() + navController.navigate( + Routes.Mission.route) + } + ) + ProductType.values().forEach { productType -> + DropdownMenuItem( + text = { Text(productType.type) }, + onClick = { + onDismissRequest() + // navigate to product type page + MainActivity.setProductType(productType.type) + navController.navigate( + Routes.ProductDetail.route) + } + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/belindas_closet/screen/Home.kt b/app/src/main/java/com/example/belindas_closet/screen/Home.kt index a0c6961c..9df8aff5 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/Home.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/Home.kt @@ -16,6 +16,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Menu import androidx.compose.material3.Button import androidx.compose.material3.Card +import androidx.compose.material3.DrawerValue import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.IconButton @@ -23,6 +24,10 @@ import androidx.compose.material3.Text import androidx.compose.material3.TextButton import androidx.compose.material3.TopAppBar 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.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color @@ -41,11 +46,13 @@ import com.example.belindas_closet.Routes import com.example.belindas_closet.data.Datasource import com.example.belindas_closet.model.Product import com.example.belindas_closet.model.ProductType +import com.example.belindas_closet.components.DropdownNavList //TODO Add Product Catefories to Navbar @OptIn(ExperimentalMaterial3Api::class) @Composable fun HomePage(navController: NavController) { + var drawerState by remember { mutableStateOf(DrawerValue.Closed) } TopAppBar( title = { Text("") }, actions = { @@ -71,10 +78,14 @@ fun HomePage(navController: NavController) { } IconButton( onClick = { + drawerState = DrawerValue.Open } ) { Icon(imageVector = Icons.Default.Menu, contentDescription = "Menu") } + DropdownNavList(drawerState, navController) { + drawerState = DrawerValue.Closed + } }, ) Row( diff --git a/app/src/main/java/com/example/belindas_closet/screen/IndividualProduct.kt b/app/src/main/java/com/example/belindas_closet/screen/IndividualProduct.kt index ca36a1cd..fa5c145b 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/IndividualProduct.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/IndividualProduct.kt @@ -37,6 +37,7 @@ import androidx.compose.runtime.* import androidx.compose.ui.graphics.RectangleShape import androidx.compose.ui.window.Popup import com.example.belindas_closet.MainActivity +import com.example.belindas_closet.components.DropdownNavList import com.example.belindas_closet.data.network.dto.auth_dto.Role //TODO Add Product Categories to Navbar @@ -89,7 +90,7 @@ fun IndividualProductPage(navController: NavController, productId: String) { contentDescription = "Menu" ) } - DropDownCategoryList(drawerState, navController) { + DropdownNavList(drawerState, navController) { drawerState = DrawerValue.Closed } } diff --git a/app/src/main/java/com/example/belindas_closet/screen/IndividualProductUpdate.kt b/app/src/main/java/com/example/belindas_closet/screen/IndividualProductUpdate.kt index 679d5d14..bfb64f1b 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/IndividualProductUpdate.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/IndividualProductUpdate.kt @@ -53,6 +53,7 @@ import androidx.navigation.NavController import com.example.belindas_closet.MainActivity import com.example.belindas_closet.R import com.example.belindas_closet.Routes +import com.example.belindas_closet.components.DropdownNavList import com.example.belindas_closet.data.Datasource import com.example.belindas_closet.data.network.product.ArchiveService import com.example.belindas_closet.data.network.product.DeleteService @@ -118,7 +119,7 @@ fun IndividualProductUpdatePage(navController: NavController, productId: String) contentDescription = "Menu" ) } - DropDownCategoryList(drawerState, navController) { + DropdownNavList(drawerState, navController) { drawerState = DrawerValue.Closed } } diff --git a/app/src/main/java/com/example/belindas_closet/screen/Mission.kt b/app/src/main/java/com/example/belindas_closet/screen/Mission.kt new file mode 100644 index 00000000..70d10ce5 --- /dev/null +++ b/app/src/main/java/com/example/belindas_closet/screen/Mission.kt @@ -0,0 +1,94 @@ +package com.example.belindas_closet.screen + +import androidx.compose.foundation.layout.Arrangement +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.padding +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.ArrowBack +import androidx.compose.material.icons.filled.Edit +import androidx.compose.material.icons.filled.Menu +import androidx.compose.material3.DrawerValue +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Scaffold +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +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.Alignment +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.Modifier +import androidx.navigation.NavController +import com.example.belindas_closet.MainActivity +import com.example.belindas_closet.Routes +import com.example.belindas_closet.data.network.dto.auth_dto.Role +import com.example.belindas_closet.components.DropdownNavList + +@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class) +@Composable +fun MissionPage(navController: NavController) { + var drawerState by remember { mutableStateOf(DrawerValue.Closed) } + + Scaffold( + modifier = Modifier + .fillMaxSize(), + topBar = { + /* Back arrow that navigates back to login page */ + TopAppBar( + title = { Text("Home") }, + navigationIcon = { + IconButton( + onClick = { + navController.navigate(Routes.Home.route) + } + ) { + Icon( + imageVector = Icons.Default.ArrowBack, + contentDescription = "Back to Home page" + ) + } + }, + actions = { + /* Edit option visibility */ + val userRole = MainActivity.getPref().getString("userRole", Role.USER.name)?.let { + Role.valueOf(it) + } ?: Role.USER + if (userRole == Role.ADMIN || userRole == Role.CREATOR) { + IconButton( + onClick = { + navController.navigate(Routes.Update.route) + } + ) { + Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit") + } + } + IconButton( + onClick = { + drawerState = DrawerValue.Open + } + ) { + Icon(imageVector = Icons.Default.Menu, contentDescription = "Menu") + } + DropdownNavList(drawerState, navController) { + drawerState = DrawerValue.Closed + } + } + ) + }, + ) { innerPadding -> + val modifier = Modifier.padding(innerPadding) + Column( + modifier = modifier + .fillMaxSize(), + verticalArrangement = Arrangement.Center, + horizontalAlignment = Alignment.CenterHorizontally + ) { + CustomTextField(text = "Mission Statement Placeholder") + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt b/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt index 1b53c2fb..2cc3f2a0 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/ProductDetail.kt @@ -45,6 +45,7 @@ import com.example.belindas_closet.data.Datasource import com.example.belindas_closet.data.network.dto.auth_dto.Role import com.example.belindas_closet.model.Product import com.example.belindas_closet.model.ProductType +import com.example.belindas_closet.components.DropdownNavList @OptIn(ExperimentalMaterial3Api::class) @Composable @@ -91,7 +92,7 @@ fun ProductDetailPage(navController: NavController) { ) { Icon(imageVector = Icons.Default.Menu, contentDescription = "Menu") } - DropDownCategoryList(drawerState, navController) { + DropdownNavList(drawerState, navController) { drawerState = DrawerValue.Closed } } @@ -168,26 +169,3 @@ fun ProductDetailList(products: List, navController: NavController) { } } } -@Composable -fun DropDownCategoryList(drawerState: DrawerValue, navController: NavController, onDismissRequest: () -> Unit = {}) { - DropdownMenu( - drawerState == DrawerValue.Open, - onDismissRequest = onDismissRequest, - modifier = Modifier - .padding(8.dp) - ) { - ProductType.values().forEach { productType -> - DropdownMenuItem( - text = { Text(productType.type) }, - onClick = { - onDismissRequest() - // navigate to product type page - MainActivity.setProductType(productType.type) - navController.navigate( - Routes.ProductDetail.route) - } - ) - } - } -} - diff --git a/app/src/main/java/com/example/belindas_closet/screen/ScreenMain.kt b/app/src/main/java/com/example/belindas_closet/screen/ScreenMain.kt index 1eacd08b..a4a1c07b 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/ScreenMain.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/ScreenMain.kt @@ -53,6 +53,10 @@ fun ScreenMain() { CreatorView(navController = navController) } + composable(Routes.Mission.route) { + MissionPage(navController = navController) + } + composable(Routes.IndividualProduct.route+"/{productId}", arguments = listOf(navArgument("productId") { type = NavType.StringType }) ) { backStackEntry -> diff --git a/app/src/main/java/com/example/belindas_closet/screen/Update.kt b/app/src/main/java/com/example/belindas_closet/screen/Update.kt index 46088166..81f3c61e 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/Update.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/Update.kt @@ -48,6 +48,7 @@ import androidx.navigation.NavController import com.example.belindas_closet.MainActivity import com.example.belindas_closet.R import com.example.belindas_closet.Routes +import com.example.belindas_closet.components.DropdownNavList import com.example.belindas_closet.data.Datasource import com.example.belindas_closet.data.network.dto.auth_dto.Role import com.example.belindas_closet.model.Product @@ -103,7 +104,7 @@ fun UpdatePage(navController: NavController) { contentDescription = "Menu" ) } - DropDownCategoryList(drawerState, navController) { + DropdownNavList(drawerState, navController) { drawerState = DrawerValue.Closed } }