Merge branch 'development' into timers
This commit is contained in:
		
						commit
						ce001898fd
					
				
					 17 changed files with 229 additions and 38 deletions
				
			
		| 
						 | 
				
			
			@ -1,5 +1,9 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.home
 | 
			
		||||
 | 
			
		||||
import androidx.compose.material.Icon
 | 
			
		||||
import androidx.compose.material.IconButton
 | 
			
		||||
import androidx.compose.material.icons.Icons
 | 
			
		||||
import androidx.compose.material.icons.filled.Person
 | 
			
		||||
import androidx.compose.runtime.Composable
 | 
			
		||||
import androidx.compose.ui.Modifier
 | 
			
		||||
import androidx.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
| 
						 | 
				
			
			@ -18,10 +22,21 @@ fun HomeScreen(
 | 
			
		|||
    PrimaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.home),
 | 
			
		||||
        open = open,
 | 
			
		||||
        openAndPopUp = openAndPopUp
 | 
			
		||||
        openAndPopUp = openAndPopUp,
 | 
			
		||||
        action = { FriendsAction() }
 | 
			
		||||
    ) {
 | 
			
		||||
        BasicButton(R.string.start_session, Modifier.basicButton()) {
 | 
			
		||||
            viewModel.onStartSessionClick(open)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun FriendsAction () {
 | 
			
		||||
    IconButton(onClick = { /*TODO*/ }) {
 | 
			
		||||
        Icon(
 | 
			
		||||
            imageVector = Icons.Default.Person,
 | 
			
		||||
            contentDescription = resources().getString(R.string.friends)
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -2,7 +2,6 @@ package be.ugent.sel.studeez.screens.navbar
 | 
			
		|||
 | 
			
		||||
import be.ugent.sel.studeez.domain.AccountDAO
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.HOME_SCREEN
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations.PROFILE_SCREEN
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,55 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.profile
 | 
			
		||||
 | 
			
		||||
import androidx.compose.foundation.layout.Column
 | 
			
		||||
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 be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.BasicTextButton
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.LabelledInputField
 | 
			
		||||
import be.ugent.sel.studeez.common.composable.SecondaryScreenTemplate
 | 
			
		||||
import be.ugent.sel.studeez.common.ext.textButton
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.ui.theme.StudeezTheme
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun EditProfileScreen(
 | 
			
		||||
    goBack: () -> Unit,
 | 
			
		||||
    openAndPopUp: (String, String) -> Unit,
 | 
			
		||||
    viewModel: ProfileEditViewModel = hiltViewModel()
 | 
			
		||||
) {
 | 
			
		||||
    val uiState by viewModel.uiState
 | 
			
		||||
 | 
			
		||||
    SecondaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(R.string.editing_profile),
 | 
			
		||||
        popUp = goBack
 | 
			
		||||
    ) {
 | 
			
		||||
        Column {
 | 
			
		||||
            LabelledInputField(
 | 
			
		||||
                value = uiState.username,
 | 
			
		||||
                onNewValue = viewModel::onUsernameChange,
 | 
			
		||||
                label = R.string.username
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
            BasicTextButton(text = R.string.save, Modifier.textButton()) {
 | 
			
		||||
                viewModel.onSaveClick()
 | 
			
		||||
            }
 | 
			
		||||
            BasicTextButton(text = R.string.delete_profile, Modifier.textButton()) {
 | 
			
		||||
                viewModel.onDeleteClick(openAndPopUp)
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Preview
 | 
			
		||||
@Composable
 | 
			
		||||
fun EditProfileScreenComposable() {
 | 
			
		||||
    StudeezTheme {
 | 
			
		||||
        EditProfileScreen (
 | 
			
		||||
            {},
 | 
			
		||||
            {_, _ -> {}}
 | 
			
		||||
        )
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.profile
 | 
			
		||||
 | 
			
		||||
data class ProfileEditUiState (
 | 
			
		||||
    val username: String = ""
 | 
			
		||||
)
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,48 @@
 | 
			
		|||
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.navigation.StudeezDestinations
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
    init {
 | 
			
		||||
        launchCatching {
 | 
			
		||||
            uiState.value = uiState.value.copy(username = userDAO.getUsername()!!)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onUsernameChange(newValue: String) {
 | 
			
		||||
        uiState.value = uiState.value.copy(username = newValue)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onSaveClick() {
 | 
			
		||||
        launchCatching {
 | 
			
		||||
            userDAO.save(uiState.value.username)
 | 
			
		||||
            SnackbarManager.showMessage(R.string.success)
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onDeleteClick(openAndPopUp: (String, String) -> Unit) {
 | 
			
		||||
        launchCatching {
 | 
			
		||||
            userDAO.deleteUserReferences() // Delete references
 | 
			
		||||
            accountDAO.deleteAccount() // Delete authentication
 | 
			
		||||
        }
 | 
			
		||||
        openAndPopUp(StudeezDestinations.SIGN_UP_SCREEN, StudeezDestinations.EDIT_PROFILE_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,5 +1,9 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.profile
 | 
			
		||||
 | 
			
		||||
import androidx.compose.material.Icon
 | 
			
		||||
import androidx.compose.material.IconButton
 | 
			
		||||
import androidx.compose.material.icons.Icons
 | 
			
		||||
import androidx.compose.material.icons.filled.Edit
 | 
			
		||||
import androidx.compose.runtime.*
 | 
			
		||||
import androidx.hilt.navigation.compose.hiltViewModel
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
| 
						 | 
				
			
			@ -22,8 +26,22 @@ fun ProfileScreen(
 | 
			
		|||
    PrimaryScreenTemplate(
 | 
			
		||||
        title = resources().getString(AppText.profile),
 | 
			
		||||
        open = open,
 | 
			
		||||
        openAndPopUp = openAndPopUp
 | 
			
		||||
        openAndPopUp = openAndPopUp,
 | 
			
		||||
        action = { EditAction { viewModel.onEditProfileClick(open) } }
 | 
			
		||||
    ) {
 | 
			
		||||
        Headline(text = (username ?: resources().getString(R.string.no_username)))
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@Composable
 | 
			
		||||
fun EditAction(
 | 
			
		||||
    onClick: () -> Unit
 | 
			
		||||
) {
 | 
			
		||||
    IconButton(onClick = onClick) {
 | 
			
		||||
        Icon(
 | 
			
		||||
            imageVector = Icons.Default.Edit,
 | 
			
		||||
            contentDescription = resources().getString(AppText.edit_profile)
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -1,20 +1,10 @@
 | 
			
		|||
package be.ugent.sel.studeez.screens.profile
 | 
			
		||||
 | 
			
		||||
import androidx.compose.runtime.rememberCoroutineScope
 | 
			
		||||
import androidx.lifecycle.viewModelScope
 | 
			
		||||
import be.ugent.sel.studeez.R
 | 
			
		||||
import be.ugent.sel.studeez.domain.LogService
 | 
			
		||||
import be.ugent.sel.studeez.domain.UserDAO
 | 
			
		||||
import be.ugent.sel.studeez.resources
 | 
			
		||||
import be.ugent.sel.studeez.navigation.StudeezDestinations
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import kotlinx.coroutines.CoroutineScope
 | 
			
		||||
import kotlinx.coroutines.coroutineScope
 | 
			
		||||
import kotlinx.coroutines.flow.SharingStarted
 | 
			
		||||
import kotlinx.coroutines.flow.StateFlow
 | 
			
		||||
import kotlinx.coroutines.flow.map
 | 
			
		||||
import kotlinx.coroutines.flow.stateIn
 | 
			
		||||
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
 | 
			
		||||
@HiltViewModel
 | 
			
		||||
| 
						 | 
				
			
			@ -27,4 +17,8 @@ class ProfileViewModel @Inject constructor(
 | 
			
		|||
        return userDAO.getUsername()
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fun onEditProfileClick(open: (String) -> Unit) {
 | 
			
		||||
        open(StudeezDestinations.EDIT_PROFILE_SCREEN)
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -13,11 +13,8 @@ import be.ugent.sel.studeez.navigation.StudeezDestinations.LOGIN_SCREEN
 | 
			
		|||
import be.ugent.sel.studeez.navigation.StudeezDestinations.SIGN_UP_SCREEN
 | 
			
		||||
import be.ugent.sel.studeez.screens.StudeezViewModel
 | 
			
		||||
import dagger.hilt.android.lifecycle.HiltViewModel
 | 
			
		||||
import kotlinx.coroutines.flow.FlowCollector
 | 
			
		||||
import kotlinx.coroutines.flow.first
 | 
			
		||||
import kotlinx.coroutines.flow.take
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
import javax.inject.Inject
 | 
			
		||||
import be.ugent.sel.studeez.R.string as AppText
 | 
			
		||||
 | 
			
		||||
@HiltViewModel
 | 
			
		||||
class SignUpViewModel @Inject constructor(
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue