From 78b2ccb2b50dfcdf8a350f7a8d5626577ff56aac Mon Sep 17 00:00:00 2001 From: Maxime Naturel Date: Mon, 28 Mar 2022 17:57:04 +0200 Subject: [PATCH] Using VectorFeatures instead of VectorOverrides --- .../debug/features/DebugFeaturesStateFactory.kt | 5 +++++ .../features/debug/features/DebugVectorFeatures.kt | 4 ++++ .../java/im/vector/app/features/VectorFeatures.kt | 2 ++ .../features/location/LocationSharingViewModel.kt | 13 ++++++------- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt index 8702c8d966..60024d4c19 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugFeaturesStateFactory.kt @@ -54,6 +54,11 @@ class DebugFeaturesStateFactory @Inject constructor( key = DebugFeatureKeys.onboardingPersonalize, factory = VectorFeatures::isOnboardingPersonalizeEnabled ), + createBooleanFeature( + label = "Live location sharing", + key = DebugFeatureKeys.liveLocationSharing, + factory = VectorFeatures::isLiveLocationEnabled + ), )) } diff --git a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt index f93e3d96fb..ec3de1408a 100644 --- a/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt +++ b/vector/src/debug/java/im/vector/app/features/debug/features/DebugVectorFeatures.kt @@ -54,6 +54,9 @@ class DebugVectorFeatures( override fun isOnboardingPersonalizeEnabled(): Boolean = read(DebugFeatureKeys.onboardingPersonalize) ?: vectorFeatures.isOnboardingPersonalizeEnabled() + override fun isLiveLocationEnabled(): Boolean = read(DebugFeatureKeys.liveLocationSharing) + ?: vectorFeatures.isLiveLocationEnabled() + fun override(value: T?, key: Preferences.Key) = updatePreferences { if (value == null) { it.remove(key) @@ -106,4 +109,5 @@ object DebugFeatureKeys { val onboardingSplashCarousel = booleanPreferencesKey("onboarding-splash-carousel") val onboardingUseCase = booleanPreferencesKey("onbboarding-splash-carousel") val onboardingPersonalize = booleanPreferencesKey("onbboarding-personalize") + val liveLocationSharing = booleanPreferencesKey("live-location-sharing") } diff --git a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt index a19b3d9026..52ad9242f4 100644 --- a/vector/src/main/java/im/vector/app/features/VectorFeatures.kt +++ b/vector/src/main/java/im/vector/app/features/VectorFeatures.kt @@ -25,6 +25,7 @@ interface VectorFeatures { fun isOnboardingSplashCarouselEnabled(): Boolean fun isOnboardingUseCaseEnabled(): Boolean fun isOnboardingPersonalizeEnabled(): Boolean + fun isLiveLocationEnabled(): Boolean enum class OnboardingVariant { LEGACY, @@ -39,4 +40,5 @@ class DefaultVectorFeatures : VectorFeatures { override fun isOnboardingSplashCarouselEnabled() = true override fun isOnboardingUseCaseEnabled() = true override fun isOnboardingPersonalizeEnabled() = false + override fun isLiveLocationEnabled(): Boolean = BuildConfig.ENABLE_LIVE_LOCATION_SHARING } 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 186c5c46b3..37ccd344b3 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,11 +21,10 @@ 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.VectorFeatures 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 @@ -51,7 +50,7 @@ class LocationSharingViewModel @AssistedInject constructor( private val locationPinProvider: LocationPinProvider, private val session: Session, private val compareLocationsUseCase: CompareLocationsUseCase, - private val vectorOverrides: VectorOverrides + private val vectorFeatures: VectorFeatures, ) : VectorViewModel(initialState), LocationTracker.Callback { private val room = session.getRoom(initialState.roomId)!! @@ -71,7 +70,7 @@ class LocationSharingViewModel @AssistedInject constructor( setUserItem() updatePin() compareTargetAndUserLocation() - observeVectorOverrides() + checkVectorFeatures() } private fun setUserItem() { @@ -113,9 +112,9 @@ 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) + private fun checkVectorFeatures() { + setState { + copy(isLiveLocationSharingEnabled = vectorFeatures.isLiveLocationEnabled()) } }