Show live location promotional bottom sheet.
This commit is contained in:
parent
13144f078a
commit
80abe1f675
@ -39,8 +39,10 @@ import im.vector.app.core.utils.registerForPermissionsResult
|
|||||||
import im.vector.app.databinding.FragmentLocationSharingBinding
|
import im.vector.app.databinding.FragmentLocationSharingBinding
|
||||||
import im.vector.app.features.home.AvatarRenderer
|
import im.vector.app.features.home.AvatarRenderer
|
||||||
import im.vector.app.features.home.room.detail.timeline.helper.MatrixItemColorProvider
|
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.live.duration.ChooseLiveDurationBottomSheet
|
||||||
import im.vector.app.features.location.option.LocationSharingOption
|
import im.vector.app.features.location.option.LocationSharingOption
|
||||||
|
import im.vector.app.features.settings.VectorPreferences
|
||||||
import org.matrix.android.sdk.api.util.MatrixItem
|
import org.matrix.android.sdk.api.util.MatrixItem
|
||||||
import java.lang.ref.WeakReference
|
import java.lang.ref.WeakReference
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
@ -52,6 +54,7 @@ class LocationSharingFragment @Inject constructor(
|
|||||||
private val urlMapProvider: UrlMapProvider,
|
private val urlMapProvider: UrlMapProvider,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val matrixItemColorProvider: MatrixItemColorProvider,
|
private val matrixItemColorProvider: MatrixItemColorProvider,
|
||||||
|
private val vectorPreferences: VectorPreferences,
|
||||||
) : VectorBaseFragment<FragmentLocationSharingBinding>(),
|
) : VectorBaseFragment<FragmentLocationSharingBinding>(),
|
||||||
LocationTargetChangeListener,
|
LocationTargetChangeListener,
|
||||||
VectorBaseBottomSheetDialogFragment.ResultListener {
|
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 ->
|
private val foregroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently ->
|
||||||
if (allGranted) {
|
if (allGranted) {
|
||||||
startLiveLocationSharing()
|
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
|
// 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)) {
|
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?) {
|
override fun onBottomSheetResult(resultCode: Int, data: Any?) {
|
||||||
if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK) {
|
if (resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK) {
|
||||||
(data as? Long)?.let { viewModel.handle(LocationSharingAction.StartLiveLocationSharing(it)) }
|
(data as? Long)?.let { viewModel.handle(LocationSharingAction.StartLiveLocationSharing(it)) }
|
||||||
|
|||||||
@ -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.
|
* 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.
|
* This should not be shown if the user already enabled the labs flag.
|
||||||
*/
|
*/
|
||||||
class LiveLocationLabsFlagPromotionBottomSheet
|
class LiveLocationLabsFlagPromotionBottomSheet :
|
||||||
: VectorBaseBottomSheetDialogFragment<BottomSheetLiveLocationLabsFlagPromotionBinding>() {
|
VectorBaseBottomSheetDialogFragment<BottomSheetLiveLocationLabsFlagPromotionBinding>() {
|
||||||
|
|
||||||
|
override val showExpanded = true
|
||||||
|
|
||||||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetLiveLocationLabsFlagPromotionBinding {
|
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetLiveLocationLabsFlagPromotionBinding {
|
||||||
return BottomSheetLiveLocationLabsFlagPromotionBinding.inflate(inflater, container, false)
|
return BottomSheetLiveLocationLabsFlagPromotionBinding.inflate(inflater, container, false)
|
||||||
|
|||||||
@ -1047,6 +1047,12 @@ class VectorPreferences @Inject constructor(
|
|||||||
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, false)
|
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.
|
* Indicates whether or not thread messages are enabled.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user