Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-organize location settings flags [PSF-1062] #6244

Merged
merged 4 commits into from
Jun 8, 2022
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/6244.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Re-organize location settings flags
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ import com.airbnb.mvrx.fragmentViewModel
import com.airbnb.mvrx.withState
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.vanniktech.emoji.EmojiPopup
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.animations.play
import im.vector.app.core.dialogs.ConfirmationDialogBuilder
Expand Down Expand Up @@ -1552,7 +1553,7 @@ class TimelineFragment @Inject constructor(
attachmentTypeSelector = AttachmentTypeSelectorView(vectorBaseActivity, vectorBaseActivity.layoutInflater, this@TimelineFragment)
attachmentTypeSelector.setAttachmentVisibility(
AttachmentTypeSelectorView.Type.LOCATION,
vectorPreferences.isLocationSharingEnabled()
BuildConfig.enableLocationSharing
Copy link
Contributor

Choose a reason for hiding this comment

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

if we use the VectorFeatures with the default value set to BuildConfig.enableLocationSharing then we'll also be able to enable/disable location sharing without recompiling the app

)
attachmentTypeSelector.setAttachmentVisibility(
AttachmentTypeSelectorView.Type.POLL, !isThreadTimeLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,7 @@ class MessageItemFactory @Inject constructor(
is MessageAudioContent -> buildAudioContent(params, messageContent, informationData, highlight, attributes)
is MessageVerificationRequestContent -> buildVerificationRequestMessageItem(messageContent, informationData, highlight, callback, attributes)
is MessagePollContent -> buildPollItem(messageContent, informationData, highlight, callback, attributes)
is MessageLocationContent -> {
if (vectorPreferences.labsRenderLocationsInTimeline()) {
buildLocationItem(messageContent, informationData, highlight, attributes)
} else {
buildMessageTextItem(messageContent.body, false, informationData, highlight, callback, attributes)
}
}
is MessageLocationContent -> buildLocationItem(messageContent, informationData, highlight, attributes)
is MessageBeaconInfoContent -> liveLocationShareMessageItemFactory.create(params.event, highlight, attributes)
else -> buildNotHandledMessageItem(messageContent, informationData, highlight, callback, attributes)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,15 @@ class TimelineMessageLayoutFactory @Inject constructor(
MessageType.MSGTYPE_STICKER_LOCAL,
MessageType.MSGTYPE_EMOTE,
MessageType.MSGTYPE_BEACON_INFO,
MessageType.MSGTYPE_LOCATION,
MessageType.MSGTYPE_BEACON_LOCATION_DATA,
)
private val MSG_TYPES_WITH_TIMESTAMP_INSIDE_MESSAGE = setOf(
MessageType.MSGTYPE_IMAGE,
MessageType.MSGTYPE_VIDEO,
MessageType.MSGTYPE_BEACON_INFO,
)

private val MSG_TYPES_WITH_LOCATION_DATA = setOf(
MessageType.MSGTYPE_LOCATION,
MessageType.MSGTYPE_BEACON_LOCATION_DATA
MessageType.MSGTYPE_BEACON_LOCATION_DATA,
)
}

Expand Down Expand Up @@ -147,22 +146,19 @@ class TimelineMessageLayoutFactory @Inject constructor(

private fun MessageContent?.isPseudoBubble(): Boolean {
if (this == null) return false
if (msgType == MessageType.MSGTYPE_LOCATION) return vectorPreferences.labsRenderLocationsInTimeline()
return this.msgType in MSG_TYPES_WITH_PSEUDO_BUBBLE_LAYOUT
}

private fun MessageContent?.timestampInsideMessage(): Boolean {
return when {
this == null -> false
msgType in MSG_TYPES_WITH_LOCATION_DATA -> vectorPreferences.labsRenderLocationsInTimeline()
else -> msgType in MSG_TYPES_WITH_TIMESTAMP_INSIDE_MESSAGE
}
}

private fun MessageContent?.shouldAddMessageOverlay(): Boolean {
return when {
this == null || msgType == MessageType.MSGTYPE_BEACON_INFO -> false
msgType == MessageType.MSGTYPE_LOCATION -> vectorPreferences.labsRenderLocationsInTimeline()
else -> msgType in MSG_TYPES_WITH_TIMESTAMP_INSIDE_MESSAGE
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@ class VectorPreferences @Inject constructor(

private const val DID_ASK_TO_ENABLE_SESSION_PUSH = "DID_ASK_TO_ENABLE_SESSION_PUSH"

// Location Sharing
const val SETTINGS_PREF_ENABLE_LOCATION_SHARING = "SETTINGS_PREF_ENABLE_LOCATION_SHARING"

private const val MEDIA_SAVING_3_DAYS = 0
private const val MEDIA_SAVING_1_WEEK = 1
private const val MEDIA_SAVING_1_MONTH = 2
Expand All @@ -203,7 +200,6 @@ class VectorPreferences @Inject constructor(

private const val TAKE_PHOTO_VIDEO_MODE = "TAKE_PHOTO_VIDEO_MODE"

private const val SETTINGS_LABS_RENDER_LOCATIONS_IN_TIMELINE = "SETTINGS_LABS_RENDER_LOCATIONS_IN_TIMELINE"
private const val SETTINGS_LABS_ENABLE_LIVE_LOCATION = "SETTINGS_LABS_ENABLE_LIVE_LOCATION"

// This key will be used to identify clients with the old thread support enabled io.element.thread
Expand Down Expand Up @@ -1044,14 +1040,6 @@ class VectorPreferences @Inject constructor(
}
}

fun isLocationSharingEnabled(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_PREF_ENABLE_LOCATION_SHARING, false) && BuildConfig.enableLocationSharing
}

fun labsRenderLocationsInTimeline(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_LABS_RENDER_LOCATIONS_IN_TIMELINE, true)
}

fun labsEnableLiveLocation(): Boolean {
return defaultPrefs.getBoolean(SETTINGS_LABS_ENABLE_LIVE_LOCATION, false)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import androidx.core.view.children
import androidx.lifecycle.lifecycleScope
import androidx.preference.Preference
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import im.vector.app.BuildConfig
import im.vector.app.R
import im.vector.app.core.dialogs.PhotoOrVideoDialog
import im.vector.app.core.extensions.restart
Expand Down Expand Up @@ -173,8 +172,6 @@ class VectorSettingsPreferencesFragment @Inject constructor(
})
true
}

findPreference<VectorSwitchPreference>(VectorPreferences.SETTINGS_PREF_ENABLE_LOCATION_SHARING)?.isVisible = BuildConfig.enableLocationSharing
}

private fun updateTakePhotoOrVideoPreferenceSummary() {
Expand Down
9 changes: 6 additions & 3 deletions vector/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3017,9 +3017,12 @@
<string name="location_not_available_dialog_title">${app_name} could not access your location</string>
<string name="location_not_available_dialog_content">${app_name} could not access your location. Please try again later.</string>
<string name="location_share_external">Open with</string>
<string name="settings_enable_location_sharing">Enable location sharing</string>
<string name="settings_enable_location_sharing_summary">Once enabled you will be able to send your location to any room</string>
<string name="labs_render_locations_in_timeline">Render user locations in the timeline</string>
<!--TODO delete-->
<string name="settings_enable_location_sharing" tools:ignore="UnusedResources">Enable location sharing</string>
<!--TODO delete-->
<string name="settings_enable_location_sharing_summary" tools:ignore="UnusedResources">Once enabled you will be able to send your location to any room</string>
<!--TODO delete-->
<string name="labs_render_locations_in_timeline" tools:ignore="UnusedResources">Render user locations in the timeline</string>
<string name="location_timeline_failed_to_load_map">Failed to load map</string>
<string name="location_share_live_enabled">Live location enabled</string>
<string name="location_share_live_started">Loading live location…</string>
Expand Down
5 changes: 0 additions & 5 deletions vector/src/main/res/xml/vector_settings_labs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,6 @@
android:summary="@string/labs_auto_report_uisi_desc"
android:title="@string/labs_auto_report_uisi" />

<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="true"
android:key="SETTINGS_LABS_RENDER_LOCATIONS_IN_TIMELINE"
android:title="@string/labs_render_locations_in_timeline" />

<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_LABS_ENABLE_LIVE_LOCATION"
Expand Down
6 changes: 0 additions & 6 deletions vector/src/main/res/xml/vector_settings_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@
android:title="@string/option_take_photo_video"
tools:summary="@string/option_always_ask" />

<im.vector.app.core.preference.VectorSwitchPreference
android:defaultValue="false"
android:key="SETTINGS_PREF_ENABLE_LOCATION_SHARING"
android:summary="@string/settings_enable_location_sharing_summary"
android:title="@string/settings_enable_location_sharing" />

</im.vector.app.core.preference.VectorPreferenceCategory>

<im.vector.app.core.preference.VectorPreferenceCategory android:title="@string/settings_category_timeline">
Expand Down