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 e25520ed81..84034c6461 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 @@ -39,8 +39,10 @@ import im.vector.app.core.utils.registerForPermissionsResult import im.vector.app.databinding.FragmentLocationSharingBinding import im.vector.app.features.home.AvatarRenderer import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider +import im.vector.app.features.location.live.LiveLocationLabsFlagPromotionBottomSheet import im.vector.app.features.location.live.duration.ChooseLiveDurationBottomSheet import im.vector.app.features.location.option.LocationSharingOption +import im.vector.app.features.settings.VectorPreferences import org.matrix.android.sdk.api.util.MatrixItem import java.lang.ref.WeakReference import javax.inject.Inject @@ -52,6 +54,7 @@ class LocationSharingFragment @Inject constructor( private val urlMapProvider: UrlMapProvider, private val avatarRenderer: AvatarRenderer, private val matrixItemColorProvider: MatrixItemColorProvider, + private val vectorPreferences: VectorPreferences, ) : VectorBaseFragment(), LocationTargetChangeListener, VectorBaseBottomSheetDialogFragment.ResultListener { @@ -192,6 +195,25 @@ class LocationSharingFragment @Inject constructor( } } + private val liveLocationLabsFlagPromotionListener = object : VectorBaseBottomSheetDialogFragment.ResultListener { + override fun onBottomSheetResult(resultCode: Int, data: Any?) { + // Check if the user wants to enable the labs flag + if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK && (data as? Boolean) == true) { + vectorPreferences.setLiveLocationLabsEnabled() + startLiveLocationSharing() + } + } + } + + private fun tryStartLiveLocationSharing() { + if (vectorPreferences.labsEnableLiveLocation()) { + startLiveLocationSharing() + } else { + LiveLocationLabsFlagPromotionBottomSheet.newInstance(liveLocationLabsFlagPromotionListener) + .show(requireActivity().supportFragmentManager, "DISPLAY_LIVE_LOCATION_LABS_FLAG_PROMOTION") + } + } + private val foregroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently -> if (allGranted) { startLiveLocationSharing() @@ -200,18 +222,14 @@ class LocationSharingFragment @Inject constructor( } } - private fun tryStartLiveLocationSharing() { + private fun startLiveLocationSharing() { // we need to re-check foreground location to be sure it has not changed after landing on this screen if (checkPermissions(PERMISSIONS_FOR_FOREGROUND_LOCATION_SHARING, requireActivity(), foregroundLocationResultLauncher)) { - startLiveLocationSharing() + ChooseLiveDurationBottomSheet.newInstance(this) + .show(requireActivity().supportFragmentManager, "DISPLAY_CHOOSE_DURATION_OPTIONS") } } - private fun startLiveLocationSharing() { - ChooseLiveDurationBottomSheet.newInstance(this) - .show(requireActivity().supportFragmentManager, "DISPLAY_CHOOSE_DURATION_OPTIONS") - } - override fun onBottomSheetResult(resultCode: Int, data: Any?) { if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK) { (data as? Long)?.let { viewModel.handle(LocationSharingAction.StartLiveLocationSharing(it)) } diff --git a/vector/src/main/java/im/vector/app/features/location/live/LiveLocationLabsFlagPromotionBottomSheet.kt b/vector/src/main/java/im/vector/app/features/location/live/LiveLocationLabsFlagPromotionBottomSheet.kt index 283e44b0e3..5c11a26d6d 100644 --- a/vector/src/main/java/im/vector/app/features/location/live/LiveLocationLabsFlagPromotionBottomSheet.kt +++ b/vector/src/main/java/im/vector/app/features/location/live/LiveLocationLabsFlagPromotionBottomSheet.kt @@ -27,8 +27,10 @@ import im.vector.app.databinding.BottomSheetLiveLocationLabsFlagPromotionBinding * Bottom sheet to warn users that feature is still in active development. Users are able to enable labs flag by using the switch in this bottom sheet. * This should not be shown if the user already enabled the labs flag. */ -class LiveLocationLabsFlagPromotionBottomSheet - : VectorBaseBottomSheetDialogFragment() { +class LiveLocationLabsFlagPromotionBottomSheet : + VectorBaseBottomSheetDialogFragment() { + + override val showExpanded = true override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetLiveLocationLabsFlagPromotionBinding { return BottomSheetLiveLocationLabsFlagPromotionBinding.inflate(inflater, container, false) diff --git a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt index 276317b557..d389c76dfa 100755 --- a/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt +++ b/vector/src/main/java/im/vector/app/features/settings/VectorPreferences.kt @@ -1047,6 +1047,12 @@ class VectorPreferences @Inject constructor( return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, false) } + fun setLiveLocationLabsEnabled() { + defaultPrefs.edit { + putBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, true) + } + } + /** * Indicates whether or not thread messages are enabled. */