Skip to content

Commit

Permalink
belindas-android_4_167_edit-user-role (#234)
Browse files Browse the repository at this point in the history
* new ind. page mockup

* Initial commit. Added Route.

* Storing 11.24

* Added datasource files and classes similar to products. Edit user role button leads to new screen. no data visible.

* Placeholder users show on EditUserRole.kt

* Edit Icon appears on user card.

* Two user cards display for each userRole type. Edit icon visible. non-functioning.

* Added scaffold & back arrow. EditUserRole.kt loads users each with edit icon. Added more users.

---------

Co-authored-by: Nickolas <[email protected]>
  • Loading branch information
Annelisebx and nickolasram authored Dec 6, 2023
1 parent 3df92a9 commit fea38e0
Show file tree
Hide file tree
Showing 8 changed files with 276 additions and 3 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ dependencies {
implementation 'androidx.compose.ui:ui'
implementation 'androidx.compose.ui:ui-graphics'
implementation 'androidx.compose.ui:ui-tooling-preview'
implementation 'androidx.recyclerview:recyclerview:1.3.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
Expand Down
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,5 +12,6 @@ sealed class Routes (val route: String) {
object IndividualProduct: Routes("Individual_Product")
object IndividualProductUpdatePage: Routes("Individual_Product_Update")
object AdminView: Routes("Admin_View")
object EditUserRole: Routes("Edit User Role")
object DonationInfo: Routes("Donation_Info")
}
67 changes: 67 additions & 0 deletions app/src/main/java/com/example/belindas_closet/data/Datasource.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,13 @@ import com.example.belindas_closet.model.ProductSizePantsWaist
import com.example.belindas_closet.model.ProductSizeShoes
import com.example.belindas_closet.model.ProductSizes
import com.example.belindas_closet.model.ProductType
import com.example.belindas_closet.model.User
import com.example.belindas_closet.model.UserRole

class Datasource {
private val productList = mutableListOf<Product>()
private val userList = mutableListOf<User>()


init {
productList.add(
Expand Down Expand Up @@ -195,9 +199,72 @@ class Datasource {
"9"
)
)

}
init {

// Adding Users to UserList
userList.add(
User(
userFirstName = "John",
userLastName = "Smith",
userEmail = "[email protected]",
UserRole.ADMIN,
userId = "1"
)
)
userList.add(
User(
userFirstName = "Alex",
userLastName = "Brown",
userEmail = "[email protected]",
UserRole.STANDARD,
userId = "2"
)
)
userList.add(
User(
userFirstName = "Jason",
userLastName = "Ni",
userEmail = "[email protected]",
UserRole.ADMIN,
userId = "3"
)
)
userList.add(
User(
userFirstName = "Kim",
userLastName = "Johnson",
userEmail = "[email protected]",
UserRole.ADMIN,
userId = "4"
)
)
userList.add(
User(
userFirstName = "Ellen",
userLastName = "Jones",
userEmail = "[email protected]",
UserRole.STANDARD,
userId = "5"
)
)
userList.add(
User(
userFirstName = "Taylor",
userLastName = "Wright",
userEmail = "[email protected]",
UserRole.STANDARD,
userId = "6"
)
)
}

fun loadProducts(): List<Product> {
return productList
}

fun loadUsers(): List<User> {
return userList
}
}
42 changes: 42 additions & 0 deletions app/src/main/java/com/example/belindas_closet/model/User.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.example.belindas_closet.model

import android.view.View
import com.example.belindas_closet.R

// saving template of product variables in case of editing user variables similarly
enum class UserRole(val userType: String) {
ADMIN("Admin"), STANDARD("Standard")
}
//
//// Shoes sizes
//enum class UserLastName(val size: Int?) {
// SELECT_SIZE(null), XS(5), S(6), M(7), L(8), XL(9), XXL(10), XXXL(11), XXXXL(12)
//}
//
//// General product sizes
//enum class UserEmail {
// SELECT_SIZE, XXS, XS, S, M, L, XL, XXL, XXXL, XXXXL
//}
//
//// productSizePantsWaist is nullable because not all products have a waist size
//enum class UserRole(val size: Int?) {
// SELECT_SIZE(null), XS(28), S(30), M(32), L(34), XL(36), XXL(38), XXXL(40), XXXXL(42)
//}


data class User(
val userFirstName: String,
val userLastName: String,
val userEmail: String,
val userRole: UserRole,
val userId: String = "0"
) {
companion object {
const val userFirstName: String = "User First Name"
const val userLastName: String = "User Last Name"
const val userEmail: String = "[email protected]"
val userRole: UserRole = UserRole.STANDARD
val userId: String ="00"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fun AdminView(navController: NavHostController) {
}
Button(
onClick = {
/*TODO add navigation logic to page to edit user roles*/
navController.navigate(Routes.EditUserRole.route)
},
modifier = Modifier
.padding(4.dp)
Expand Down
160 changes: 160 additions & 0 deletions app/src/main/java/com/example/belindas_closet/screen/EditUserRole.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package com.example.belindas_closet.screen

import androidx.compose.foundation.Image
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.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.items
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Edit
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
import androidx.compose.material3.Scaffold
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.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.TextUnit
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
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.data.Datasource
import com.example.belindas_closet.model.Product
import com.example.belindas_closet.model.ProductType
import com.example.belindas_closet.model.User
import com.example.belindas_closet.model.UserRole

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun EditUserRole(navController: NavController) {

Scaffold(
modifier = Modifier
.fillMaxSize(),
topBar = {
/* Back arrow that navigates back to login page */
TopAppBar(
title = { Text("Back") },
navigationIcon = {
IconButton(
onClick = {
navController.navigate(Routes.AdminView.route)
}
) {
Icon(
imageVector = Icons.Default.ArrowBack,
contentDescription = "Back to Home page"
)
}
}
)
}
) { innerPadding ->
val modifier = Modifier.padding(innerPadding)
Row(
modifier = Modifier
.size(125.dp)
.padding(top = 10.dp, start = 10.dp),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.Start
) {
NSCLogo()
}
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))
UserList(users = Datasource().loadUsers(), navController = navController)
}
}
}
}

@Composable
fun UserCard(user: User, navController: NavController) {
Card(
modifier = Modifier
/** To Do: Make clickable **/
/** To Do: Make clickable **/
) {
Column(
modifier = Modifier
.padding(16.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = user.userFirstName + " " + user.userLastName,
style = TextStyle(
fontSize = 15.sp,
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.Default,
),
modifier = Modifier
.wrapContentSize()
)
Text(
text = "Current Role: " + user.userRole,
style = TextStyle(
fontSize = 15.sp,
fontWeight = FontWeight.Bold,
fontFamily = FontFamily.Default,
),
modifier = Modifier
.wrapContentSize()
)
IconButton(
onClick = {
//TO DO: make icon functional and able to edit role.
}
) {
Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit")
}
}
}
}

@Composable
fun UserList(users: List<User>, navController: NavController) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(20.dp),
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
items(users) { User ->
UserCard(user = User, navController = navController)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ fun ProductTypeList(products: List<Product>, navController: NavController) {
verticalArrangement = Arrangement.Top,
horizontalAlignment = Alignment.CenterHorizontally
) {
items(typeList){productType ->
items(typeList){ productType ->
TypeCard(productType = productType, navController = navController)
Spacer(modifier = Modifier.padding(16.dp))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ fun ScreenMain() {
}
composable(Routes.ProductDetail.route) {
ProductDetailPage(navController = navController)

}
composable(Routes.Update.route) {
UpdatePage(navController = navController)
Expand All @@ -43,6 +42,9 @@ fun ScreenMain() {
composable(Routes.AdminView.route) {
AdminView(navController = navController)
}
composable(Routes.EditUserRole.route) {
EditUserRole(navController = navController)
}
composable(Routes.DonationInfo.route) {
DonationInfoPage(navController = navController)
}
Expand Down

0 comments on commit fea38e0

Please sign in to comment.