From cfce144b61fd64fa57de91e80cf1f894606a93ab Mon Sep 17 00:00:00 2001 From: Maxime Naturel Date: Fri, 18 Mar 2022 17:28:18 +0100 Subject: [PATCH] Using the override setting in the LocationSharing screen --- .../app/features/location/LocationSharingFragment.kt | 3 +-- .../features/location/LocationSharingViewModel.kt | 12 +++++++++++- .../features/location/LocationSharingViewState.kt | 5 ++++- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt index b779b50c8b..ea350b00c3 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingFragment.kt @@ -29,7 +29,6 @@ import com.airbnb.mvrx.fragmentViewModel import com.airbnb.mvrx.withState import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.mapbox.mapboxsdk.maps.MapView -import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.core.platform.VectorBaseFragment import im.vector.app.core.utils.PERMISSIONS_FOR_BACKGROUND_LOCATION_SHARING @@ -243,7 +242,7 @@ class LocationSharingFragment @Inject constructor( // first, update the options view val options: Set = when (state.areTargetAndUserLocationEqual) { true -> { - if (BuildConfig.ENABLE_LIVE_LOCATION_SHARING) { + if (state.isLiveLocationSharingEnabled) { setOf(LocationSharingOption.USER_CURRENT, LocationSharingOption.USER_LIVE) } else { setOf(LocationSharingOption.USER_CURRENT) diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt index dfa936dcaa..186c5c46b3 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewModel.kt @@ -21,9 +21,11 @@ import com.airbnb.mvrx.MavericksViewModelFactory import dagger.assisted.Assisted import dagger.assisted.AssistedFactory import dagger.assisted.AssistedInject +import im.vector.app.BuildConfig import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.platform.VectorViewModel +import im.vector.app.features.VectorOverrides import im.vector.app.features.home.room.detail.timeline.helper.LocationPinProvider import im.vector.app.features.location.domain.usecase.CompareLocationsUseCase import kotlinx.coroutines.flow.MutableSharedFlow @@ -48,7 +50,8 @@ class LocationSharingViewModel @AssistedInject constructor( private val locationTracker: LocationTracker, private val locationPinProvider: LocationPinProvider, private val session: Session, - private val compareLocationsUseCase: CompareLocationsUseCase + private val compareLocationsUseCase: CompareLocationsUseCase, + private val vectorOverrides: VectorOverrides ) : VectorViewModel(initialState), LocationTracker.Callback { private val room = session.getRoom(initialState.roomId)!! @@ -68,6 +71,7 @@ class LocationSharingViewModel @AssistedInject constructor( setUserItem() updatePin() compareTargetAndUserLocation() + observeVectorOverrides() } private fun setUserItem() { @@ -109,6 +113,12 @@ class LocationSharingViewModel @AssistedInject constructor( ?.let { userLocation -> compareLocationsUseCase.execute(userLocation, targetLocation) } } + private fun observeVectorOverrides() { + vectorOverrides.forceEnableLiveLocationSharing.setOnEach { forceLiveLocation -> + copy(isLiveLocationSharingEnabled = forceLiveLocation || BuildConfig.ENABLE_LIVE_LOCATION_SHARING) + } + } + override fun onCleared() { super.onCleared() locationTracker.removeCallback(this) diff --git a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt index ee5ba402e2..64039b00c4 100644 --- a/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt +++ b/vector/src/main/java/im/vector/app/features/location/LocationSharingViewState.kt @@ -19,6 +19,7 @@ package im.vector.app.features.location import android.graphics.drawable.Drawable import androidx.annotation.StringRes import com.airbnb.mvrx.MavericksState +import im.vector.app.BuildConfig import im.vector.app.R import org.matrix.android.sdk.api.extensions.orTrue import org.matrix.android.sdk.api.util.MatrixItem @@ -31,6 +32,7 @@ enum class LocationSharingMode(@StringRes val titleRes: Int) { data class LocationSharingViewState( val roomId: String, val mode: LocationSharingMode, + val isLiveLocationSharingEnabled: Boolean, val userItem: MatrixItem.UserItem? = null, val areTargetAndUserLocationEqual: Boolean? = null, val lastKnownUserLocation: LocationData? = null, @@ -39,7 +41,8 @@ data class LocationSharingViewState( constructor(locationSharingArgs: LocationSharingArgs) : this( roomId = locationSharingArgs.roomId, - mode = locationSharingArgs.mode + mode = locationSharingArgs.mode, + isLiveLocationSharingEnabled = BuildConfig.ENABLE_LIVE_LOCATION_SHARING ) }