Directly use VectorFeatures inside Fragment

This commit is contained in:
Maxime NATUREL 2022-03-31 11:25:30 +02:00
parent 9e3dc4c10f
commit 167fcb5366
3 changed files with 4 additions and 14 deletions

View file

@ -36,6 +36,7 @@ import im.vector.app.core.utils.PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING
import im.vector.app.core.utils.checkPermissions
import im.vector.app.core.utils.registerForPermissionsResult
import im.vector.app.databinding.FragmentLocationSharingBinding
import im.vector.app.features.VectorFeatures
import im.vector.app.features.home.AvatarRenderer
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
import im.vector.app.features.location.option.LocationSharingOption
@ -49,7 +50,8 @@ import javax.inject.Inject
class LocationSharingFragment @Inject constructor(
private val urlMapProvider: UrlMapProvider,
private val avatarRenderer: AvatarRenderer,
private val matrixItemColorProvider: MatrixItemColorProvider
private val matrixItemColorProvider: MatrixItemColorProvider,
private val vectorFeatures: VectorFeatures,
) : VectorBaseFragment<FragmentLocationSharingBinding>(), LocationTargetChangeListener {
private val viewModel: LocationSharingViewModel by fragmentViewModel()
@ -242,7 +244,7 @@ class LocationSharingFragment @Inject constructor(
// first, update the options view
val options: Set<LocationSharingOption> = when (state.areTargetAndUserLocationEqual) {
true -> {
if (state.isLiveLocationSharingEnabled) {
if (vectorFeatures.isLiveLocationEnabled()) {
setOf(LocationSharingOption.USER_CURRENT, LocationSharingOption.USER_LIVE)
} else {
setOf(LocationSharingOption.USER_CURRENT)

View file

@ -24,7 +24,6 @@ import dagger.assisted.AssistedInject
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.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
@ -50,7 +49,6 @@ class LocationSharingViewModel @AssistedInject constructor(
private val locationPinProvider: LocationPinProvider,
private val session: Session,
private val compareLocationsUseCase: CompareLocationsUseCase,
private val vectorFeatures: VectorFeatures,
) : VectorViewModel<LocationSharingViewState, LocationSharingAction, LocationSharingViewEvents>(initialState), LocationTracker.Callback {
private val room = session.getRoom(initialState.roomId)!!
@ -70,7 +68,6 @@ class LocationSharingViewModel @AssistedInject constructor(
setUserItem()
updatePin()
compareTargetAndUserLocation()
checkVectorFeatures()
}
private fun setUserItem() {
@ -112,12 +109,6 @@ class LocationSharingViewModel @AssistedInject constructor(
?.let { userLocation -> compareLocationsUseCase.execute(userLocation, targetLocation) }
}
private fun checkVectorFeatures() {
setState {
copy(isLiveLocationSharingEnabled = vectorFeatures.isLiveLocationEnabled())
}
}
override fun onCleared() {
super.onCleared()
locationTracker.removeCallback(this)

View file

@ -19,7 +19,6 @@ 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
@ -32,7 +31,6 @@ 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,
@ -42,7 +40,6 @@ data class LocationSharingViewState(
constructor(locationSharingArgs: LocationSharingArgs) : this(
roomId = locationSharingArgs.roomId,
mode = locationSharingArgs.mode,
isLiveLocationSharingEnabled = BuildConfig.ENABLE_LIVE_LOCATION_SHARING
)
}