diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt
index e174ef2..64c7352 100644
--- a/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt
+++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/ButtonComposable.kt
@@ -8,6 +8,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.sp
@Composable
+
fun BasicTextButton(@StringRes text: Int, modifier: Modifier, action: () -> Unit) {
TextButton(onClick = action, modifier = modifier) { Text(text = stringResource(text)) }
}
diff --git a/app/src/main/java/be/ugent/sel/studeez/common/composable/TextFieldComposable.kt b/app/src/main/java/be/ugent/sel/studeez/common/composable/TextFieldComposable.kt
index 0a0765d..93c0463 100644
--- a/app/src/main/java/be/ugent/sel/studeez/common/composable/TextFieldComposable.kt
+++ b/app/src/main/java/be/ugent/sel/studeez/common/composable/TextFieldComposable.kt
@@ -1,6 +1,7 @@
package be.ugent.sel.studeez.common.composable
import androidx.annotation.StringRes
+import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.Icon
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.drawable as AppIcon
import androidx.compose.ui.Modifier
+import androidx.compose.ui.input.key.Key
import androidx.compose.ui.res.painterResource
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.PasswordVisualTransformation
import androidx.compose.ui.text.input.VisualTransformation
diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditScreen.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditScreen.kt
index 3b5b029..38fa4cf 100644
--- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditScreen.kt
+++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditScreen.kt
@@ -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()
+ }
}
}
}
diff --git a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditViewModel.kt b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditViewModel.kt
index 5f71016..6a31516 100644
--- a/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditViewModel.kt
+++ b/app/src/main/java/be/ugent/sel/studeez/screens/profile/ProfileEditViewModel.kt
@@ -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()
+ }
}
}
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 6590aa3..41083e7 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -5,9 +5,6 @@
Email
Password
Repeat password
- Something wrong happened. Please try again.
- Please insert a valid email.
- Try again
Go back
Menu
@@ -16,6 +13,12 @@
Save
Cancel
+
+ Saved successfully!
+ Try again
+ Something wrong happened. Please try again.
+ Please insert a valid email.
+
Create account
Your password should have at least six characters and include one digit, one lower case letter and one upper case letter.