Skip to content

Commit

Permalink
Merge pull request #212 from skniyajali/159-enhancement-profile
Browse files Browse the repository at this point in the history
Enhancement - Profile Screen
  • Loading branch information
niyajali authored Apr 8, 2024
2 parents 8067efc + 45be490 commit 052d50e
Show file tree
Hide file tree
Showing 7 changed files with 499 additions and 131 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import com.niyaj.common.tags.ProfileTestTags.TAG_EMPTY_ERROR
import com.niyaj.common.utils.Resource
import com.niyaj.common.utils.ValidationResult
import com.niyaj.common.utils.isValidPassword
import com.niyaj.data.mapper.toEntity
import com.niyaj.data.repository.RestaurantInfoRepository
import com.niyaj.data.repository.validation.RestaurantInfoValidationRepository
import com.niyaj.database.model.RestaurantInfoEntity
Expand Down Expand Up @@ -87,7 +88,7 @@ class RestaurantInfoRepositoryImpl(
restaurant.logo = imageName
restaurant.updatedAt = System.currentTimeMillis().toString()
} else {
val newRestaurant = RestaurantInfoEntity()
val newRestaurant = RestaurantInfo().toEntity()
newRestaurant.restaurantId = RESTAURANT_ID
newRestaurant.logo = imageName
newRestaurant.createdAt = System.currentTimeMillis().toString()
Expand Down Expand Up @@ -115,7 +116,7 @@ class RestaurantInfoRepositoryImpl(
restaurant.printLogo = imageName
restaurant.updatedAt = System.currentTimeMillis().toString()
} else {
val newRestaurant = RestaurantInfoEntity()
val newRestaurant = RestaurantInfo().toEntity()
newRestaurant.restaurantId = RESTAURANT_ID
newRestaurant.printLogo = imageName
newRestaurant.createdAt = System.currentTimeMillis().toString()
Expand Down
1 change: 1 addition & 0 deletions core/ui/src/main/java/com/niyaj/ui/util/Screens.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ object Screens {
const val HOME_SCREEN = "home_screen"

const val PROFILE_SCREEN = "profile_screen"
const val UPDATE_PROFILE_SCREEN = "update_profile_screen"

const val CART_SCREEN = "cart_screen"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.material.FabPosition
import androidx.compose.material.Icon
import androidx.compose.material.IconButton
import androidx.compose.material.Scaffold
import androidx.compose.material.ScaffoldState
import androidx.compose.material.Text
import androidx.compose.material.TopAppBar
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
import androidx.compose.material.icons.filled.Edit
import androidx.compose.material.icons.filled.Password
import androidx.compose.runtime.Composable
Expand All @@ -29,6 +32,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.navigation.NavController
Expand All @@ -44,12 +48,9 @@ import com.niyaj.feature.profile.components.RestaurantCard
import com.niyaj.feature.profile.destinations.UpdateProfileScreenDestination
import com.niyaj.model.RESTAURANT_LOGO_NAME
import com.niyaj.model.RESTAURANT_PRINT_LOGO_NAME
import com.niyaj.ui.components.ScrollToTop
import com.niyaj.ui.components.SettingsCard
import com.niyaj.ui.components.StandardScaffoldNew
import com.niyaj.ui.event.UiEvent
import com.niyaj.ui.util.Screens
import com.niyaj.ui.util.isScrolled
import com.ramcosta.composedestinations.annotation.Destination
import com.ramcosta.composedestinations.annotation.RootNavGraph
import com.ramcosta.composedestinations.navigation.navigate
Expand Down Expand Up @@ -179,39 +180,43 @@ fun ProfileScreen(
}
}


StandardScaffoldNew(
navController = navController,
Scaffold(
modifier = Modifier
.fillMaxSize(),
scaffoldState = scaffoldState,
showBackButton = true,
selectionCount = 0,
title = PROFILE_SCREEN,
navActions = {
IconButton(
onClick = {
navController.navigate(UpdateProfileScreenDestination())
}
) {
Icon(imageVector = Icons.Default.Edit, contentDescription = "Edit Profile")
}
},
showFab = true,
floatingActionButton = {
ScrollToTop(
visible = lazyListState.isScrolled,
onClick = {
scope.launch {
lazyListState.animateScrollToItem(index = 0)
topBar = {
TopAppBar(
title = { Text(text = PROFILE_SCREEN) },
navigationIcon = {
IconButton(
onClick = { navController.navigateUp() }
) {
Icon(
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
contentDescription = "Navigate Back"
)
}
},
actions = {
IconButton(
onClick = {
navController.navigate(UpdateProfileScreenDestination())
}
) {
Icon(
imageVector = Icons.Default.Edit,
contentDescription = "Edit Profile"
)
}
},
elevation = 0.dp
)
},
fabPosition = FabPosition.End,
}
) {
LazyColumn(
modifier = Modifier
.fillMaxSize()
.padding(SpaceSmall)
.padding(it)
.background(LightColor6),
state = lazyListState,
verticalArrangement = Arrangement.spacedBy(SpaceSmall)
Expand Down Expand Up @@ -241,11 +246,15 @@ fun ProfileScreen(
}

item("Account Info") {
AccountInfo(account = accountInfo)
AccountInfo(
modifier = Modifier.padding(SpaceSmall),
account = accountInfo
)
}

item("Change Password") {
SettingsCard(
modifier = Modifier.padding(SpaceSmall),
text = "Change Password",
icon = Icons.Default.Password
) {
Expand All @@ -256,6 +265,4 @@ fun ProfileScreen(
}
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -158,37 +158,32 @@ class ProfileViewModel @Inject constructor(
val validatedName = validation.validateRestaurantName(updateState.name)
val validatedTagLine = validation.validateRestaurantTagline(updateState.tagline)
val validatedEmail = validation.validateRestaurantEmail(updateState.email)
val validatedPrimaryPhone =
validation.validatePrimaryPhone(updateState.primaryPhone)
val validatedSecondaryPhone =
validation.validateSecondaryPhone(updateState.secondaryPhone)
val validatedPPhone = validation.validatePrimaryPhone(updateState.primaryPhone)
val validatedSPhone = validation.validateSecondaryPhone(updateState.secondaryPhone)
val validatedAddress = validation.validateRestaurantAddress(updateState.address)
val validatedPaymentQrCode =
validation.validatePaymentQrCode(updateState.paymentQrCode)
val validatedDesc =
validation.validatePaymentQrCode(updateState.description)

val validatedQrCode = validation.validatePaymentQrCode(updateState.paymentQrCode)
val validatedDesc = validation.validatePaymentQrCode(updateState.description)

val hasError = listOf(
validatedName,
validatedTagLine,
validatedEmail,
validatedPrimaryPhone,
validatedSecondaryPhone,
validatedPPhone,
validatedSPhone,
validatedAddress,
validatedDesc,
validatedPaymentQrCode
validatedQrCode
).any { !it.successful }

if (hasError) {
updateState = updateState.copy(
nameError = validatedName.errorMessage,
taglineError = validatedTagLine.errorMessage,
emailError = validatedEmail.errorMessage,
primaryPhoneError = validatedPrimaryPhone.errorMessage,
secondaryPhoneError = validatedSecondaryPhone.errorMessage,
primaryPhoneError = validatedPPhone.errorMessage,
secondaryPhoneError = validatedSPhone.errorMessage,
addressError = validatedAddress.errorMessage,
paymentQrCodeError = validatedPaymentQrCode.errorMessage,
paymentQrCodeError = validatedQrCode.errorMessage,
descriptionError = validatedDesc.errorMessage
)

Expand Down
Loading

0 comments on commit 052d50e

Please sign in to comment.