Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

belindas-closet-android_3_108_creator-view-page #233

Merged
merged 3 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/com/example/belindas_closet/Routes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ 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")
}
119 changes: 119 additions & 0 deletions app/src/main/java/com/example/belindas_closet/screen/CreatorView.kt
Original file line number Diff line number Diff line change
@@ -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")
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ fun ScreenMain() {
AdminView(navController = navController)
}

composable(Routes.CreatorView.route) {
CreatorView(navController = navController)
}

composable(Routes.IndividualProduct.route+"/{productId}",
arguments = listOf(navArgument("productId") { type = NavType.StringType })
) { backStackEntry ->
Expand Down