Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -39,6 +39,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 @@ -194,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) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this comment above could be replaced by extracting this condition to its own function

private fun hasUserOptedInToLiveLocationLabs(code, data) {
  return resultCode == VectorBaseBottomSheetDialogFragment.ResultListener.RESULT_OK && (data as? Boolean) == true 
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, done.

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()
Expand All @@ -202,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)) }
Expand All @@ -223,13 +239,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,59 @@
/*
* 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 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
resultListener?.onBottomSheetResult(ResultListener.RESULT_OK, enableLabsFlag)
dismiss()
}
}

companion object {
fun newInstance(resultListener: ResultListener): LiveLocationLabsFlagPromotionBottomSheet {
return LiveLocationLabsFlagPromotionBottomSheet().also {
it.resultListener = resultListener

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Not a big big deal, but we will loose the listener if the Fragment is recreated by system

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Fixed.

}
}
}
}
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() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

add parameter?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

defaultPrefs.edit {
putBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, true)
}
}

/**
* 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
Copy Markdown
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
Copy Markdown
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>