Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/6350.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Promote live location labs flag
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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()
Expand All @@ -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)) }
Expand All @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1047,6 +1047,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.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -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>
6 changes: 6 additions & 0 deletions vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3088,4 +3088,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>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this the final copy? it's a little bit techy~

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes it is. I think it is not so hard to understand for users.

<string name="live_location_labs_promotion_switch_title">Enable location sharing</string>

</resources>