Using the override setting in the LocationSharing screen

This commit is contained in:
Maxime Naturel 2022-03-18 17:28:18 +01:00 committed by Maxime NATUREL
parent 424f70bc58
commit cfce144b61
3 changed files with 16 additions and 4 deletions

View file

@ -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<LocationSharingOption> = 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)

View file

@ -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<LocationSharingViewState, LocationSharingAction, LocationSharingViewEvents>(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)

View file

@ -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
)
}