From 8e17fa285d5e32656a9297d105626cfd1678bf89 Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 1 May 2018 12:03:35 +0200 Subject: [PATCH] allow use of share location plugin with setting --- .../ui/ConversationFragment.java | 3 +- .../conversations/ui/SettingsActivity.java | 10 ++ .../siacs/conversations/utils/GeoHelper.java | 24 ++++ src/main/res/values/defaults.xml | 1 + src/main/res/values/strings.xml | 2 + src/main/res/xml/preferences.xml | 135 ++++++++++-------- 6 files changed, 113 insertions(+), 62 deletions(-) diff --git a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java index 8d0bec3f7..912183fea 100644 --- a/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java +++ b/src/main/java/eu/siacs/conversations/ui/ConversationFragment.java @@ -95,6 +95,7 @@ import eu.siacs.conversations.ui.util.SendButtonAction; import eu.siacs.conversations.ui.util.SendButtonTool; import eu.siacs.conversations.ui.util.ShareUtil; import eu.siacs.conversations.ui.widget.EditMessage; +import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.MessageUtils; import eu.siacs.conversations.utils.NickValidityChecker; import eu.siacs.conversations.utils.QuickLoader; @@ -1498,7 +1499,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke intent = new Intent(getActivity(), RecordingActivity.class); break; case ATTACHMENT_CHOICE_LOCATION: - intent = new Intent(getActivity(), ShareLocationActivity.class); + intent = GeoHelper.getFetchIntent(activity); break; } if (intent.resolveActivity(getActivity().getPackageManager()) != null) { diff --git a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java index e143e48ee..fdd7adc49 100644 --- a/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java +++ b/src/main/java/eu/siacs/conversations/ui/SettingsActivity.java @@ -1,5 +1,6 @@ package eu.siacs.conversations.ui; +import android.preference.CheckBoxPreference; import android.support.annotation.NonNull; import android.support.v7.app.AlertDialog; import android.app.FragmentManager; @@ -37,6 +38,7 @@ import eu.siacs.conversations.entities.Account; import eu.siacs.conversations.services.ExportLogsService; import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.ui.util.Color; +import eu.siacs.conversations.utils.GeoHelper; import eu.siacs.conversations.utils.TimeframeUtils; import rocks.xmpp.addr.Jid; @@ -98,6 +100,14 @@ public class SettingsActivity extends XmppActivity implements PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen"); + PreferenceCategory attachmentsCategory = (PreferenceCategory) mSettingsFragment.findPreference("attachments"); + CheckBoxPreference locationPlugin = (CheckBoxPreference) mSettingsFragment.findPreference("use_share_location_plugin"); + if (attachmentsCategory != null && locationPlugin != null) { + if (!GeoHelper.isLocationPluginInstalled(this)) { + attachmentsCategory.removePreference(locationPlugin); + } + } + //this feature is only available on Huawei Android 6. PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei"); if (huaweiPreferenceScreen != null) { diff --git a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java index 0c1535547..a2df7737e 100644 --- a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java @@ -1,7 +1,10 @@ package eu.siacs.conversations.utils; +import android.app.Activity; import android.content.Intent; +import android.content.SharedPreferences; import android.net.Uri; +import android.preference.PreferenceManager; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -9,15 +12,36 @@ import java.util.ArrayList; import java.util.regex.Matcher; import java.util.regex.Pattern; +import eu.siacs.conversations.R; import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; +import eu.siacs.conversations.ui.ShareLocationActivity; public class GeoHelper { + + private static final String SHARE_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.request"; + public static Pattern GEO_URI = Pattern.compile("geo:([\\-0-9.]+),([\\-0-9.]+)(?:,([\\-0-9.]+))?(?:\\?(.*))?", Pattern.CASE_INSENSITIVE); + public static boolean isLocationPluginInstalled(Activity activity) { + return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(activity.getPackageManager()) != null; + } + public static boolean isLocationPluginInstalledAndDesired(Activity activity) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity); + final boolean configured = preferences.getBoolean("use_share_location_plugin", activity.getResources().getBoolean(R.bool.use_share_location_plugin)); + return configured && isLocationPluginInstalled(activity); + } + + public static Intent getFetchIntent(Activity activity) { + if (isLocationPluginInstalledAndDesired(activity)) { + return new Intent(SHARE_LOCATION_PACKAGE_NAME); + } else { + return new Intent(activity, ShareLocationActivity.class); + } + } public static ArrayList createGeoIntentsFromMessage(Message message) { final ArrayList intents = new ArrayList<>(); diff --git a/src/main/res/values/defaults.xml b/src/main/res/values/defaults.xml index f3a641dd4..5c4cee785 100644 --- a/src/main/res/values/defaults.xml +++ b/src/main/res/values/defaults.xml @@ -43,4 +43,5 @@ true default_on small + false diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 9ef9e4cca..a36dce9d7 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -706,4 +706,6 @@ Search messages GIF View conversation + Share Location Plugin + Use the Share Location Plugin instead of the build in map diff --git a/src/main/res/xml/preferences.xml b/src/main/res/xml/preferences.xml index 1d30a679a..9b58cc984 100644 --- a/src/main/res/xml/preferences.xml +++ b/src/main/res/xml/preferences.xml @@ -1,29 +1,30 @@ + android:background="?attr/color_background_secondary" + android:key="main_screen"> - + + android:targetClass="com.huawei.systemmanager.optimize.process.ProtectActivity" + android:targetPackage="com.huawei.systemmanager"/> - + android:summary="@string/pref_broadcast_last_activity_summary" + android:title="@string/pref_broadcast_last_activity"/> + + android:key="notifications_from_strangers" + android:summary="@string/pref_notifications_from_strangers_summary" + android:title="@string/pref_notifications_from_strangers"/> + android:summary="@string/pref_headsup_notifications_summary" + android:title="@string/pref_headsup_notifications"/> + android:summary="@string/pref_led_summary" + android:title="@string/pref_led"/> - + android:targetClass="eu.siacs.conversations.ui.SettingsActivity" + android:targetPackage="@string/applicationId"> + - + + android:summary="@string/pref_return_to_previous_summary" + android:title="@string/pref_return_to_previous"/> + + android:key="font_size" + android:summary="@string/pref_font_size_summary" + android:title="@string/pref_font_size"/> - + android:targetClass="eu.siacs.conversations.ui.SettingsActivity" + android:targetPackage="@string/applicationId"> + - + + android:summary="@string/pref_blind_trust_before_verification_summary" + android:title="@string/pref_blind_trust_before_verification"/> + android:title="@string/pref_automatically_delete_messages"/> + android:summary="@string/pref_allow_message_correction_summary" + android:title="@string/pref_allow_message_correction"/> + android:summary="@string/pref_delete_omemo_identities_summary" + android:title="@string/pref_delete_omemo_identities"/> + android:summary="@string/pref_scroll_to_bottom_summary" + android:title="@string/pref_scroll_to_bottom"/> + android:title="@string/pref_manually_change_presence"/> + android:title="@string/pref_away_when_screen_off"/> + android:title="@string/pref_dnd_on_silent_mode"/> + android:summary="@string/pref_treat_vibrate_as_dnd_summary" + android:title="@string/pref_treat_vibrate_as_silent"/>