Using VectorFeatures instead of VectorOverrides

This commit is contained in:
Maxime Naturel 2022-03-28 17:57:04 +02:00 committed by Maxime NATUREL
parent e92a05abe7
commit 78b2ccb2b5
4 changed files with 17 additions and 7 deletions

View file

@ -54,6 +54,11 @@ class DebugFeaturesStateFactory @Inject constructor(
key = DebugFeatureKeys.onboardingPersonalize, key = DebugFeatureKeys.onboardingPersonalize,
factory = VectorFeatures::isOnboardingPersonalizeEnabled factory = VectorFeatures::isOnboardingPersonalizeEnabled
), ),
createBooleanFeature(
label = "Live location sharing",
key = DebugFeatureKeys.liveLocationSharing,
factory = VectorFeatures::isLiveLocationEnabled
),
)) ))
} }

View file

@ -54,6 +54,9 @@ class DebugVectorFeatures(
override fun isOnboardingPersonalizeEnabled(): Boolean = read(DebugFeatureKeys.onboardingPersonalize) override fun isOnboardingPersonalizeEnabled(): Boolean = read(DebugFeatureKeys.onboardingPersonalize)
?: vectorFeatures.isOnboardingPersonalizeEnabled() ?: vectorFeatures.isOnboardingPersonalizeEnabled()
override fun isLiveLocationEnabled(): Boolean = read(DebugFeatureKeys.liveLocationSharing)
?: vectorFeatures.isLiveLocationEnabled()
fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences { fun <T> override(value: T?, key: Preferences.Key<T>) = updatePreferences {
if (value == null) { if (value == null) {
it.remove(key) it.remove(key)
@ -106,4 +109,5 @@ object DebugFeatureKeys {
val onboardingSplashCarousel = booleanPreferencesKey("onboarding-splash-carousel") val onboardingSplashCarousel = booleanPreferencesKey("onboarding-splash-carousel")
val onboardingUseCase = booleanPreferencesKey("onbboarding-splash-carousel") val onboardingUseCase = booleanPreferencesKey("onbboarding-splash-carousel")
val onboardingPersonalize = booleanPreferencesKey("onbboarding-personalize") val onboardingPersonalize = booleanPreferencesKey("onbboarding-personalize")
val liveLocationSharing = booleanPreferencesKey("live-location-sharing")
} }

View file

@ -25,6 +25,7 @@ interface VectorFeatures {
fun isOnboardingSplashCarouselEnabled(): Boolean fun isOnboardingSplashCarouselEnabled(): Boolean
fun isOnboardingUseCaseEnabled(): Boolean fun isOnboardingUseCaseEnabled(): Boolean
fun isOnboardingPersonalizeEnabled(): Boolean fun isOnboardingPersonalizeEnabled(): Boolean
fun isLiveLocationEnabled(): Boolean
enum class OnboardingVariant { enum class OnboardingVariant {
LEGACY, LEGACY,
@ -39,4 +40,5 @@ class DefaultVectorFeatures : VectorFeatures {
override fun isOnboardingSplashCarouselEnabled() = true override fun isOnboardingSplashCarouselEnabled() = true
override fun isOnboardingUseCaseEnabled() = true override fun isOnboardingUseCaseEnabled() = true
override fun isOnboardingPersonalizeEnabled() = false override fun isOnboardingPersonalizeEnabled() = false
override fun isLiveLocationEnabled(): Boolean = BuildConfig.ENABLE_LIVE_LOCATION_SHARING
} }

View file

@ -21,11 +21,10 @@ import com.airbnb.mvrx.MavericksViewModelFactory
import dagger.assisted.Assisted import dagger.assisted.Assisted
import dagger.assisted.AssistedFactory import dagger.assisted.AssistedFactory
import dagger.assisted.AssistedInject import dagger.assisted.AssistedInject
import im.vector.app.BuildConfig
import im.vector.app.core.di.MavericksAssistedViewModelFactory import im.vector.app.core.di.MavericksAssistedViewModelFactory
import im.vector.app.core.di.hiltMavericksViewModelFactory import im.vector.app.core.di.hiltMavericksViewModelFactory
import im.vector.app.core.platform.VectorViewModel 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.home.room.detail.timeline.helper.LocationPinProvider
import im.vector.app.features.location.domain.usecase.CompareLocationsUseCase import im.vector.app.features.location.domain.usecase.CompareLocationsUseCase
import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.MutableSharedFlow
@ -51,7 +50,7 @@ class LocationSharingViewModel @AssistedInject constructor(
private val locationPinProvider: LocationPinProvider, private val locationPinProvider: LocationPinProvider,
private val session: Session, private val session: Session,
private val compareLocationsUseCase: CompareLocationsUseCase, private val compareLocationsUseCase: CompareLocationsUseCase,
private val vectorOverrides: VectorOverrides private val vectorFeatures: VectorFeatures,
) : VectorViewModel<LocationSharingViewState, LocationSharingAction, LocationSharingViewEvents>(initialState), LocationTracker.Callback { ) : VectorViewModel<LocationSharingViewState, LocationSharingAction, LocationSharingViewEvents>(initialState), LocationTracker.Callback {
private val room = session.getRoom(initialState.roomId)!! private val room = session.getRoom(initialState.roomId)!!
@ -71,7 +70,7 @@ class LocationSharingViewModel @AssistedInject constructor(
setUserItem() setUserItem()
updatePin() updatePin()
compareTargetAndUserLocation() compareTargetAndUserLocation()
observeVectorOverrides() checkVectorFeatures()
} }
private fun setUserItem() { private fun setUserItem() {
@ -113,9 +112,9 @@ class LocationSharingViewModel @AssistedInject constructor(
?.let { userLocation -> compareLocationsUseCase.execute(userLocation, targetLocation) } ?.let { userLocation -> compareLocationsUseCase.execute(userLocation, targetLocation) }
} }
private fun observeVectorOverrides() { private fun checkVectorFeatures() {
vectorOverrides.forceEnableLiveLocationSharing.setOnEach { forceLiveLocation -> setState {
copy(isLiveLocationSharingEnabled = forceLiveLocation || BuildConfig.ENABLE_LIVE_LOCATION_SHARING) copy(isLiveLocationSharingEnabled = vectorFeatures.isLiveLocationEnabled())
} }
} }