From bc47b662c69bfd5d0f63aec9b7bfd4d3cf44efc2 Mon Sep 17 00:00:00 2001 From: Nickolas <91910852+nickolasram@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:40:41 -0800 Subject: [PATCH] Creator view Page added (#233) Co-authored-by: kaimanasse15 <91504156+kaimanasse15@users.noreply.github.com> --- .../com/example/belindas_closet/Routes.kt | 1 + .../belindas_closet/screen/CreatorView.kt | 119 ++++++++++++++++++ .../example/belindas_closet/screen/Login.kt | 7 +- .../belindas_closet/screen/ScreenMain.kt | 4 + 4 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 app/src/main/java/com/example/belindas_closet/screen/CreatorView.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 e709f137..f0e0e877 100644 --- a/app/src/main/java/com/example/belindas_closet/Routes.kt +++ b/app/src/main/java/com/example/belindas_closet/Routes.kt @@ -12,6 +12,7 @@ sealed class Routes (val route: String) { object IndividualProduct: Routes("Individual_Product") object IndividualProductUpdatePage: Routes("Individual_Product_Update") object AdminView: Routes("Admin_View") + object CreatorView: Routes("Creator_View") object EditUserRole: Routes("Edit User Role") object DonationInfo: Routes("Donation_Info") } \ No newline at end of file diff --git a/app/src/main/java/com/example/belindas_closet/screen/CreatorView.kt b/app/src/main/java/com/example/belindas_closet/screen/CreatorView.kt new file mode 100644 index 00000000..1b30f21f --- /dev/null +++ b/app/src/main/java/com/example/belindas_closet/screen/CreatorView.kt @@ -0,0 +1,119 @@ +package com.example.belindas_closet.screen + +import android.widget.Toast +import androidx.compose.foundation.Image +import androidx.compose.foundation.background +import androidx.compose.foundation.border +import androidx.compose.foundation.clickable +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.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +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.ExitToApp +import androidx.compose.material.icons.filled.Menu +import androidx.compose.material3.Button +import androidx.compose.material3.DrawerValue +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.IconButton +import androidx.compose.material3.Text +import androidx.compose.material3.TopAppBar +import androidx.compose.runtime.Composable +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.RectangleShape +import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource +import androidx.compose.ui.res.stringResource +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.navigation.NavHostController +import com.example.belindas_closet.MainActivity +import com.example.belindas_closet.R +import com.example.belindas_closet.Routes + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun CreatorView(navController: NavHostController) { + val current = LocalContext.current + Row( + modifier = Modifier + .height(75.dp) + .padding(10.dp) + .fillMaxWidth(), + verticalAlignment = Alignment.Top, + horizontalArrangement = Arrangement.SpaceBetween + ) { + NSCLogo() + Icon(Icons.Filled.ExitToApp, contentDescription="Logout", + modifier = Modifier.clickable { + MainActivity.getPref().edit().remove("token").commit() + MainActivity.getPref().edit().remove("userRole").commit() + navController.navigate(Routes.Home.route) + Toast.makeText( + current, + "Logged Out", + Toast.LENGTH_SHORT + ).show() + }) + } + Row( + modifier = Modifier + .fillMaxSize(), + verticalAlignment = Alignment.CenterVertically, + horizontalArrangement = Arrangement.SpaceBetween + ){ + Column( + modifier = Modifier + .fillMaxSize(), + verticalArrangement = Arrangement.Top, + horizontalAlignment = Alignment.CenterHorizontally + ) { + Spacer(modifier = Modifier.padding(50.dp)) + Image( + painter = painterResource(id = R.drawable.packaging), + contentDescription = stringResource(id = R.string.home_logo_description), + modifier = Modifier + .size(100.dp) + .padding(8.dp, bottom = 16.dp) + ) + CustomTextField( + text = stringResource(R.string.home_welcome), + fontSize = 30.sp + ) + Spacer(modifier = Modifier.padding(16.dp)) + + // Add Product button + Button( + onClick = { + navController.navigate(Routes.AddProduct.route) + }, + modifier = Modifier + .padding(4.dp) + .align(Alignment.CenterHorizontally) + ) { + Text(text = "Add Product") + } + Button( + onClick = { + navController.navigate(Routes.Home.route) + }, + modifier = Modifier + .padding(4.dp) + .align(Alignment.CenterHorizontally) + ) { + Text(text = "All Products") + } + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/belindas_closet/screen/Login.kt b/app/src/main/java/com/example/belindas_closet/screen/Login.kt index 1b58b3de..1783fa08 100644 --- a/app/src/main/java/com/example/belindas_closet/screen/Login.kt +++ b/app/src/main/java/com/example/belindas_closet/screen/Login.kt @@ -2,6 +2,7 @@ package com.example.belindas_closet.screen import android.content.Context import android.util.Base64 +import android.util.Log import android.util.Patterns import android.widget.Toast import androidx.compose.foundation.Image @@ -315,7 +316,11 @@ suspend fun loginWithValidCredentials(email: String, password: String, navContro MainActivity.getPref().edit().putString("userRole", userRole.name).apply() MainActivity.getPref().edit().putString("token", loginResponse.token).apply() - navController.navigate(Routes.AdminView.route) + if (userRole.name == "ADMIN") { + navController.navigate(Routes.AdminView.route) + } else { + navController.navigate(Routes.CreatorView.route) + } Toast.makeText( current, "Welcome ${getName(loginResponse.token)} to Belinda's Closet!", 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 bc35a842..1eacd08b 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 @@ -49,6 +49,10 @@ fun ScreenMain() { DonationInfoPage(navController = navController) } + composable(Routes.CreatorView.route) { + CreatorView(navController = navController) + } + composable(Routes.IndividualProduct.route+"/{productId}", arguments = listOf(navArgument("productId") { type = NavType.StringType }) ) { backStackEntry ->