Skip to content

Commit

Permalink
add profile edit screen
Browse files Browse the repository at this point in the history
  • Loading branch information
X1nto committed Dec 28, 2023
1 parent 5e1a6a2 commit 93d5ac6
Show file tree
Hide file tree
Showing 18 changed files with 501 additions and 24 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 @@ -7,12 +7,13 @@ import dev.xinto.argos.ui.screen.course.page.scores.ScoresViewModel
import dev.xinto.argos.ui.screen.course.page.syllabus.SyllabusViewModel
import dev.xinto.argos.ui.screen.login.LoginViewModel
import dev.xinto.argos.ui.screen.main.MainViewModel
import dev.xinto.argos.ui.screen.main.dialog.user.UserViewModel
import dev.xinto.argos.ui.screen.main.dialog.user.UserInfoViewModel
import dev.xinto.argos.ui.screen.main.page.home.HomeViewModel
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 org.koin.androidx.viewmodel.dsl.viewModelOf
import org.koin.dsl.module

Expand All @@ -23,11 +24,12 @@ val UiModule = module {
viewModelOf(::MessagesViewModel)
viewModelOf(::NewsViewModel)
viewModelOf(::NotificationsViewModel)
viewModelOf(::UserViewModel)
viewModelOf(::UserInfoViewModel)
viewModelOf(::MessageViewModel)
viewModelOf(::SyllabusViewModel)
viewModelOf(::GroupsViewModel)
viewModelOf(::ScoresViewModel)
viewModelOf(::MaterialsViewModel)
viewModelOf(::ClassmatesViewModel)
viewModelOf(::UserViewModel)
}
11 changes: 11 additions & 0 deletions androidApp/src/main/java/dev/xinto/argos/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ 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.theme.ArgosTheme
import org.koin.android.ext.android.inject

Expand Down Expand Up @@ -76,6 +77,9 @@ class MainActivity : ComponentActivity() {
onNotificationsClick = {
rootNavController.navigate(ArgosNavigation.Notifications)
},
onUserClick = {
rootNavController.navigate(ArgosNavigation.User)
},
onMessageClick = { messageId, semesterId ->
rootNavController.navigate(
ArgosNavigation.Message(
Expand All @@ -96,6 +100,13 @@ class MainActivity : ComponentActivity() {
)
}

is ArgosNavigation.User -> {
UserScreen(
modifier = Modifier.fillMaxSize(),
onBackNavigate = rootNavController::pop
)
}

is ArgosNavigation.Message -> {
MessageScreen(
modifier = Modifier.fillMaxSize(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ sealed interface ArgosNavigation : Parcelable {
@Parcelize
data object Notifications : ArgosNavigation

@Parcelize
data object User : ArgosNavigation

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import org.koin.androidx.compose.getViewModel
@Composable
fun MainScreen(
onNotificationsClick: () -> Unit,
onUserClick: () -> Unit,
onMessageClick: (messageId: String, semesterId: String) -> Unit,
onCourseClick: (String) -> Unit,
modifier: Modifier = Modifier,
Expand All @@ -56,6 +57,7 @@ fun MainScreen(
state = state,
onNotificationsClick = onNotificationsClick,
onLogoutClick = viewModel::logout,
onUserClick = onUserClick,
onMessageClick = onMessageClick,
onCourseClick = onCourseClick
)
Expand All @@ -64,6 +66,7 @@ fun MainScreen(
@Composable
fun MainScreen(
onNotificationsClick: () -> Unit,
onUserClick: () -> Unit,
onLogoutClick: () -> Unit,
onMessageClick: (messageId: String, semesterId: String) -> Unit,
onCourseClick: (String) -> Unit,
Expand Down Expand Up @@ -118,6 +121,10 @@ fun MainScreen(
onDismiss = { userDialogShown = false },
onBalanceNavigate = { /*TODO*/ },
onLibraryNavigate = { /*TODO*/ },
onUserNavigate = {
userDialogShown = false
onUserClick()
},
onSettingsNavigate = { /*TODO*/ },
onLogoutClick = {
userDialogShown = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,18 @@ fun UserDialog(
onDismiss: () -> Unit,
onBalanceNavigate: () -> Unit,
onLibraryNavigate: () -> Unit,
onUserNavigate: () -> Unit,
onSettingsNavigate: () -> Unit,
onLogoutClick: () -> Unit,
) {
val viewModel: UserViewModel = getViewModel()
val viewModel: UserInfoViewModel = getViewModel()
val state by viewModel.state.collectAsStateWithLifecycle()
UserDialog(
state = state,
onDismiss = onDismiss,
onBalanceNavigate = onBalanceNavigate,
onLibraryNavigate = onLibraryNavigate,
onUserNavigate = onUserNavigate,
onSettingsNavigate = onSettingsNavigate,
onLogoutClick = onLogoutClick
)
Expand All @@ -57,10 +59,11 @@ fun UserDialog(
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun UserDialog(
state: UserState,
state: UserInfoState,
onDismiss: () -> Unit,
onBalanceNavigate: () -> Unit,
onLibraryNavigate: () -> Unit,
onUserNavigate: () -> Unit,
onSettingsNavigate: () -> Unit,
onLogoutClick: () -> Unit,
) {
Expand All @@ -83,7 +86,7 @@ fun UserDialog(
)
}
when (state) {
is UserState.Loading -> {
is UserInfoState.Loading -> {
Box(
modifier = Modifier.height(200.dp),
contentAlignment = Alignment.Center
Expand All @@ -92,7 +95,7 @@ fun UserDialog(
}
}

is UserState.Success -> {
is UserInfoState.Success -> {
Column(
modifier = Modifier
.fillMaxWidth()
Expand Down Expand Up @@ -142,6 +145,13 @@ fun UserDialog(
)
}
}
HorizontalSegmentedButton(onClick = onUserNavigate) {
Icon(
painter = painterResource(R.drawable.ic_account),
contentDescription = null
)
Text(stringResource(R.string.user_title))
}
HorizontalSegmentedButton(onClick = onSettingsNavigate) {
Icon(
painter = painterResource(R.drawable.ic_settings),
Expand All @@ -160,7 +170,7 @@ fun UserDialog(
}
}

is UserState.Error -> {
is UserInfoState.Error -> {

}
}
Expand All @@ -174,10 +184,11 @@ fun UserDialog(
fun UserDialog_Success_Preview() {
ArgosTheme {
UserDialog(
state = UserState.mockSuccess,
state = UserInfoState.mockSuccess,
onDismiss = {},
onLogoutClick = {},
onBalanceNavigate = {},
onUserNavigate = {},
onLibraryNavigate = {},
onSettingsNavigate = {}
)
Expand All @@ -189,10 +200,11 @@ fun UserDialog_Success_Preview() {
fun UserDialog_Loading_Preview() {
ArgosTheme {
UserDialog(
state = UserState.Loading,
state = UserInfoState.Loading,
onDismiss = {},
onLogoutClick = {},
onBalanceNavigate = {},
onUserNavigate = {},
onLibraryNavigate = {},
onSettingsNavigate = {}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,35 @@ import dev.xinto.argos.domain.user.DomainUserInfo
import dev.xinto.argos.domain.user.DomainUserState

@Immutable
sealed interface UserState {
sealed interface UserInfoState {

@Immutable
data object Loading : UserState
data object Loading : UserInfoState

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

@Immutable
data object Error : UserState
data object Error : UserInfoState

companion object {

val mockSuccess = Success(
userInfo = DomainUserInfo(
fullName = "Giorgi Giorgadze",
firstName = "Giorgi",
lastName = "Giorgadze",
birthDate = "01/01/2005",
idNumber = "00000000000",
email = "[email protected]",
mobileNumber1 = "(599) 99-99-99",
mobileNumber2 = "",
homeNumber = "",
currentAddress = "",
juridicalAddress = "",
photoUrl = null,
degree = 1
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn

class UserViewModel(
class UserInfoViewModel(
private val userRepository: UserRepository
) : ViewModel() {

Expand All @@ -18,18 +18,18 @@ class UserViewModel(
userRepository.getUserState().asFlow()
) { info, state -> info to state }.map {
when (it) {
is DomainResponse.Loading -> UserState.Loading
is DomainResponse.Success -> UserState.Success(
is DomainResponse.Loading -> UserInfoState.Loading
is DomainResponse.Success -> UserInfoState.Success(
userInfo = it.value.first,
userState = it.value.second
)

is DomainResponse.Error -> UserState.Error
is DomainResponse.Error -> UserInfoState.Error
}
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = UserState.Loading
initialValue = UserInfoState.Loading
)

}
Loading

0 comments on commit 93d5ac6

Please sign in to comment.