#18 Working update username
This commit is contained in:
parent
8ad82dda43
commit
f263b34c12
5 changed files with 34 additions and 13 deletions
|
@ -1,16 +1,12 @@
|
|||
package be.ugent.sel.studeez.screens.profile
|
||||
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.material.Button
|
||||
import androidx.compose.material.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import androidx.hilt.navigation.compose.hiltViewModel
|
||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
||||
import be.ugent.sel.studeez.R
|
||||
import be.ugent.sel.studeez.common.composable.BasicButton
|
||||
import be.ugent.sel.studeez.common.composable.BasicTextButton
|
||||
import be.ugent.sel.studeez.common.composable.LabelledInputField
|
||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
||||
|
@ -36,8 +32,12 @@ fun EditProfileScreen(
|
|||
label = R.string.username
|
||||
)
|
||||
|
||||
BasicTextButton(text = R.string.save, Modifier.textButton()) {} // TODO
|
||||
BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {} // TODO
|
||||
BasicTextButton(text = R.string.save, Modifier.textButton()) {
|
||||
viewModel.onSaveClick()
|
||||
}
|
||||
BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {
|
||||
viewModel.onDeleteClick()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,31 +1,45 @@
|
|||
package be.ugent.sel.studeez.screens.profile
|
||||
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import be.ugent.sel.studeez.R
|
||||
import be.ugent.sel.studeez.common.snackbar.SnackbarManager
|
||||
import be.ugent.sel.studeez.domain.AccountDAO
|
||||
import be.ugent.sel.studeez.domain.LogService
|
||||
import be.ugent.sel.studeez.domain.UserDAO
|
||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||
import javax.inject.Inject
|
||||
|
||||
@HiltViewModel
|
||||
class ProfileEditViewModel @Inject constructor(
|
||||
private val accountDAO: AccountDAO,
|
||||
private val userDAO: UserDAO,
|
||||
logService: LogService
|
||||
) : StudeezViewModel(logService) {
|
||||
|
||||
var uiState = mutableStateOf(ProfileEditUiState())
|
||||
private set
|
||||
|
||||
private val username
|
||||
get() = uiState.value.username
|
||||
init {
|
||||
launchCatching {
|
||||
uiState.value = uiState.value.copy(username = userDAO.getUsername()!!)
|
||||
}
|
||||
}
|
||||
|
||||
fun onUsernameChange(newValue: String) {
|
||||
uiState.value = uiState.value.copy(username = newValue)
|
||||
}
|
||||
|
||||
fun onSaveClick() {
|
||||
// TODO
|
||||
launchCatching {
|
||||
userDAO.save(uiState.value.username)
|
||||
SnackbarManager.showMessage(R.string.save_success)
|
||||
}
|
||||
}
|
||||
|
||||
fun onDeleteClick() {
|
||||
// TODO
|
||||
launchCatching {
|
||||
accountDAO.deleteAccount()
|
||||
}
|
||||
}
|
||||
}
|
Reference in a new issue