diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt index 5e567b66..1796433f 100644 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt +++ b/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileScreen.kt @@ -275,17 +275,22 @@ private fun SpaceProfileContent() { cursorBrush = SolidColor(AppTheme.colorScheme.primary) ) if (state.allowSave) { - Icon( - imageVector = Icons.Default.Check, - contentDescription = "", - tint = outlineColor, - modifier = Modifier - .padding(horizontal = 8.dp) - .clickable { - viewModel.saveSpace() - focusManager.clearFocus() - } - ) + if (state.isNameChanging) { + CircularProgressIndicator(modifier = Modifier.size(20.dp)) + } else { + Icon( + imageVector = Icons.Default.Check, + contentDescription = "", + tint = outlineColor, + modifier = Modifier + .padding(horizontal = 8.dp) + .clickable { + ripple(true) + viewModel.saveSpace() + focusManager.clearFocus() + } + ) + } } } @@ -347,22 +352,23 @@ private fun SpaceProfileContent() { Header(title = stringResource(id = R.string.space_setting_title_your_location)) - state.spaceInfo?.members?.firstOrNull { it.user.id == state.currentUserId }?.let { user -> - UserItem( - userInfo = user, - isChecked = state.locationEnabled, - enable = true, - isAdmin = state.isAdmin, - currentUser = state.currentUserId!!, - isAdminUser = state.spaceInfo?.space?.admin_id == user.user.id, - onCheckedChange = { isChecked -> - viewModel.onLocationEnabledChanged(isChecked) - }, - onMemberRemove = { - viewModel.showRemoveMemberConfirmationWithId(true, "") - } - ) - } + state.spaceInfo?.members?.firstOrNull { it.user.id == state.currentUserId } + ?.let { user -> + UserItem( + userInfo = user, + isChecked = state.locationEnabled, + enable = true, + isAdmin = state.isAdmin, + currentUser = state.currentUserId!!, + isAdminUser = state.spaceInfo?.space?.admin_id == user.user.id, + onCheckedChange = { isChecked -> + viewModel.onLocationEnabledChanged(isChecked) + }, + onMemberRemove = { + viewModel.showRemoveMemberConfirmationWithId(true, "") + } + ) + } HorizontalDivider( modifier = Modifier diff --git a/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt b/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt index e7f3e03a..acd08e72 100644 --- a/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt +++ b/app/src/main/java/com/canopas/yourspace/ui/flow/settings/space/SpaceProfileViewModel.kt @@ -100,24 +100,17 @@ class SpaceProfileViewModel @Inject constructor( fun updateMemberLocation(memberId: String, enableLocation: Boolean) { viewModelScope.launch(appDispatcher.IO) { try { - _state.emit(_state.value.copy(userLocationUpdatingId = memberId)) spaceRepository.enableLocation(spaceID, memberId, enableLocation) val spaceInfo = spaceRepository.getSpaceInfo(spaceID) _state.emit( _state.value.copy( spaceInfo = spaceInfo, - locationEnabledChanges = _state.value.locationEnabledChanges + (memberId to enableLocation), - userLocationUpdatingId = null + locationEnabledChanges = _state.value.locationEnabledChanges + (memberId to enableLocation) ) ) } catch (e: Exception) { Timber.e(e, "Failed to update member location") - _state.emit( - _state.value.copy( - error = e, - userLocationUpdatingId = null - ) - ) + _state.emit(_state.value.copy(error = e)) } } } @@ -185,6 +178,7 @@ class SpaceProfileViewModel @Inject constructor( try { _state.emit(_state.value.copy(saving = true)) if (isNameUpdated) { + _state.emit(_state.value.copy(isNameChanging = true)) spaceRepository.updateSpace( space.copy(name = _state.value.spaceName?.trim() ?: "") ) @@ -197,10 +191,10 @@ class SpaceProfileViewModel @Inject constructor( ) } val spaceInfo = spaceRepository.getSpaceInfo(spaceID) - _state.emit(_state.value.copy(saving = false, allowSave = false, spaceInfo = spaceInfo)) + _state.emit(_state.value.copy(saving = false, allowSave = false, spaceInfo = spaceInfo, isNameChanging = false)) } catch (e: Exception) { Timber.e(e, "Failed to save space") - _state.emit(_state.value.copy(saving = false, error = e, allowSave = false)) + _state.emit(_state.value.copy(saving = false, error = e, allowSave = false, isNameChanging = false)) } } @@ -344,5 +338,5 @@ data class SpaceProfileState( val isCodeLoading: Boolean = false, val locationEnabledChanges: Map = emptyMap(), val isLocationSettingChange: Boolean = false, - val userLocationUpdatingId: String? = null + val isNameChanging: Boolean = false )