Skip to content

Commit

Permalink
Minor bug fixes (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-radhika-s authored Feb 6, 2024
1 parent e62fcd6 commit 541330f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ fun MapScreen() {

val permissionState = rememberPermissionState(Manifest.permission.ACCESS_FINE_LOCATION)
LaunchedEffect(permissionState) {
snapshotFlow { permissionState.status == PermissionStatus.Granted && state.currentCameraPosition == null }
snapshotFlow { permissionState.status == PermissionStatus.Granted && state.defaultCameraPosition == null }
.collect {
if (it) {
viewModel.startLocationTracking()
Expand Down Expand Up @@ -132,8 +132,8 @@ fun MapScreenContent(modifier: Modifier) {
val viewModel = hiltViewModel<MapViewModel>()
val state by viewModel.state.collectAsState()

val userLocation = remember(state.currentCameraPosition) {
val location = state.currentCameraPosition
val userLocation = remember(state.defaultCameraPosition) {
val location = state.defaultCameraPosition
LatLng(location?.latitude ?: 0.0, location?.longitude ?: 0.0)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MapViewModel @Inject constructor(
viewModelScope.launch {
_state.value = _state.value.copy(currentUserId = userPreferences.currentUser?.id)
withContext(appDispatcher.IO) {
_state.emit(_state.value.copy(currentCameraPosition = locationManager.getLastLocation()))
_state.emit(_state.value.copy(defaultCameraPosition = locationManager.getLastLocation()))
}
userPreferences.currentSpaceState.collectLatest {
locationJob?.cancel()
Expand All @@ -54,7 +54,7 @@ class MapViewModel @Inject constructor(
_state.emit(
_state.value.copy(
members = it,
currentCameraPosition = currentLocation
defaultCameraPosition = currentLocation
)
)
}
Expand Down Expand Up @@ -98,7 +98,7 @@ class MapViewModel @Inject constructor(
fun startLocationTracking() {
viewModelScope.launch(appDispatcher.IO) {
val currentLocation = locationManager.getLastLocation()
_state.emit(_state.value.copy(currentCameraPosition = currentLocation))
_state.emit(_state.value.copy(defaultCameraPosition = currentLocation))
locationManager.startService()
}
}
Expand All @@ -107,7 +107,7 @@ class MapViewModel @Inject constructor(
data class MapScreenState(
val members: List<UserInfo> = emptyList(),
val currentUserId: String? = "",
val currentCameraPosition: Location? = null,
val defaultCameraPosition: Location? = null,
val selectedUser: UserInfo? = null,
val showUserDetails: Boolean = false,
val loadingInviteCode: Boolean = false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.flatMapLatest
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.toList
import javax.inject.Inject

class SpaceRepository @Inject constructor(
Expand Down Expand Up @@ -51,6 +50,7 @@ class SpaceRepository @Inject constructor(
suspend fun getAllSpaceInfo(): Flow<List<SpaceInfo>> {
val userId = authService.currentUser?.id ?: ""
return getUserSpaces(userId).flatMapLatest { spaces ->
if (spaces.isEmpty()) return@flatMapLatest flowOf(emptyList())
val flows = spaces.filterNotNull().map { space ->
spaceService.getMemberBySpaceId(space.id)
.map { members ->
Expand Down Expand Up @@ -92,6 +92,7 @@ class SpaceRepository @Inject constructor(
if (currentSpaceId.isEmpty()) return emptyFlow()
return spaceService.getMemberBySpaceId(currentSpaceId)
.flatMapLatest { members ->
if (members.isEmpty()) return@flatMapLatest flowOf(emptyList())
val flows = members
.mapNotNull { member ->
val user = userService.getUser(member.user_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ fun <T> Query.snapshotFlow(dataType: Class<T>): Flow<List<T>> = callbackFlow {
}
if (value != null) {
trySend(value.toObjects(dataType))
} else {
trySend(emptyList())
}
}
awaitClose {
Expand Down

0 comments on commit 541330f

Please sign in to comment.