Merge pull request #6350 from vector-im/feature/ons/promote_live_location_labs_flag

Promote live location labs flag [PSF-959]
This commit is contained in:
Onuray Sahin 2022-06-29 15:26:39 +03:00 committed by GitHub
commit abea68557b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 164 additions and 14 deletions

1
changelog.d/6350.feature Normal file
View file

@ -0,0 +1 @@
Promote live location labs flag

View file

@ -24,6 +24,7 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.isGone
import androidx.fragment.app.setFragmentResultListener
import androidx.lifecycle.lifecycleScope
import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
@ -39,6 +40,7 @@ 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
@ -71,6 +73,15 @@ class LocationSharingFragment @Inject constructor(
return FragmentLocationSharingBinding.inflate(inflater, container, false)
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setFragmentResultListener(LiveLocationLabsFlagPromotionBottomSheet.REQUEST_KEY) { _, bundle ->
val isApproved = bundle.getBoolean(LiveLocationLabsFlagPromotionBottomSheet.BUNDLE_KEY_LABS_APPROVAL)
handleLiveLocationLabsFlagPromotionResult(isApproved)
}
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
@ -194,6 +205,22 @@ class LocationSharingFragment @Inject constructor(
}
}
private fun handleLiveLocationLabsFlagPromotionResult(isApproved: Boolean) {
if (isApproved) {
vectorPreferences.setLiveLocationLabsEnabled(isEnabled = true)
startLiveLocationSharing()
}
}
private fun tryStartLiveLocationSharing() {
if (vectorPreferences.labsEnableLiveLocation()) {
startLiveLocationSharing()
} else {
LiveLocationLabsFlagPromotionBottomSheet.newInstance()
.show(requireActivity().supportFragmentManager, "DISPLAY_LIVE_LOCATION_LABS_FLAG_PROMOTION")
}
}
private val foregroundLocationResultLauncher = registerForPermissionsResult { allGranted, deniedPermanently ->
if (allGranted) {
startLiveLocationSharing()
@ -202,18 +229,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)) }
@ -223,13 +246,7 @@ class LocationSharingFragment @Inject constructor(
private fun updateMap(state: LocationSharingViewState) {
// first, update the options view
val options: Set<LocationSharingOption> = when (state.areTargetAndUserLocationEqual) {
true -> {
if (vectorPreferences.labsEnableLiveLocation()) {
setOf(LocationSharingOption.USER_CURRENT, LocationSharingOption.USER_LIVE)
} else {
setOf(LocationSharingOption.USER_CURRENT)
}
}
true -> setOf(LocationSharingOption.USER_CURRENT, LocationSharingOption.USER_LIVE)
false -> setOf(LocationSharingOption.PINNED)
else -> emptySet()
}

View file

@ -0,0 +1,64 @@
/*
* Copyright (c) 2022 New Vector Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package im.vector.app.features.location.live
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.setFragmentResult
import im.vector.app.core.platform.VectorBaseBottomSheetDialogFragment
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<BottomSheetLiveLocationLabsFlagPromotionBinding>() {
override val showExpanded = true
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): BottomSheetLiveLocationLabsFlagPromotionBinding {
return BottomSheetLiveLocationLabsFlagPromotionBinding.inflate(inflater, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initOkButton()
}
private fun initOkButton() {
views.promoteLiveLocationFlagOkButton.debouncedClicks {
val enableLabsFlag = views.promoteLiveLocationFlagSwitch.isChecked
setFragmentResult(REQUEST_KEY, Bundle().apply {
putBoolean(BUNDLE_KEY_LABS_APPROVAL, enableLabsFlag)
})
dismiss()
}
}
companion object {
const val REQUEST_KEY = "LiveLocationLabsFlagPromotionBottomSheetRequest"
const val BUNDLE_KEY_LABS_APPROVAL = "BUNDLE_KEY_LABS_APPROVAL"
fun newInstance(): LiveLocationLabsFlagPromotionBottomSheet {
return LiveLocationLabsFlagPromotionBottomSheet()
}
}
}

View file

@ -1051,6 +1051,12 @@ class VectorPreferences @Inject constructor(
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, false)
}
fun setLiveLocationLabsEnabled(isEnabled: Boolean) {
defaultPrefs.edit {
putBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, isEnabled)
}
}
/**
* Indicates whether or not thread messages are enabled.
*/

View file

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?colorSurface"
android:orientation="vertical"
android:paddingHorizontal="16dp"
android:paddingBottom="8dp">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="30dp"
android:background="@drawable/circle"
android:backgroundTint="?vctr_live_location"
android:importantForAccessibility="no"
android:padding="4dp"
android:src="@drawable/ic_attachment_location_live_white" />
<TextView
style="@style/TextAppearance.Vector.Headline.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:text="@string/live_location_labs_promotion_title" />
<TextView
style="@style/TextAppearance.Vector.Body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="24dp"
android:gravity="center"
android:text="@string/live_location_labs_promotion_description" />
<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/promoteLiveLocationFlagSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:text="@string/live_location_labs_promotion_switch_title"
app:switchPadding="8dp" />
<Button
android:id="@+id/promoteLiveLocationFlagOkButton"
style="@style/Widget.Vector.Button.Positive"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="@string/ok" />
</LinearLayout>

View file

@ -3092,4 +3092,10 @@
<string name="settings_troubleshoot_test_current_endpoint_failed">Cannot find the endpoint.</string>
<string name="settings_troubleshoot_test_current_gateway_title">Gateway</string>
<string name="settings_troubleshoot_test_current_gateway">Current gateway: %s</string>
<!-- Live Location Sharing Labs Flag Promotional BottomSheet -->
<string name="live_location_labs_promotion_title">Live location sharing</string>
<string name="live_location_labs_promotion_description">Please note: this is a labs feature using a temporary implementation. This means you will not be able to delete your location history, and advanced users will be able to see your location history even after you stop sharing your live location with this room.</string>
<string name="live_location_labs_promotion_switch_title">Enable location sharing</string>
</resources>