Skip to content

Commit

Permalink
Show large avatar when clicked
Browse files Browse the repository at this point in the history
  • Loading branch information
nbradbury committed Oct 2, 2024
1 parent a6d9dec commit 55be759
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class SelfHostedUsersViewModel @Inject constructor(
@Named(UI_THREAD) mainDispatcher: CoroutineDispatcher,
) : ScopedViewModel(mainDispatcher) {
private val users = ArrayList<UserWithEditContext>()
private var selectedUser: UserWithEditContext? = null

private val _uiState = MutableStateFlow<SelfHostedUserState>(SelfHostedUserState.Loading)
val uiState = _uiState.asStateFlow()
Expand All @@ -46,15 +47,30 @@ class SelfHostedUsersViewModel @Inject constructor(
}

fun onCloseClick(context: Context) {
if (_uiState.value is SelfHostedUserState.UserDetail) {
_uiState.value = SelfHostedUserState.UserList(users)
} else {
(context as? Activity)?.finish()
when (_uiState.value) {
is SelfHostedUserState.UserDetail -> {
_uiState.value = SelfHostedUserState.UserList(users)
}

is SelfHostedUserState.UserAvatar -> {
_uiState.value = SelfHostedUserState.UserDetail(selectedUser!!)
}

else -> {
(context as? Activity)?.finish()
}
}
}

fun onUserClick(user: UserWithEditContext) {
_uiState.value = SelfHostedUserState.UserDetail(user)
selectedUser = user
_uiState.value = SelfHostedUserState.UserDetail(user)
}

fun onUserAvatarClick(user: UserWithEditContext) {
user.avatarUrls?.values?.firstOrNull()?.let { avatarUrl ->
_uiState.value = SelfHostedUserState.UserAvatar(avatarUrl)
}
}

sealed class SelfHostedUserState {
Expand All @@ -63,5 +79,6 @@ class SelfHostedUsersViewModel @Inject constructor(
data object EmptyUserList : SelfHostedUserState()
data class UserList(val users: List<UserWithEditContext>) : SelfHostedUserState()
data class UserDetail(val user: UserWithEditContext) : SelfHostedUserState()
data class UserAvatar(val avatarUrl: String) : SelfHostedUserState()
}
}

0 comments on commit 55be759

Please sign in to comment.