#18 Working update username
This commit is contained in:
parent
8ad82dda43
commit
f263b34c12
5 changed files with 34 additions and 13 deletions
|
@ -8,6 +8,7 @@ import androidx.compose.ui.res.stringResource
|
||||||
import androidx.compose.ui.unit.sp
|
import androidx.compose.ui.unit.sp
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|
||||||
fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) {
|
fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) {
|
||||||
TextButton(onClick = action, modifier = modifier) { Text(text = stringResource(text)) }
|
TextButton(onClick = action, modifier = modifier) { Text(text = stringResource(text)) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package be.ugent.sel.studeez.common.composable
|
package be.ugent.sel.studeez.common.composable
|
||||||
|
|
||||||
import androidx.annotation.StringRes
|
import androidx.annotation.StringRes
|
||||||
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.material.Icon
|
import androidx.compose.material.Icon
|
||||||
import androidx.compose.material.IconButton
|
import androidx.compose.material.IconButton
|
||||||
|
@ -14,8 +15,10 @@ import androidx.compose.runtime.*
|
||||||
import be.ugent.sel.studeez.R.string as AppText
|
import be.ugent.sel.studeez.R.string as AppText
|
||||||
import be.ugent.sel.studeez.R.drawable as AppIcon
|
import be.ugent.sel.studeez.R.drawable as AppIcon
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.input.key.Key
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
import androidx.compose.ui.text.input.ImeAction
|
||||||
import androidx.compose.ui.text.input.KeyboardType
|
import androidx.compose.ui.text.input.KeyboardType
|
||||||
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
import androidx.compose.ui.text.input.PasswordVisualTransformation
|
||||||
import androidx.compose.ui.text.input.VisualTransformation
|
import androidx.compose.ui.text.input.VisualTransformation
|
||||||
|
|
|
@ -1,16 +1,12 @@
|
||||||
package be.ugent.sel.studeez.screens.profile
|
package be.ugent.sel.studeez.screens.profile
|
||||||
|
|
||||||
import androidx.compose.foundation.layout.Column
|
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.Composable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.tooling.preview.Preview
|
import androidx.compose.ui.tooling.preview.Preview
|
||||||
import androidx.hilt.navigation.compose.hiltViewModel
|
import androidx.hilt.navigation.compose.hiltViewModel
|
||||||
import androidx.lifecycle.viewmodel.compose.viewModel
|
|
||||||
import be.ugent.sel.studeez.R
|
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.BasicTextButton
|
||||||
import be.ugent.sel.studeez.common.composable.LabelledInputField
|
import be.ugent.sel.studeez.common.composable.LabelledInputField
|
||||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
|
||||||
|
@ -36,8 +32,12 @@ fun EditProfileScreen(
|
||||||
label = R.string.username
|
label = R.string.username
|
||||||
)
|
)
|
||||||
|
|
||||||
BasicTextButton(text = R.string.save, Modifier.textButton()) {} // TODO
|
BasicTextButton(text = R.string.save, Modifier.textButton()) {
|
||||||
BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {} // TODO
|
viewModel.onSaveClick()
|
||||||
|
}
|
||||||
|
BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {
|
||||||
|
viewModel.onDeleteClick()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,45 @@
|
||||||
package be.ugent.sel.studeez.screens.profile
|
package be.ugent.sel.studeez.screens.profile
|
||||||
|
|
||||||
import androidx.compose.runtime.mutableStateOf
|
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.LogService
|
||||||
|
import be.ugent.sel.studeez.domain.UserDAO
|
||||||
import be.ugent.sel.studeez.screens.StudeezViewModel
|
import be.ugent.sel.studeez.screens.StudeezViewModel
|
||||||
import dagger.hilt.android.lifecycle.HiltViewModel
|
import dagger.hilt.android.lifecycle.HiltViewModel
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@HiltViewModel
|
@HiltViewModel
|
||||||
class ProfileEditViewModel @Inject constructor(
|
class ProfileEditViewModel @Inject constructor(
|
||||||
|
private val accountDAO: AccountDAO,
|
||||||
|
private val userDAO: UserDAO,
|
||||||
logService: LogService
|
logService: LogService
|
||||||
) : StudeezViewModel(logService) {
|
) : StudeezViewModel(logService) {
|
||||||
|
|
||||||
var uiState = mutableStateOf(ProfileEditUiState())
|
var uiState = mutableStateOf(ProfileEditUiState())
|
||||||
private set
|
private set
|
||||||
|
|
||||||
private val username
|
init {
|
||||||
get() = uiState.value.username
|
launchCatching {
|
||||||
|
uiState.value = uiState.value.copy(username = userDAO.getUsername()!!)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun onUsernameChange(newValue: String) {
|
fun onUsernameChange(newValue: String) {
|
||||||
uiState.value = uiState.value.copy(username = newValue)
|
uiState.value = uiState.value.copy(username = newValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onSaveClick() {
|
fun onSaveClick() {
|
||||||
// TODO
|
launchCatching {
|
||||||
|
userDAO.save(uiState.value.username)
|
||||||
|
SnackbarManager.showMessage(R.string.save_success)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onDeleteClick() {
|
fun onDeleteClick() {
|
||||||
// TODO
|
launchCatching {
|
||||||
|
accountDAO.deleteAccount()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -5,9 +5,6 @@
|
||||||
<string name="email">Email</string>
|
<string name="email">Email</string>
|
||||||
<string name="password">Password</string>
|
<string name="password">Password</string>
|
||||||
<string name="repeat_password">Repeat password</string>
|
<string name="repeat_password">Repeat password</string>
|
||||||
<string name="generic_error">Something wrong happened. Please try again.</string>
|
|
||||||
<string name="email_error">Please insert a valid email.</string>
|
|
||||||
<string name="try_again">Try again</string>
|
|
||||||
<string name="go_back">Go back</string>
|
<string name="go_back">Go back</string>
|
||||||
<string name="menu">Menu</string>
|
<string name="menu">Menu</string>
|
||||||
|
|
||||||
|
@ -16,6 +13,12 @@
|
||||||
<string name="save">Save</string>
|
<string name="save">Save</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
|
|
||||||
|
<!-- Messages -->
|
||||||
|
<string name="save_success">Saved successfully!</string>
|
||||||
|
<string name="try_again">Try again</string>
|
||||||
|
<string name="generic_error">Something wrong happened. Please try again.</string>
|
||||||
|
<string name="email_error">Please insert a valid email.</string>
|
||||||
|
|
||||||
<!-- SignUpScreen -->
|
<!-- SignUpScreen -->
|
||||||
<string name="create_account">Create account</string>
|
<string name="create_account">Create account</string>
|
||||||
<string name="password_error">Your password should have at least six characters and include one digit, one lower case letter and one upper case letter.</string>
|
<string name="password_error">Your password should have at least six characters and include one digit, one lower case letter and one upper case letter.</string>
|
||||||
|
|
Reference in a new issue