Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-radhika-s committed Feb 9, 2024
1 parent 344d1e5 commit 1e2cc42
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -148,26 +148,14 @@ fun MapScreenContent(modifier: Modifier) {
}
}

LaunchedEffect(userLocation, state.selectedUser) {
if (state.selectedUser != null) {
val location = state.selectedUser?.location
if (location != null) {
val latLng = LatLng(location.latitude, location.longitude)
cameraPositionState.animate(
CameraUpdateFactory.newLatLngZoom(
latLng,
DEFAULT_CAMERA_ZOOM_FOR_SELECTED_USER
)
)
}
} else {
cameraPositionState.animate(
CameraUpdateFactory.newLatLngZoom(
userLocation,
DEFAULT_CAMERA_ZOOM
)
LaunchedEffect(userLocation) {
val location = state.selectedUser?.location
cameraPositionState.animate(
CameraUpdateFactory.newLatLngZoom(
userLocation,
if (location != null) DEFAULT_CAMERA_ZOOM_FOR_SELECTED_USER else DEFAULT_CAMERA_ZOOM
)
}
)
}

Box(modifier = modifier.fillMaxSize()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.canopas.catchme.ui.flow.home.map
import android.location.Location
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.canopas.catchme.data.models.location.toLocation
import com.canopas.catchme.data.models.user.UserInfo
import com.canopas.catchme.data.repository.SpaceRepository
import com.canopas.catchme.data.service.location.LocationManager
Expand Down Expand Up @@ -50,11 +51,9 @@ class MapViewModel @Inject constructor(
private fun listenMemberLocation() {
locationJob = viewModelScope.launch(appDispatcher.IO) {
spaceRepository.getMemberWithLocation().collectLatest {
val currentLocation = locationManager.getLastLocation()
_state.emit(
_state.value.copy(
members = it,
defaultCameraPosition = currentLocation
members = it
)
)
}
Expand All @@ -66,7 +65,14 @@ class MapViewModel @Inject constructor(
if (selectedUser != null && selectedUser.user.id == userInfo.user.id) {
dismissMemberDetail()
} else {
_state.emit(_state.value.copy(selectedUser = userInfo, showUserDetails = true))
val selectedLocation = userInfo.location?.toLocation()
_state.emit(
_state.value.copy(
selectedUser = userInfo,
defaultCameraPosition = selectedLocation,
showUserDetails = true
)
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,8 @@ data class ApiLocation(
val longitude: Double = 0.0,
val created_at: Long? = System.currentTimeMillis()
)

fun ApiLocation.toLocation() = android.location.Location("").apply {
latitude = this@toLocation.latitude
longitude = this@toLocation.longitude
}

0 comments on commit 1e2cc42

Please sign in to comment.