Skip to content

Commit

Permalink
Add user profile screen and rename the user screen to me user profile…
Browse files Browse the repository at this point in the history
… screen to avoid confusion
  • Loading branch information
X1nto committed Jan 3, 2024
1 parent 5428dc0 commit f4ffd70
Show file tree
Hide file tree
Showing 27 changed files with 474 additions and 108 deletions.
6 changes: 4 additions & 2 deletions androidApp/src/main/java/dev/xinto/argos/di/UiModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import dev.xinto.argos.ui.screen.main.page.messages.MessagesViewModel
import dev.xinto.argos.ui.screen.main.page.news.NewsViewModel
import dev.xinto.argos.ui.screen.message.MessageViewModel
import dev.xinto.argos.ui.screen.notifications.NotificationsViewModel
import dev.xinto.argos.ui.screen.user.UserViewModel
import dev.xinto.argos.ui.screen.meuserprofile.MeUserProfileViewModel
import dev.xinto.argos.ui.screen.userprofile.UserProfileViewModel
import org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module

Expand All @@ -31,5 +32,6 @@ val UiModule = module {
viewModelOf(::ScoresViewModel)
viewModelOf(::MaterialsViewModel)
viewModelOf(::ClassmatesViewModel)
viewModelOf(::UserViewModel)
viewModelOf(::MeUserProfileViewModel)
viewModelOf(::UserProfileViewModel)
}
20 changes: 16 additions & 4 deletions androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ import dev.xinto.argos.ui.screen.login.LoginScreen
import dev.xinto.argos.ui.screen.main.MainScreen
import dev.xinto.argos.ui.screen.message.MessageScreen
import dev.xinto.argos.ui.screen.notifications.NotificationsScreen
import dev.xinto.argos.ui.screen.user.UserScreen
import dev.xinto.argos.ui.screen.meuserprofile.MeUserProfileScreen
import dev.xinto.argos.ui.screen.userprofile.UserProfileScreen
import dev.xinto.argos.ui.theme.ArgosTheme
import org.koin.android.ext.android.inject

Expand Down Expand Up @@ -78,7 +79,7 @@ class MainActivity : ComponentActivity() {
rootNavController.navigate(ArgosNavigation.Notifications)
},
onUserClick = {
rootNavController.navigate(ArgosNavigation.User)
rootNavController.navigate(ArgosNavigation.MeUserProfile)
},
onMessageClick = { messageId, semesterId ->
rootNavController.navigate(
Expand All @@ -100,8 +101,8 @@ class MainActivity : ComponentActivity() {
)
}

is ArgosNavigation.User -> {
UserScreen(
is ArgosNavigation.MeUserProfile -> {
MeUserProfileScreen(
modifier = Modifier.fillMaxSize(),
onBackNavigate = rootNavController::pop
)
Expand All @@ -120,6 +121,17 @@ class MainActivity : ComponentActivity() {
CourseScreen(
modifier = Modifier.fillMaxSize(),
courseId = destination.id,
onBackClick = rootNavController::pop,
onUserClick = {
rootNavController.navigate(ArgosNavigation.UserProfile(it))
}
)
}

is ArgosNavigation.UserProfile -> {
UserProfileScreen(
userId = destination.id,
modifier = Modifier.fillMaxSize(),
onBackClick = rootNavController::pop
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ sealed interface ArgosNavigation : Parcelable {
data object Notifications : ArgosNavigation

@Parcelize
data object User : ArgosNavigation
data object MeUserProfile : ArgosNavigation

@Parcelize
data class Message(val id: String, val semesterId: String) : ArgosNavigation

@Parcelize
data class Course(val id: String) : ArgosNavigation

@Parcelize
data class UserProfile(val id: String) : ArgosNavigation

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ import dev.xinto.argos.ui.screen.course.page.syllabus.SyllabusPage
@Composable
fun CourseScreen(
modifier: Modifier = Modifier,
onUserClick: (String) -> Unit,
onBackClick: () -> Unit,
courseId: String,
onBackClick: () -> Unit
) {
BackHandler(onBack = onBackClick)

Expand Down Expand Up @@ -105,7 +106,8 @@ fun CourseScreen(
is CourseNavigation.Classmates -> {
ClassmatesPage(
courseId = courseId,
modifier = Modifier.fillMaxSize()
modifier = Modifier.fillMaxSize(),
onClassmateClick = onUserClick
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import org.koin.androidx.compose.getStateViewModel
@Composable
fun ClassmatesPage(
modifier: Modifier = Modifier,
onClassmateClick: (String) -> Unit,
courseId: String
) {
val viewModel: ClassmatesViewModel = getStateViewModel(state = {
Expand All @@ -35,13 +36,15 @@ fun ClassmatesPage(
val state by viewModel.state.collectAsStateWithLifecycle()
ClassmatesPage(
state = state,
modifier = modifier
modifier = modifier,
onClassmateClick = onClassmateClick
)
}

@Composable
fun ClassmatesPage(
modifier: Modifier = Modifier,
onClassmateClick: (String) -> Unit,
state: ClassmatesState
) {
Box(
Expand All @@ -62,16 +65,16 @@ fun ClassmatesPage(
itemsSegmented(
items = state.classmates,
key = { it.uuid }
) { type, item ->
) { type, classmate ->
SegmentedListItem(
type = type,
headlineContent = {
Text(item.fullName)
Text(classmate.fullName)
},
leadingContent = {
UserImage(
modifier = Modifier.size(40.dp),
url = item.photoUrl
url = classmate.photoUrl
)
},
trailingContent = {
Expand All @@ -81,6 +84,9 @@ fun ClassmatesPage(
contentDescription = null
)
}
},
onClick = {
onClassmateClick(classmate.uuid)
}
)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.xinto.argos.ui.screen.main

import androidx.compose.runtime.Immutable
import dev.xinto.argos.domain.user.DomainUserInfo
import dev.xinto.argos.domain.user.DomainUserState
import dev.xinto.argos.domain.user.DomainMeUserInfo
import dev.xinto.argos.domain.user.DomainMeUserState

@Immutable
sealed interface MainState {
Expand All @@ -11,8 +11,8 @@ sealed interface MainState {
data object Loading : MainState

data class Success(
val userInfo: DomainUserInfo,
val userState: DomainUserState
val userInfo: DomainMeUserInfo,
val userState: DomainMeUserState
) : MainState

data object Error : MainState
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class MainViewModel(
private val userRepository: UserRepository
) : ViewModel() {

private val userInfo = userRepository.getUserInfo()
private val userState = userRepository.getUserState()
private val meUserInfo = userRepository.getMeUserInfo()
private val meUserState = userRepository.getMeUserState()

val state = combine(userInfo.asFlow(), userState.asFlow()) { info, state ->
val state = combine(meUserInfo.asFlow(), meUserState.asFlow()) { info, state ->
info to state
}.map {
when (it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fun UserDialog(
painter = painterResource(R.drawable.ic_account),
contentDescription = null
)
Text(stringResource(R.string.user_title))
Text(stringResource(R.string.meuserprofile_title))
}
HorizontalSegmentedButton(onClick = onSettingsNavigate) {
Icon(
Expand All @@ -164,7 +164,7 @@ fun UserDialog(
painter = painterResource(R.drawable.ic_logout),
contentDescription = null
)
Text(stringResource(R.string.user_action_logout))
Text(stringResource(R.string.meuserprofile_action_logout))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package dev.xinto.argos.ui.screen.main.dialog.user

import androidx.compose.runtime.Immutable
import dev.xinto.argos.domain.user.DomainUserInfo
import dev.xinto.argos.domain.user.DomainUserState
import dev.xinto.argos.domain.user.DomainMeUserInfo
import dev.xinto.argos.domain.user.DomainMeUserState

@Immutable
sealed interface UserInfoState {
Expand All @@ -12,8 +12,8 @@ sealed interface UserInfoState {

@Immutable
data class Success(
val userInfo: DomainUserInfo,
val userState: DomainUserState
val userInfo: DomainMeUserInfo,
val userState: DomainMeUserState
) : UserInfoState

@Immutable
Expand All @@ -22,7 +22,7 @@ sealed interface UserInfoState {
companion object {

val mockSuccess = Success(
userInfo = DomainUserInfo(
userInfo = DomainMeUserInfo(
fullName = "Giorgi Giorgadze",
firstName = "Giorgi",
lastName = "Giorgadze",
Expand All @@ -37,7 +37,7 @@ sealed interface UserInfoState {
photoUrl = null,
degree = 1
),
userState = DomainUserState(
userState = DomainMeUserState(
billingBalance = "562.50₾",
libraryBalance = "0",
newsUnread = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class UserInfoViewModel(
) : ViewModel() {

val state = combine(
userRepository.getUserInfo().asFlow(),
userRepository.getUserState().asFlow()
userRepository.getMeUserInfo().asFlow(),
userRepository.getMeUserState().asFlow()
) { info, state -> info to state }.map {
when (it) {
is DomainResponse.Loading -> UserInfoState.Loading
Expand Down
Loading

0 comments on commit f4ffd70

Please sign in to comment.