diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/data/di/ConnectivityManagerModule.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/data/di/ConnectivityManagerModule.kt index 214015fd..a4780d50 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/data/di/ConnectivityManagerModule.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/data/di/ConnectivityManagerModule.kt @@ -12,10 +12,11 @@ import javax.inject.Singleton @Module @InstallIn(SingletonComponent::class) object ConnectivityManagerModule { - @Singleton @Provides - fun provideConnectivityManager(@ApplicationContext context: Context): ConnectivityManager { + fun provideConnectivityManager( + @ApplicationContext context: Context, + ): ConnectivityManager { return context.getSystemService(ConnectivityManager::class.java) } } diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/NetworkManager.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/NetworkManager.kt index 1f26554b..9df3a032 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/NetworkManager.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/data/network/NetworkManager.kt @@ -9,31 +9,34 @@ import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import javax.inject.Inject -class NetworkManager @Inject constructor(private val connectivityManager: ConnectivityManager) { - - private val _isConnected = MutableStateFlow(false) - val isConnected: StateFlow = _isConnected - - private val request: NetworkRequest = NetworkRequest.Builder() - .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) - .addCapability(NET_CAPABILITY_INTERNET) - .build() - - private val networkCallback = object : ConnectivityManager.NetworkCallback() { - override fun onAvailable(network: Network) { - _isConnected.value = true +class NetworkManager + @Inject + constructor(private val connectivityManager: ConnectivityManager) { + private val _isConnected = MutableStateFlow(false) + val isConnected: StateFlow = _isConnected + + private val request: NetworkRequest = + NetworkRequest.Builder() + .addCapability(NetworkCapabilities.NET_CAPABILITY_NOT_METERED) + .addCapability(NET_CAPABILITY_INTERNET) + .build() + + private val networkCallback = + object : ConnectivityManager.NetworkCallback() { + override fun onAvailable(network: Network) { + _isConnected.value = true + } + + override fun onLost(network: Network) { + _isConnected.value = false + } + } + + fun registerNetworkCallback() { + connectivityManager.registerNetworkCallback(request, networkCallback) } - override fun onLost(network: Network) { - _isConnected.value = false + fun unRegisterNetworkCallback() { + connectivityManager.unregisterNetworkCallback(networkCallback) } } - - fun registerNetworkCallback() { - connectivityManager.registerNetworkCallback(request, networkCallback) - } - - fun unRegisterNetworkCallback() { - connectivityManager.unregisterNetworkCallback(networkCallback) - } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/base/BaseActivityViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/base/BaseActivityViewModel.kt index dde590d1..280773f2 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/base/BaseActivityViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/base/BaseActivityViewModel.kt @@ -17,47 +17,47 @@ import javax.inject.Inject @HiltViewModel open class BaseActivityViewModel -@Inject -constructor( - private val logoutEventRepository: LogoutEventRepository, - private val networkManager: NetworkManager, -) : ViewModel() { - private val _events = MutableSharedFlow() - val events: SharedFlow = _events.asSharedFlow() - private val _isConnected = MutableStateFlow(false) - val isConnected: StateFlow = _isConnected + @Inject + constructor( + private val logoutEventRepository: LogoutEventRepository, + private val networkManager: NetworkManager, + ) : ViewModel() { + private val _events = MutableSharedFlow() + val events: SharedFlow = _events.asSharedFlow() + private val _isConnected = MutableStateFlow(false) + val isConnected: StateFlow = _isConnected - init { - networkManager.registerNetworkCallback() - observerNetworkConnection() - } + init { + networkManager.registerNetworkCallback() + observerNetworkConnection() + } - private fun sendLogoutEvent() { - viewModelScope.launch { - logoutEventRepository.logout().collect { logoutEvent -> - if (logoutEvent) { - _events.emit(ViewEvent.Logout) + private fun sendLogoutEvent() { + viewModelScope.launch { + logoutEventRepository.logout().collect { logoutEvent -> + if (logoutEvent) { + _events.emit(ViewEvent.Logout) + } } } } - } - private fun observerNetworkConnection() { - viewModelScope.launch { - networkManager.isConnected.collectLatest { isConnected -> - _isConnected.update { isConnected } + private fun observerNetworkConnection() { + viewModelScope.launch { + networkManager.isConnected.collectLatest { isConnected -> + _isConnected.update { isConnected } + } } } - } - fun logout() { - viewModelScope.launch { - logoutEventRepository.logout() + fun logout() { + viewModelScope.launch { + logoutEventRepository.logout() + } } - } - override fun onCleared() { - super.onCleared() - networkManager.unRegisterNetworkCallback() + override fun onCleared() { + super.onCleared() + networkManager.unRegisterNetworkCallback() + } } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListScreen.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListScreen.kt index 7dd5ed11..955635da 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListScreen.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListScreen.kt @@ -70,9 +70,9 @@ fun BoardListScreen( }) { innerPadding -> BoxWithConstraints( modifier = - Modifier - .padding(innerPadding) - .fillMaxWidth(), + Modifier + .padding(innerPadding) + .fillMaxWidth(), ) { BoardListComponent( uiState = uiState, @@ -158,12 +158,12 @@ fun BoardThumbnail( placeholder = painterResource(id = R.drawable.ic_placeholder), error = painterResource(id = R.drawable.ic_placeholder), modifier = - Modifier - .size(width = 100.dp, height = 100.dp) - .clip(CircleShape) - .clickable { - navigateToMindMap(board.id, board.name) - }, + Modifier + .size(width = 100.dp, height = 100.dp) + .clip(CircleShape) + .clickable { + navigateToMindMap(board.id, board.name) + }, contentScale = ContentScale.Crop, ) } diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListViewModel.kt index 1a80e67c..0ad71518 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/boardlist/BoardListViewModel.kt @@ -21,151 +21,151 @@ import javax.inject.Inject @HiltViewModel class BoardListViewModel -@Inject -constructor( - private val savedStateHandle: SavedStateHandle, - private val boardListRepository: BoardListRepository, - logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager, -) : BaseActivityViewModel(logoutEventRepository, networkManager) { - private val _boardUiState = MutableStateFlow(BoardListUiState()) - val boardUiState: StateFlow = _boardUiState - private val _boardUiEvent = MutableSharedFlow() - val boardUiEvent: SharedFlow = _boardUiEvent - private lateinit var coroutineExceptionHandler: CoroutineExceptionHandler + @Inject + constructor( + private val savedStateHandle: SavedStateHandle, + private val boardListRepository: BoardListRepository, + logoutEventRepository: LogoutEventRepository, + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { + private val _boardUiState = MutableStateFlow(BoardListUiState()) + val boardUiState: StateFlow = _boardUiState + private val _boardUiEvent = MutableSharedFlow() + val boardUiEvent: SharedFlow = _boardUiEvent + private lateinit var coroutineExceptionHandler: CoroutineExceptionHandler - init { - setCoroutineExceptionHandler() - setSpaceId() - } + init { + setCoroutineExceptionHandler() + setSpaceId() + } - private fun setCoroutineExceptionHandler() { - coroutineExceptionHandler = - CoroutineExceptionHandler { _, throwable -> - viewModelScope.launch { - _boardUiEvent.emit(BoardListUiEvent.ShowMessage(throwable.message.toString())) + private fun setCoroutineExceptionHandler() { + coroutineExceptionHandler = + CoroutineExceptionHandler { _, throwable -> + viewModelScope.launch { + _boardUiEvent.emit(BoardListUiEvent.ShowMessage(throwable.message.toString())) + } } - } - } - - private fun setSpaceId() { - val spaceId = savedStateHandle.get("spaceId").orEmpty() - spaceId?.let { - _boardUiState.update { boardUiState -> - boardUiState.copy(spaceId = spaceId) - } - getBoards() } - } - fun addBoard( - imageFile: File?, - name: String, - ) { - val imageUrl = - imageFile?.let { - fileToMultiPart(imageFile, "image") - } - viewModelScope.launch(coroutineExceptionHandler) { - boardListRepository.createBoard( - boardName = name, - spaceId = _boardUiState.value.spaceId, - imageUrl = imageUrl, - ).collectLatest { board -> + private fun setSpaceId() { + val spaceId = savedStateHandle.get("spaceId").orEmpty() + spaceId?.let { _boardUiState.update { boardUiState -> - val newBoards = boardUiState.boards.toMutableList().apply { add(board) } - boardUiState.copy(boards = newBoards) + boardUiState.copy(spaceId = spaceId) } + getBoards() } } - } - fun showCreateBoardDialog(isShown: Boolean) { - _boardUiState.update { uiState -> - uiState.copy( - isShownDialog = isShown, - boardName = "", - boardImage = "", - boardThumbnailFile = null, - ) - } - } - - fun getBoards() { - viewModelScope.launch(coroutineExceptionHandler) { - boardListRepository.getBoard(_boardUiState.value.spaceId, false) - .collectLatest { boards -> + fun addBoard( + imageFile: File?, + name: String, + ) { + val imageUrl = + imageFile?.let { + fileToMultiPart(imageFile, "image") + } + viewModelScope.launch(coroutineExceptionHandler) { + boardListRepository.createBoard( + boardName = name, + spaceId = _boardUiState.value.spaceId, + imageUrl = imageUrl, + ).collectLatest { board -> _boardUiState.update { boardUiState -> - boardUiState.copy(boards = boards) + val newBoards = boardUiState.boards.toMutableList().apply { add(board) } + boardUiState.copy(boards = newBoards) } } + } } - } - fun selectBoard() { - _boardUiState.update { boardUiState -> - val newSelectBoards = - boardUiState.boards.toMutableList().filter { board -> board.isChecked } - boardUiState.copy( - selectBoards = newSelectBoards, - ) + fun showCreateBoardDialog(isShown: Boolean) { + _boardUiState.update { uiState -> + uiState.copy( + isShownDialog = isShown, + boardName = "", + boardImage = "", + boardThumbnailFile = null, + ) + } } - } - fun deleteBoard() { - viewModelScope.launch(coroutineExceptionHandler) { - val newBoards = boardUiState.value.boards.toMutableList() - val newSelectBoards = boardUiState.value.selectBoards.toMutableList() - _boardUiState.value.boards.filter { board -> - board.isChecked - }.map { board -> - boardListRepository.deleteBoard(board.id).collectLatest { - newBoards.remove(board) - } + fun getBoards() { + viewModelScope.launch(coroutineExceptionHandler) { + boardListRepository.getBoard(_boardUiState.value.spaceId, false) + .collectLatest { boards -> + _boardUiState.update { boardUiState -> + boardUiState.copy(boards = boards) + } + } } + } + + fun selectBoard() { _boardUiState.update { boardUiState -> + val newSelectBoards = + boardUiState.boards.toMutableList().filter { board -> board.isChecked } boardUiState.copy( - boards = newBoards, - selectBoards = listOf(), + selectBoards = newSelectBoards, ) } } - } - fun restoreBoard() { - viewModelScope.launch(coroutineExceptionHandler) { - val newBoards = boardUiState.value.boards.toMutableList() - val newSelectBoards = boardUiState.value.selectBoards.toMutableList() - _boardUiState.value.selectBoards.map { board -> - boardListRepository.restoreBoard(board.id).collectLatest { - newBoards.remove(board) - newSelectBoards.remove(board) + fun deleteBoard() { + viewModelScope.launch(coroutineExceptionHandler) { + val newBoards = boardUiState.value.boards.toMutableList() + val newSelectBoards = boardUiState.value.selectBoards.toMutableList() + _boardUiState.value.boards.filter { board -> + board.isChecked + }.map { board -> + boardListRepository.deleteBoard(board.id).collectLatest { + newBoards.remove(board) + } + } + _boardUiState.update { boardUiState -> + boardUiState.copy( + boards = newBoards, + selectBoards = listOf(), + ) } } - _boardUiState.update { boardUiState -> - boardUiState.copy( - boards = newBoards, - selectBoards = newSelectBoards, - ) + } + + fun restoreBoard() { + viewModelScope.launch(coroutineExceptionHandler) { + val newBoards = boardUiState.value.boards.toMutableList() + val newSelectBoards = boardUiState.value.selectBoards.toMutableList() + _boardUiState.value.selectBoards.map { board -> + boardListRepository.restoreBoard(board.id).collectLatest { + newBoards.remove(board) + newSelectBoards.remove(board) + } + } + _boardUiState.update { boardUiState -> + boardUiState.copy( + boards = newBoards, + selectBoards = newSelectBoards, + ) + } } } - } - fun onBoardNameChanged(inputSpaceName: CharSequence) { - _boardUiState.update { uiState -> - uiState.copy(boardName = inputSpaceName.toString()) + fun onBoardNameChanged(inputSpaceName: CharSequence) { + _boardUiState.update { uiState -> + uiState.copy(boardName = inputSpaceName.toString()) + } } - } - fun setBoardImage(boardImage: String) { - _boardUiState.update { uiState -> - uiState.copy(boardImage = boardImage) + fun setBoardImage(boardImage: String) { + _boardUiState.update { uiState -> + uiState.copy(boardImage = boardImage) + } } - } - fun setImageFile(file: File) { - _boardUiState.update { uiState -> - uiState.copy(boardThumbnailFile = file) + fun setImageFile(file: File) { + _boardUiState.update { uiState -> + uiState.copy(boardThumbnailFile = file) + } } } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConnectedNetworkDialog.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConnectedNetworkDialog.kt index e66a6a99..fed5f9cc 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConnectedNetworkDialog.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConnectedNetworkDialog.kt @@ -23,7 +23,6 @@ import kotlinx.coroutines.launch @AndroidEntryPoint class DisConnectedNetworkDialog(private val isConnected: StateFlow) : DialogFragment() { - private var _binding: DialogDisconnectNetworkBinding? = null private val binding get() = _binding!! diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConntedNetworkDialog.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConntedNetworkDialog.kt index 708bb976..c35ff533 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConntedNetworkDialog.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/dialog/DisConntedNetworkDialog.kt @@ -29,14 +29,16 @@ fun DisConnectedNetworkDialogScreen() { Dialog(onDismissRequest = {}) { Column( - modifier = Modifier - .width(dialogWidth) - .height(screenHeight), + modifier = + Modifier + .width(dialogWidth) + .height(screenHeight), verticalArrangement = Arrangement.Center, ) { Row( - modifier = Modifier - .align(Alignment.CenterHorizontally), + modifier = + Modifier + .align(Alignment.CenterHorizontally), verticalAlignment = Alignment.CenterVertically, ) { Image( diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/login/LoginViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/login/LoginViewModel.kt index fbd2badf..f0f781f3 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/login/LoginViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/login/LoginViewModel.kt @@ -21,73 +21,73 @@ import javax.inject.Inject @HiltViewModel class LoginViewModel -@Inject -constructor( - private val loginRepository: LoginRepository, - private val tokenRepository: TokenRepository, - logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager, -) : + @Inject + constructor( + private val loginRepository: LoginRepository, + private val tokenRepository: TokenRepository, + logoutEventRepository: LogoutEventRepository, + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { - private val _loginEvent = MutableSharedFlow() - val loginEvent = _loginEvent.asSharedFlow() + private val _loginEvent = MutableSharedFlow() + val loginEvent = _loginEvent.asSharedFlow() - private fun getTokenWithKakao(kakaoUserId: Long) { - viewModelScope.launch { - loginRepository.loginWithKakao(kakaoUserId) - .onSuccess { result -> - Log.d("LoginViewModel", "getTokenWithKakao: ${result.accessToken}") - tokenRepository.saveAccessToken(result.accessToken) - tokenRepository.saveRefreshToken(result.refreshToken) - _loginEvent.emit(LoginEvent.Success) - }.onFailure { - _loginEvent.emit( - LoginEvent.Error("${NetworkExceptionMessage.ERROR_MESSAGE_CANT_GET_TOKEN.message}\n${it.message}}"), - ) - } + private fun getTokenWithKakao(kakaoUserId: Long) { + viewModelScope.launch { + loginRepository.loginWithKakao(kakaoUserId) + .onSuccess { result -> + Log.d("LoginViewModel", "getTokenWithKakao: ${result.accessToken}") + tokenRepository.saveAccessToken(result.accessToken) + tokenRepository.saveRefreshToken(result.refreshToken) + _loginEvent.emit(LoginEvent.Success) + }.onFailure { + _loginEvent.emit( + LoginEvent.Error("${NetworkExceptionMessage.ERROR_MESSAGE_CANT_GET_TOKEN.message}\n${it.message}}"), + ) + } + } } - } - fun successGoogleLogin() { - Log.d("LoginActivity", "successGoogleLogin: success!") - // TODO : server token 요청하기 - } + fun successGoogleLogin() { + Log.d("LoginActivity", "successGoogleLogin: success!") + // TODO : server token 요청하기 + } - fun successKakaoLoin() { - UserApiClient.instance.me { user, error -> - if (error != null) { - Log.e("LoginActivity", "사용자 정보 요청 실패", error) - } else if (user != null) { - user.id?.let { userId -> - getTokenWithKakao(userId) + fun successKakaoLoin() { + UserApiClient.instance.me { user, error -> + if (error != null) { + Log.e("LoginActivity", "사용자 정보 요청 실패", error) + } else if (user != null) { + user.id?.let { userId -> + getTokenWithKakao(userId) + } } } } - } - fun handleGoogleSignInResult(completedTask: Task) { - try { - val account = completedTask.getResult(ApiException::class.java) + fun handleGoogleSignInResult(completedTask: Task) { + try { + val account = completedTask.getResult(ApiException::class.java) - val name = account.displayName - val token = account.idToken + val name = account.displayName + val token = account.idToken - // TODO : server token 요청하기 - } catch (e: ApiException) { - viewModelScope.launch { - _loginEvent.emit(LoginEvent.Error("google login error: ${e.message}\n${e.stackTrace}\n${e.cause}")) + // TODO : server token 요청하기 + } catch (e: ApiException) { + viewModelScope.launch { + _loginEvent.emit(LoginEvent.Error("google login error: ${e.message}\n${e.stackTrace}\n${e.cause}")) + } } } - } - fun getResultCallBack(): (OAuthToken?, Throwable?) -> Unit = - { token, error -> - if (error != null) { - viewModelScope.launch { - _loginEvent.emit(LoginEvent.Error(NetworkExceptionMessage.ERROR_MESSAGE_KAKAO_RESULT_NULL.message)) + fun getResultCallBack(): (OAuthToken?, Throwable?) -> Unit = + { token, error -> + if (error != null) { + viewModelScope.launch { + _loginEvent.emit(LoginEvent.Error(NetworkExceptionMessage.ERROR_MESSAGE_KAKAO_RESULT_NULL.message)) + } + } else if (token != null) { + successKakaoLoin() } - } else if (token != null) { - successKakaoLoin() } - } -} + } diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/main/MainViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/main/MainViewModel.kt index 8d7a5ec4..88b61dbb 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/main/MainViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/main/MainViewModel.kt @@ -20,97 +20,97 @@ import javax.inject.Inject @HiltViewModel class MainViewModel -@Inject -constructor( - private val profileRepository: ProfileRepository, - private val profileSpaceRepository: ProfileSpaceRepository, - logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager, -) : BaseActivityViewModel(logoutEventRepository, networkManager) { - private val _uiState = MutableStateFlow(MainUiState()) - val uiState: StateFlow = _uiState - private val _event = MutableSharedFlow() - val event: SharedFlow = _event + @Inject + constructor( + private val profileRepository: ProfileRepository, + private val profileSpaceRepository: ProfileSpaceRepository, + logoutEventRepository: LogoutEventRepository, + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { + private val _uiState = MutableStateFlow(MainUiState()) + val uiState: StateFlow = _uiState + private val _event = MutableSharedFlow() + val event: SharedFlow = _event - private val coroutineExceptionHandler = - CoroutineExceptionHandler { _, throwable -> - viewModelScope.launch { _event.emit(MainUiEvent.ShowMessage(throwable.message.toString())) } - } + private val coroutineExceptionHandler = + CoroutineExceptionHandler { _, throwable -> + viewModelScope.launch { _event.emit(MainUiEvent.ShowMessage(throwable.message.toString())) } + } - fun fetchProfile() { - viewModelScope.launch(coroutineExceptionHandler) { - profileRepository.getProfile().collectLatest { profile -> - _uiState.update { uiState -> - uiState.copy( - profileImageUrl = profile.imageUrl, - ) + fun fetchProfile() { + viewModelScope.launch(coroutineExceptionHandler) { + profileRepository.getProfile().collectLatest { profile -> + _uiState.update { uiState -> + uiState.copy( + profileImageUrl = profile.imageUrl, + ) + } } } } - } - fun getSpaces() { - viewModelScope.launch(coroutineExceptionHandler) { - profileSpaceRepository.getSpaces().collectLatest { responseSpaces -> - val newSpaces = - responseSpaces.map { space -> - if (space.id == _uiState.value.nowSpace?.id) { - space.copy(isSelected = true) - } else { - space + fun getSpaces() { + viewModelScope.launch(coroutineExceptionHandler) { + profileSpaceRepository.getSpaces().collectLatest { responseSpaces -> + val newSpaces = + responseSpaces.map { space -> + if (space.id == _uiState.value.nowSpace?.id) { + space.copy(isSelected = true) + } else { + space + } } + _uiState.update { uiState -> + uiState.copy( + spaces = newSpaces, + ) } - _uiState.update { uiState -> - uiState.copy( - spaces = newSpaces, - ) } } } - } - fun updateCurrentSpace(space: Space) { - val updatedSpaces = _uiState.value.spaces.map { it.copy(isSelected = it == space) } - _uiState.update { uiState -> - uiState.copy( - nowSpace = space, - spaces = updatedSpaces, - ) - } - viewModelScope.launch { - _event.emit(MainUiEvent.ShowMessage("${space.name}방에 참가했습니다.")) - getSpaceUsers() + fun updateCurrentSpace(space: Space) { + val updatedSpaces = _uiState.value.spaces.map { it.copy(isSelected = it == space) } + _uiState.update { uiState -> + uiState.copy( + nowSpace = space, + spaces = updatedSpaces, + ) + } + viewModelScope.launch { + _event.emit(MainUiEvent.ShowMessage("${space.name}방에 참가했습니다.")) + getSpaceUsers() + } } - } - fun getSpaceUsers() { - uiState.value.nowSpace?.let { nowSpace -> - viewModelScope.launch(coroutineExceptionHandler) { - profileSpaceRepository.getSpaceUsers(nowSpace.id).collectLatest { list -> - _uiState.update { uiState -> - uiState.copy( - users = list, - ) + fun getSpaceUsers() { + uiState.value.nowSpace?.let { nowSpace -> + viewModelScope.launch(coroutineExceptionHandler) { + profileSpaceRepository.getSpaceUsers(nowSpace.id).collectLatest { list -> + _uiState.update { uiState -> + uiState.copy( + users = list, + ) + } } } } } - } - fun leaveSpace() { - uiState.value.nowSpace?.let { nowSpace -> - viewModelScope.launch(coroutineExceptionHandler) { - profileSpaceRepository.leaveSpace(nowSpace.id).collectLatest { - _uiState.update { mainUiState -> - mainUiState.copy( - spaces = mainUiState.spaces.filter { space -> space.id != nowSpace.id }, - nowSpace = null, - users = listOf(), - ) + fun leaveSpace() { + uiState.value.nowSpace?.let { nowSpace -> + viewModelScope.launch(coroutineExceptionHandler) { + profileSpaceRepository.leaveSpace(nowSpace.id).collectLatest { + _uiState.update { mainUiState -> + mainUiState.copy( + spaces = mainUiState.spaces.filter { space -> space.id != nowSpace.id }, + nowSpace = null, + users = listOf(), + ) + } + _event.emit(MainUiEvent.LeaveSpace(nowSpace.name)) } - _event.emit(MainUiEvent.LeaveSpace(nowSpace.name)) } } } } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileScreen.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileScreen.kt index 33a910b1..c742c6f2 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileScreen.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileScreen.kt @@ -94,7 +94,7 @@ fun ProfileScreen( updateProfile = updateProfile, updateNickname = updateNickname, editNickname = editNickname, - isConneceted = isConnected + isConneceted = isConnected, ) } @@ -139,31 +139,31 @@ private fun ProfileContent( ) { innerPadding -> BoxWithConstraints( modifier = - Modifier - .padding(innerPadding) - .fillMaxWidth(), + Modifier + .padding(innerPadding) + .fillMaxWidth(), ) { val guidelineTop = maxHeight * 0.15f val guidelineStart = maxWidth * 0.1f val guidelineEnd = maxWidth * 0.1f Column( modifier = - Modifier - .fillMaxSize() - .padding(top = guidelineTop), + Modifier + .fillMaxSize() + .padding(top = guidelineTop), ) { ProfileImage( modifier = - Modifier - .align(Alignment.CenterHorizontally), + Modifier + .align(Alignment.CenterHorizontally), imageUri = uiState.imageUri, showImagePicker = showImagePicker, ) Row( modifier = - Modifier - .padding(top = 16.dp), + Modifier + .padding(top = 16.dp), verticalAlignment = Alignment.CenterVertically, ) { Spacer(modifier = Modifier.weight(1f)) @@ -181,13 +181,13 @@ private fun ProfileContent( ModifyButton( modifier = - Modifier - .padding( - top = 30.dp, - start = guidelineStart, - end = guidelineEnd, - ) - .fillMaxWidth(), + Modifier + .padding( + top = 30.dp, + start = guidelineStart, + end = guidelineEnd, + ) + .fillMaxWidth(), profileImageName = stringResource(id = R.string.profile_image_name), updateProfile = updateProfile, isModify = uiState.isModify, @@ -221,8 +221,8 @@ private fun ProfileTopAppBar(onBack: () -> Unit) { text = stringResource(id = R.string.profile_my_page), style = MaterialTheme.typography.displayMedium, modifier = - Modifier - .padding(start = 14.dp), + Modifier + .padding(start = 14.dp), ) } } @@ -235,30 +235,30 @@ private fun ProfileImage( ) { Box( modifier = - modifier - .size(120.dp), + modifier + .size(120.dp), ) { AsyncImage( model = imageUri, contentDescription = null, modifier = - Modifier - .clip(CircleShape) - .clickable { - showImagePicker() - }, + Modifier + .clip(CircleShape) + .clickable { + showImagePicker() + }, contentScale = ContentScale.Crop, ) Box( contentAlignment = Alignment.Center, modifier = - Modifier - .size(30.dp) - .offset(y = 10.dp) - .clip(shape = RoundedCornerShape(5.dp)) - .background(color = Blue1) - .align(Alignment.TopEnd), + Modifier + .size(30.dp) + .offset(y = 10.dp) + .clip(shape = RoundedCornerShape(5.dp)) + .background(color = Blue1) + .align(Alignment.TopEnd), ) { Image( painter = painterResource(id = R.drawable.ic_add_board), diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileViewModel.kt index 18f55fdf..4b465e33 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/profile/ProfileViewModel.kt @@ -22,99 +22,99 @@ import javax.inject.Inject @HiltViewModel class ProfileViewModel -@Inject -constructor( - private val profileRepository: ProfileRepository, - logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager, -) : + @Inject + constructor( + private val profileRepository: ProfileRepository, + logoutEventRepository: LogoutEventRepository, + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { - private val _uiState = MutableStateFlow(ProfileUiState()) - val uiState: StateFlow = _uiState - private val _event = MutableSharedFlow() - val event: SharedFlow = _event - private val coroutineExceptionHandler = - CoroutineExceptionHandler { _, throwable -> - viewModelScope.launch { _event.emit(ProfileUiEvent.ShowMessage(throwable.message.toString())) } - } - - init { - fetchProfile() - } + private val _uiState = MutableStateFlow(ProfileUiState()) + val uiState: StateFlow = _uiState + private val _event = MutableSharedFlow() + val event: SharedFlow = _event + private val coroutineExceptionHandler = + CoroutineExceptionHandler { _, throwable -> + viewModelScope.launch { _event.emit(ProfileUiEvent.ShowMessage(throwable.message.toString())) } + } - fun updateProfileUri(uri: Uri) { - _uiState.update { uiState -> - uiState.copy(imageUri = uri) + init { + fetchProfile() } - } - fun updateNickName(nickname: CharSequence) { - _uiState.update { uiState -> - uiState.copy(nickname = nickname.toString(), isModify = isProfileEditDisabled(nickname)) + fun updateProfileUri(uri: Uri) { + _uiState.update { uiState -> + uiState.copy(imageUri = uri) + } } - viewModelScope.launch { - _event.emit(ProfileUiEvent.UpdateProfileNickName) + + fun updateNickName(nickname: CharSequence) { + _uiState.update { uiState -> + uiState.copy(nickname = nickname.toString(), isModify = isProfileEditDisabled(nickname)) + } + viewModelScope.launch { + _event.emit(ProfileUiEvent.UpdateProfileNickName) + } } - } - private fun isProfileEditDisabled(nickname: CharSequence) = - uiState.value.serverFetchedNickName != nickname.toString() || uiState.value.imageFile != null + private fun isProfileEditDisabled(nickname: CharSequence) = + uiState.value.serverFetchedNickName != nickname.toString() || uiState.value.imageFile != null - fun setProfileImageFile(file: File) { - _uiState.update { uiState -> - val isNicknameNotEmpty = uiState.nickname.isNotEmpty() - uiState.copy( - imageFile = file, - isModify = isNicknameNotEmpty || uiState.isModify, - ) + fun setProfileImageFile(file: File) { + _uiState.update { uiState -> + val isNicknameNotEmpty = uiState.nickname.isNotEmpty() + uiState.copy( + imageFile = file, + isModify = isNicknameNotEmpty || uiState.isModify, + ) + } } - } - fun updateProfile(imageName: String) { - val image = - _uiState.value.imageFile?.let { file -> - fileToMultiPart(file, imageName) - } - val nickname = _uiState.value.nickname.toRequestBody() + fun updateProfile(imageName: String) { + val image = + _uiState.value.imageFile?.let { file -> + fileToMultiPart(file, imageName) + } + val nickname = _uiState.value.nickname.toRequestBody() - viewModelScope.launch(coroutineExceptionHandler) { - profileRepository.patchProfile(nickname, image).collectLatest { - _event.emit(ProfileUiEvent.NavigateToBack) + viewModelScope.launch(coroutineExceptionHandler) { + profileRepository.patchProfile(nickname, image).collectLatest { + _event.emit(ProfileUiEvent.NavigateToBack) + } } } - } - fun editNickname(nickname: CharSequence) { - _uiState.update { uiState -> - uiState.copy(editingNickname = nickname.toString()) + fun editNickname(nickname: CharSequence) { + _uiState.update { uiState -> + uiState.copy(editingNickname = nickname.toString()) + } } - } - private fun fetchProfile() { - viewModelScope.launch(coroutineExceptionHandler) { - profileRepository.getProfile().collectLatest { profile -> - _uiState.update { uiState -> - uiState.copy( - serverFetchedImage = Uri.parse(profile.imageUrl), - serverFetchedNickName = profile.nickname, - nickname = profile.nickname, - imageUri = Uri.parse(profile.imageUrl), - editingNickname = profile.nickname, - ) + private fun fetchProfile() { + viewModelScope.launch(coroutineExceptionHandler) { + profileRepository.getProfile().collectLatest { profile -> + _uiState.update { uiState -> + uiState.copy( + serverFetchedImage = Uri.parse(profile.imageUrl), + serverFetchedNickName = profile.nickname, + nickname = profile.nickname, + imageUri = Uri.parse(profile.imageUrl), + editingNickname = profile.nickname, + ) + } } } } - } - fun showNicknameDialog(isShown: Boolean) { - _uiState.update { uiState -> - uiState.copy(isShownNicknameDialog = isShown) + fun showNicknameDialog(isShown: Boolean) { + _uiState.update { uiState -> + uiState.copy(isShownNicknameDialog = isShown) + } } - } - fun onClickBack() { - viewModelScope.launch { - _event.emit(ProfileUiEvent.NavigateToBack) + fun onClickBack() { + viewModelScope.launch { + _event.emit(ProfileUiEvent.NavigateToBack) + } } } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/recyclebin/RecycleBinViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/recyclebin/RecycleBinViewModel.kt index dcbef07b..80b5ad38 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/recyclebin/RecycleBinViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/recyclebin/RecycleBinViewModel.kt @@ -19,69 +19,69 @@ import javax.inject.Inject @HiltViewModel class RecycleBinViewModel -@Inject -constructor( - private val boardListRepository: BoardListRepository, - logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager, -) : BaseActivityViewModel(logoutEventRepository, networkManager) { - private val _uiState = MutableStateFlow(RecycleBinUiState()) - val uiState: StateFlow = _uiState - private val _uiEvent = MutableSharedFlow() - val uiEvent: SharedFlow = _uiEvent + @Inject + constructor( + private val boardListRepository: BoardListRepository, + logoutEventRepository: LogoutEventRepository, + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { + private val _uiState = MutableStateFlow(RecycleBinUiState()) + val uiState: StateFlow = _uiState + private val _uiEvent = MutableSharedFlow() + val uiEvent: SharedFlow = _uiEvent - private val coroutineExceptionHandler = - CoroutineExceptionHandler { _, throwable -> - viewModelScope.launch { - _uiEvent.emit(RecycleBinUiEvent.ShowMessage(throwable.message.toString())) + private val coroutineExceptionHandler = + CoroutineExceptionHandler { _, throwable -> + viewModelScope.launch { + _uiEvent.emit(RecycleBinUiEvent.ShowMessage(throwable.message.toString())) + } } - } - fun setSpace(spaceId: String) { - _uiState.update { boardUiState -> - boardUiState.copy( - spaceId = spaceId, - ) + fun setSpace(spaceId: String) { + _uiState.update { boardUiState -> + boardUiState.copy( + spaceId = spaceId, + ) + } + getBoards() } - getBoards() - } - fun getBoards() { - viewModelScope.launch(coroutineExceptionHandler) { - boardListRepository.getBoard(_uiState.value.spaceId, true).collectLatest { boards -> - _uiState.update { boardUiState -> - boardUiState.copy(boards = boards) + fun getBoards() { + viewModelScope.launch(coroutineExceptionHandler) { + boardListRepository.getBoard(_uiState.value.spaceId, true).collectLatest { boards -> + _uiState.update { boardUiState -> + boardUiState.copy(boards = boards) + } } } } - } - - fun selectBoard(selectBoard: Board) { - _uiState.update { boardUiState -> - val newSelectBoards = - boardUiState.boards.toMutableList().filter { board -> board.isChecked } - boardUiState.copy( - selectBoards = newSelectBoards, - ) - } - } - fun restoreBoard() { - viewModelScope.launch(coroutineExceptionHandler) { - val newBoards = uiState.value.boards.toMutableList() - val newSelectBoards = uiState.value.selectBoards.toMutableList() - _uiState.value.selectBoards.map { board -> - boardListRepository.restoreBoard(board.id).collectLatest { - newBoards.remove(board) - newSelectBoards.remove(board) - } - } + fun selectBoard(selectBoard: Board) { _uiState.update { boardUiState -> + val newSelectBoards = + boardUiState.boards.toMutableList().filter { board -> board.isChecked } boardUiState.copy( - boards = newBoards, selectBoards = newSelectBoards, ) } } + + fun restoreBoard() { + viewModelScope.launch(coroutineExceptionHandler) { + val newBoards = uiState.value.boards.toMutableList() + val newSelectBoards = uiState.value.selectBoards.toMutableList() + _uiState.value.selectBoards.map { board -> + boardListRepository.restoreBoard(board.id).collectLatest { + newBoards.remove(board) + newSelectBoards.remove(board) + } + } + _uiState.update { boardUiState -> + boardUiState.copy( + boards = newBoards, + selectBoards = newSelectBoards, + ) + } + } + } } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceScreen.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceScreen.kt index 18ab87b6..8d239622 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceScreen.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceScreen.kt @@ -75,9 +75,9 @@ fun AddSpaceScreen( ) { innerPadding -> BoxWithConstraints( modifier = - Modifier - .padding(innerPadding) - .fillMaxWidth(), + Modifier + .padding(innerPadding) + .fillMaxWidth(), ) { if (isConnected.not()) { DisConnectedNetworkDialogScreen() @@ -115,36 +115,36 @@ fun AddSpaceContent( } Row( modifier = - Modifier - .padding(top = 50.dp) - .fillMaxWidth(), + Modifier + .padding(top = 50.dp) + .fillMaxWidth(), horizontalArrangement = Arrangement.Absolute.Center, ) { AddSpaceInfo() } Row( modifier = - Modifier - .fillMaxWidth() - .padding(top = 150.dp), + Modifier + .fillMaxWidth() + .padding(top = 150.dp), horizontalArrangement = Arrangement.Absolute.Center, ) { AddSpaceThumbnail(onImageClicked = imageLauncher, imageUrl = uiState.spaceThumbnail) } Row( modifier = - Modifier - .fillMaxWidth() - .padding(top = 300.dp, start = 20.dp, end = 20.dp), + Modifier + .fillMaxWidth() + .padding(top = 300.dp, start = 20.dp, end = 20.dp), horizontalArrangement = Arrangement.Center, ) { InputSpaceNameField(uiState = uiState, updateSpaceName = updateSpaceName) } Row( modifier = - Modifier - .padding(top = 450.dp) - .fillMaxWidth(), + Modifier + .padding(top = 450.dp) + .fillMaxWidth(), horizontalArrangement = Arrangement.Center, ) { SpaceNameInputButton(createSpace = createSpace, uiState.spaceName) @@ -174,9 +174,9 @@ fun AddSpaceTopBar(onBackClicked: () -> Unit) { Row { IconButton( modifier = - Modifier - .size(25.dp) - .padding(1.dp), + Modifier + .size(25.dp) + .padding(1.dp), onClick = onBackClicked, ) { Image( @@ -208,8 +208,8 @@ fun AddSpaceThumbnail( ) { Box( modifier = - Modifier - .size(120.dp), + Modifier + .size(120.dp), ) { AsyncImage( model = imageUrl, @@ -217,13 +217,13 @@ fun AddSpaceThumbnail( placeholder = painterResource(id = R.drawable.ic_placeholder), error = painterResource(id = R.drawable.ic_placeholder), modifier = - Modifier - .clickable { - onImageClicked.launch( - PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly), - ) - } - .clip(CircleShape), + Modifier + .clickable { + onImageClicked.launch( + PickVisualMediaRequest(ActivityResultContracts.PickVisualMedia.ImageOnly), + ) + } + .clip(CircleShape), contentScale = ContentScale.Crop, ) Box( @@ -287,9 +287,9 @@ fun SpaceNameInputButton( enabled = spaceName.length in 1..20, modifier = Modifier.width(264.dp), colors = - ButtonDefaults.buttonColors( - disabledContainerColor = Color.LightGray, - ), + ButtonDefaults.buttonColors( + disabledContainerColor = Color.LightGray, + ), ) { Text(text = stringResource(id = R.string.check_message)) } diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceViewModel.kt index a56d853f..e19ef708 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/generate/AddSpaceViewModel.kt @@ -27,8 +27,8 @@ class AddSpaceViewModel constructor( private val spaceRepository: SpaceRepository, logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager - ) : BaseActivityViewModel(logoutEventRepository,networkManager) { + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { private val _uiState = MutableStateFlow(SpaceUiState()) val uiState: StateFlow = _uiState private val _event = MutableSharedFlow() diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/AddInviteSpaceViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/AddInviteSpaceViewModel.kt index 340d9433..b00abcd3 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/AddInviteSpaceViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/AddInviteSpaceViewModel.kt @@ -8,4 +8,4 @@ class AddInviteSpaceViewModel( logoutEventRepository: LogoutEventRepository, networkManager: NetworkManager, ) : - BaseActivityViewModel(logoutEventRepository,networkManager) + BaseActivityViewModel(logoutEventRepository, networkManager) diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/ConfirmInviteSpaceViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/ConfirmInviteSpaceViewModel.kt index ab32c7d1..a22a7c19 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/ConfirmInviteSpaceViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/ConfirmInviteSpaceViewModel.kt @@ -26,7 +26,7 @@ class ConfirmInviteSpaceViewModel private val profileSpaceRepository: ProfileSpaceRepository, logoutEventRepository: LogoutEventRepository, networkManager: NetworkManager, - ) : BaseActivityViewModel(logoutEventRepository,networkManager) { + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { private val _uiState = MutableStateFlow(SpaceUiState()) val uiState: StateFlow = _uiState private val _event = MutableSharedFlow() diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/InputSpaceCodeViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/InputSpaceCodeViewModel.kt index 4ebfcd89..3c60b33a 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/InputSpaceCodeViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/join/InputSpaceCodeViewModel.kt @@ -21,43 +21,43 @@ import javax.inject.Inject @HiltViewModel class InputSpaceCodeViewModel -@Inject -constructor( - private val spaceRepository: SpaceRepository, - logoutEventRepository: LogoutEventRepository, - networkManager: NetworkManager, -) : BaseActivityViewModel(logoutEventRepository,networkManager) { - private val _uiState = MutableStateFlow(SpaceUiState()) - val uiState: StateFlow = _uiState - private val _event = MutableSharedFlow() - val event = _event.asSharedFlow() - private val coroutineExceptionHandler = - CoroutineExceptionHandler { _, throwable -> - viewModelScope.launch { - _event.emit( - SpaceUiEvent.ShowMessage(SpaceExceptionMessage.ERROR_MESSAGE_SPACE_INVITE_CODE_WRONG.message), - ) + @Inject + constructor( + private val spaceRepository: SpaceRepository, + logoutEventRepository: LogoutEventRepository, + networkManager: NetworkManager, + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { + private val _uiState = MutableStateFlow(SpaceUiState()) + val uiState: StateFlow = _uiState + private val _event = MutableSharedFlow() + val event = _event.asSharedFlow() + private val coroutineExceptionHandler = + CoroutineExceptionHandler { _, throwable -> + viewModelScope.launch { + _event.emit( + SpaceUiEvent.ShowMessage(SpaceExceptionMessage.ERROR_MESSAGE_SPACE_INVITE_CODE_WRONG.message), + ) + } } - } - fun onSpaceInviteCodeChanged( - inviteSpaceCode: CharSequence, - start: Int, - before: Int, - count: Int, - ) { - _uiState.update { uiState -> - uiState.copy( - spaceInviteCode = inviteSpaceCode.toString(), - ) + fun onSpaceInviteCodeChanged( + inviteSpaceCode: CharSequence, + start: Int, + before: Int, + count: Int, + ) { + _uiState.update { uiState -> + uiState.copy( + spaceInviteCode = inviteSpaceCode.toString(), + ) + } } - } - fun compareInviteCode() { - viewModelScope.launch(coroutineExceptionHandler) { - spaceRepository.joinInviteCode(_uiState.value.spaceInviteCode).collectLatest { space -> - _event.emit(SpaceUiEvent.NavigationToConfirmSpace(space)) + fun compareInviteCode() { + viewModelScope.launch(coroutineExceptionHandler) { + spaceRepository.joinInviteCode(_uiState.value.spaceInviteCode).collectLatest { space -> + _event.emit(SpaceUiEvent.NavigationToConfirmSpace(space)) + } } } } -} diff --git a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/list/SpaceListViewModel.kt b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/list/SpaceListViewModel.kt index ee39ca9c..5415088e 100644 --- a/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/list/SpaceListViewModel.kt +++ b/AOS/app/src/main/java/boostcamp/and07/mindsync/ui/space/list/SpaceListViewModel.kt @@ -27,7 +27,7 @@ class SpaceListViewModel private val profileSpaceRepository: ProfileSpaceRepository, logoutEventRepository: LogoutEventRepository, networkManager: NetworkManager, - ) : BaseActivityViewModel(logoutEventRepository,networkManager) { + ) : BaseActivityViewModel(logoutEventRepository, networkManager) { private val _uiState = MutableStateFlow(SpaceUiState()) val uiState: StateFlow = _uiState private val _uiEvent = MutableSharedFlow()