allow use of share location plugin with setting

This commit is contained in:
Daniel Gultsch 2018-05-01 12:03:35 +02:00
parent 35e6547db4
commit 8e17fa285d
6 changed files with 113 additions and 62 deletions

View file

@ -95,6 +95,7 @@ import eu.siacs.conversations.ui.util.SendButtonAction;
import eu.siacs.conversations.ui.util.SendButtonTool; import eu.siacs.conversations.ui.util.SendButtonTool;
import eu.siacs.conversations.ui.util.ShareUtil; import eu.siacs.conversations.ui.util.ShareUtil;
import eu.siacs.conversations.ui.widget.EditMessage; import eu.siacs.conversations.ui.widget.EditMessage;
import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.MessageUtils; import eu.siacs.conversations.utils.MessageUtils;
import eu.siacs.conversations.utils.NickValidityChecker; import eu.siacs.conversations.utils.NickValidityChecker;
import eu.siacs.conversations.utils.QuickLoader; import eu.siacs.conversations.utils.QuickLoader;
@ -1498,7 +1499,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke
intent = new Intent(getActivity(), RecordingActivity.class); intent = new Intent(getActivity(), RecordingActivity.class);
break; break;
case ATTACHMENT_CHOICE_LOCATION: case ATTACHMENT_CHOICE_LOCATION:
intent = new Intent(getActivity(), ShareLocationActivity.class); intent = GeoHelper.getFetchIntent(activity);
break; break;
} }
if (intent.resolveActivity(getActivity().getPackageManager()) != null) { if (intent.resolveActivity(getActivity().getPackageManager()) != null) {

View file

@ -1,5 +1,6 @@
package eu.siacs.conversations.ui; package eu.siacs.conversations.ui;
import android.preference.CheckBoxPreference;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.app.FragmentManager; 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.ExportLogsService;
import eu.siacs.conversations.services.MemorizingTrustManager; import eu.siacs.conversations.services.MemorizingTrustManager;
import eu.siacs.conversations.ui.util.Color; import eu.siacs.conversations.ui.util.Color;
import eu.siacs.conversations.utils.GeoHelper;
import eu.siacs.conversations.utils.TimeframeUtils; import eu.siacs.conversations.utils.TimeframeUtils;
import rocks.xmpp.addr.Jid; import rocks.xmpp.addr.Jid;
@ -98,6 +100,14 @@ public class SettingsActivity extends XmppActivity implements
PreferenceScreen mainPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("main_screen"); 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. //this feature is only available on Huawei Android 6.
PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei"); PreferenceScreen huaweiPreferenceScreen = (PreferenceScreen) mSettingsFragment.findPreference("huawei");
if (huaweiPreferenceScreen != null) { if (huaweiPreferenceScreen != null) {

View file

@ -1,7 +1,10 @@
package eu.siacs.conversations.utils; package eu.siacs.conversations.utils;
import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri; import android.net.Uri;
import android.preference.PreferenceManager;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -9,15 +12,36 @@ import java.util.ArrayList;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import eu.siacs.conversations.R;
import eu.siacs.conversations.entities.Contact; import eu.siacs.conversations.entities.Contact;
import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversation;
import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Conversational;
import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.entities.Message;
import eu.siacs.conversations.ui.ShareLocationActivity;
public class GeoHelper { 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 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<Intent> createGeoIntentsFromMessage(Message message) { public static ArrayList<Intent> createGeoIntentsFromMessage(Message message) {
final ArrayList<Intent> intents = new ArrayList<>(); final ArrayList<Intent> intents = new ArrayList<>();

View file

@ -43,4 +43,5 @@
<bool name="scroll_to_bottom">true</bool> <bool name="scroll_to_bottom">true</bool>
<string name="omemo_setting_default">default_on</string> <string name="omemo_setting_default">default_on</string>
<string name="default_font_size">small</string> <string name="default_font_size">small</string>
<bool name="use_share_location_plugin">false</bool>
</resources> </resources>

View file

@ -706,4 +706,6 @@
<string name="search_messages">Search messages</string> <string name="search_messages">Search messages</string>
<string name="gif">GIF</string> <string name="gif">GIF</string>
<string name="view_conversation">View conversation</string> <string name="view_conversation">View conversation</string>
<string name="pref_use_share_location_plugin">Share Location Plugin</string>
<string name="pref_use_share_location_plugin_summary">Use the Share Location Plugin instead of the build in map</string>
</resources> </resources>

View file

@ -1,29 +1,30 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen <PreferenceScreen
android:key="main_screen"
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
android:background="?attr/color_background_secondary"> android:background="?attr/color_background_secondary"
android:key="main_screen">
<PreferenceCategory android:title="@string/pref_general" <PreferenceCategory
android:key="general"> android:key="general"
android:title="@string/pref_general">
<PreferenceScreen <PreferenceScreen
android:key="huawei" android:key="huawei"
android:title="@string/huawei_protected_apps"
android:summary="@string/huawei_protected_apps_summary" android:summary="@string/huawei_protected_apps_summary"
android:title="@string/huawei_protected_apps"
> >
<intent <intent
android:targetPackage="com.huawei.systemmanager" android:targetClass="com.huawei.systemmanager.optimize.process.ProtectActivity"
android:targetClass="com.huawei.systemmanager.optimize.process.ProtectActivity"/> android:targetPackage="com.huawei.systemmanager"/>
</PreferenceScreen> </PreferenceScreen>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_privacy"> <PreferenceCategory android:title="@string/pref_privacy">
<ListPreference <ListPreference
android:key="omemo"
android:title="@string/pref_omemo_setting"
android:summary="@string/pref_omemo_setting_summary_default_on"
android:defaultValue="@string/omemo_setting_default" android:defaultValue="@string/omemo_setting_default"
android:entryValues="@array/omemo_setting_entry_values"
android:entries="@array/omemo_setting_entries" android:entries="@array/omemo_setting_entries"
android:entryValues="@array/omemo_setting_entry_values"
android:key="omemo"
android:summary="@string/pref_omemo_setting_summary_default_on"
android:title="@string/pref_omemo_setting"
/> />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/confirm_messages" android:defaultValue="@bool/confirm_messages"
@ -39,9 +40,9 @@
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/last_activity" android:defaultValue="@bool/last_activity"
android:key="last_activity" android:key="last_activity"
android:title="@string/pref_broadcast_last_activity" android:summary="@string/pref_broadcast_last_activity_summary"
android:summary="@string/pref_broadcast_last_activity_summary"/> android:title="@string/pref_broadcast_last_activity"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_notification_settings"> <PreferenceCategory android:title="@string/pref_notification_settings">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/show_notification" android:defaultValue="@bool/show_notification"
@ -50,16 +51,16 @@
android:title="@string/pref_notifications"/> android:title="@string/pref_notifications"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/notifications_from_strangers" android:defaultValue="@bool/notifications_from_strangers"
android:key="notifications_from_strangers"
android:dependency="show_notification" android:dependency="show_notification"
android:title="@string/pref_notifications_from_strangers" android:key="notifications_from_strangers"
android:summary="@string/pref_notifications_from_strangers_summary"/> android:summary="@string/pref_notifications_from_strangers_summary"
android:title="@string/pref_notifications_from_strangers"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/headsup_notifications" android:defaultValue="@bool/headsup_notifications"
android:dependency="show_notification" android:dependency="show_notification"
android:key="notification_headsup" android:key="notification_headsup"
android:title="@string/pref_headsup_notifications" android:summary="@string/pref_headsup_notifications_summary"
android:summary="@string/pref_headsup_notifications_summary"/> android:title="@string/pref_headsup_notifications"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/vibrate_on_notification" android:defaultValue="@bool/vibrate_on_notification"
android:dependency="show_notification" android:dependency="show_notification"
@ -70,8 +71,8 @@
android:defaultValue="@bool/led" android:defaultValue="@bool/led"
android:dependency="show_notification" android:dependency="show_notification"
android:key="led" android:key="led"
android:title="@string/pref_led" android:summary="@string/pref_led_summary"
android:summary="@string/pref_led_summary"/> android:title="@string/pref_led"/>
<RingtonePreference <RingtonePreference
android:defaultValue="@string/notification_ringtone" android:defaultValue="@string/notification_ringtone"
android:dependency="show_notification" android:dependency="show_notification"
@ -86,9 +87,11 @@
android:title="@string/title_pref_quiet_hours"> android:title="@string/title_pref_quiet_hours">
<intent <intent
android:action="android.intent.action.VIEW" android:action="android.intent.action.VIEW"
android:targetPackage="@string/applicationId" android:targetClass="eu.siacs.conversations.ui.SettingsActivity"
android:targetClass="eu.siacs.conversations.ui.SettingsActivity" > android:targetPackage="@string/applicationId">
<extra android:name="page" android:value="quiet_hours" /> <extra
android:name="page"
android:value="quiet_hours"/>
</intent> </intent>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/enable_quiet_hours" android:defaultValue="@bool/enable_quiet_hours"
@ -109,16 +112,18 @@
android:title="@string/title_pref_quiet_hours_end_time"/> android:title="@string/title_pref_quiet_hours_end_time"/>
</PreferenceScreen> </PreferenceScreen>
<ListPreference <ListPreference
android:dependency="show_notification"
android:key="grace_period_length"
android:title="@string/pref_notification_grace_period"
android:summary="@string/pref_notification_grace_period_summary"
android:defaultValue="@integer/grace_period" android:defaultValue="@integer/grace_period"
android:dependency="show_notification"
android:entries="@array/grace_periods" android:entries="@array/grace_periods"
android:entryValues="@array/grace_periods_values" android:entryValues="@array/grace_periods_values"
android:key="grace_period_length"
android:summary="@string/pref_notification_grace_period_summary"
android:title="@string/pref_notification_grace_period"
/> />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_attachments"> <PreferenceCategory
android:key="attachments"
android:title="@string/pref_attachments">
<ListPreference <ListPreference
android:defaultValue="@integer/auto_accept_filesize" android:defaultValue="@integer/auto_accept_filesize"
android:entries="@array/filesizes" android:entries="@array/filesizes"
@ -136,8 +141,13 @@
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/return_to_previous" android:defaultValue="@bool/return_to_previous"
android:key="return_to_previous" android:key="return_to_previous"
android:title="@string/pref_return_to_previous" android:summary="@string/pref_return_to_previous_summary"
android:summary="@string/pref_return_to_previous_summary"/> android:title="@string/pref_return_to_previous"/>
<CheckBoxPreference
android:defaultValue="@bool/use_share_location_plugin"
android:key="use_share_location_plugin"
android:summary="@string/pref_use_share_location_plugin_summary"
android:title="@string/pref_use_share_location_plugin"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_ui_options"> <PreferenceCategory android:title="@string/pref_ui_options">
<ListPreference <ListPreference
@ -154,11 +164,11 @@
android:title="@string/pref_use_green_background"/> android:title="@string/pref_use_green_background"/>
<ListPreference <ListPreference
android:defaultValue="@string/default_font_size" android:defaultValue="@string/default_font_size"
android:key="font_size" android:entries="@array/font_size_entries"
android:title="@string/pref_font_size"
android:summary="@string/pref_font_size_summary"
android:entryValues="@array/font_size_entry_values" android:entryValues="@array/font_size_entry_values"
android:entries="@array/font_size_entries"/> android:key="font_size"
android:summary="@string/pref_font_size_summary"
android:title="@string/pref_font_size"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/use_subject" android:defaultValue="@bool/use_subject"
android:key="use_subject" android:key="use_subject"
@ -192,22 +202,25 @@
android:title="@string/pref_expert_options"> android:title="@string/pref_expert_options">
<intent <intent
android:action="android.intent.action.VIEW" android:action="android.intent.action.VIEW"
android:targetPackage="@string/applicationId" android:targetClass="eu.siacs.conversations.ui.SettingsActivity"
android:targetClass="eu.siacs.conversations.ui.SettingsActivity" > android:targetPackage="@string/applicationId">
<extra android:name="page" android:value="expert" /> <extra
android:name="page"
android:value="expert"/>
</intent> </intent>
<PreferenceCategory android:title="@string/pref_security_settings" <PreferenceCategory
android:key="security_options"> android:key="security_options"
android:title="@string/pref_security_settings">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/btbv" android:defaultValue="@bool/btbv"
android:key="btbv" android:key="btbv"
android:title="@string/pref_blind_trust_before_verification" android:summary="@string/pref_blind_trust_before_verification_summary"
android:summary="@string/pref_blind_trust_before_verification_summary"/> android:title="@string/pref_blind_trust_before_verification"/>
<ListPreference <ListPreference
android:defaultValue="@integer/automatic_message_deletion"
android:key="automatic_message_deletion" android:key="automatic_message_deletion"
android:title="@string/pref_automatically_delete_messages"
android:summary="@string/pref_automatically_delete_messages_description" android:summary="@string/pref_automatically_delete_messages_description"
android:defaultValue="@integer/automatic_message_deletion"/> android:title="@string/pref_automatically_delete_messages"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/dont_trust_system_cas" android:defaultValue="@bool/dont_trust_system_cas"
android:key="dont_trust_system_cas" android:key="dont_trust_system_cas"
@ -225,8 +238,8 @@
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/allow_message_correction" android:defaultValue="@bool/allow_message_correction"
android:key="allow_message_correction" android:key="allow_message_correction"
android:title="@string/pref_allow_message_correction" android:summary="@string/pref_allow_message_correction_summary"
android:summary="@string/pref_allow_message_correction_summary"/> android:title="@string/pref_allow_message_correction"/>
<Preference <Preference
android:key="clean_cache" android:key="clean_cache"
android:summary="@string/pref_clean_cache_summary" android:summary="@string/pref_clean_cache_summary"
@ -237,8 +250,8 @@
android:title="@string/pref_clean_private_storage"/> android:title="@string/pref_clean_private_storage"/>
<Preference <Preference
android:key="delete_omemo_identities" android:key="delete_omemo_identities"
android:title="@string/pref_delete_omemo_identities" android:summary="@string/pref_delete_omemo_identities_summary"
android:summary="@string/pref_delete_omemo_identities_summary"/> android:title="@string/pref_delete_omemo_identities"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="connection_options" android:key="connection_options"
@ -268,41 +281,41 @@
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/scroll_to_bottom" android:defaultValue="@bool/scroll_to_bottom"
android:key="scroll_to_bottom" android:key="scroll_to_bottom"
android:title="@string/pref_scroll_to_bottom" android:summary="@string/pref_scroll_to_bottom_summary"
android:summary="@string/pref_scroll_to_bottom_summary"/> android:title="@string/pref_scroll_to_bottom"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_presence_settings"> <PreferenceCategory android:title="@string/pref_presence_settings">
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/manually_change_presence" android:defaultValue="@bool/manually_change_presence"
android:disableDependentsState="true"
android:key="manually_change_presence" android:key="manually_change_presence"
android:title="@string/pref_manually_change_presence"
android:summary="@string/pref_manually_change_presence_summary" android:summary="@string/pref_manually_change_presence_summary"
android:disableDependentsState="true"/> android:title="@string/pref_manually_change_presence"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/away_when_screen_off" android:defaultValue="@bool/away_when_screen_off"
android:dependency="manually_change_presence"
android:key="away_when_screen_off" android:key="away_when_screen_off"
android:summary="@string/pref_away_when_screen_off_summary" android:summary="@string/pref_away_when_screen_off_summary"
android:title="@string/pref_away_when_screen_off" android:title="@string/pref_away_when_screen_off"/>
android:dependency="manually_change_presence"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/dnd_on_silent_mode" android:defaultValue="@bool/dnd_on_silent_mode"
android:dependency="manually_change_presence"
android:key="dnd_on_silent_mode" android:key="dnd_on_silent_mode"
android:summary="@string/pref_dnd_on_silent_mode_summary" android:summary="@string/pref_dnd_on_silent_mode_summary"
android:title="@string/pref_dnd_on_silent_mode" android:title="@string/pref_dnd_on_silent_mode"/>
android:dependency="manually_change_presence"/>
<CheckBoxPreference <CheckBoxPreference
android:dependency="dnd_on_silent_mode"
android:defaultValue="@bool/treat_vibrate_as_silent" android:defaultValue="@bool/treat_vibrate_as_silent"
android:dependency="dnd_on_silent_mode"
android:key="treat_vibrate_as_silent" android:key="treat_vibrate_as_silent"
android:title="@string/pref_treat_vibrate_as_silent" android:summary="@string/pref_treat_vibrate_as_dnd_summary"
android:summary="@string/pref_treat_vibrate_as_dnd_summary"/> android:title="@string/pref_treat_vibrate_as_silent"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/pref_expert_options_other"> <PreferenceCategory android:title="@string/pref_expert_options_other">
<CheckBoxPreference <CheckBoxPreference
android:key="autojoin"
android:defaultValue="@bool/autojoin" android:defaultValue="@bool/autojoin"
android:title="@string/pref_autojoin" android:key="autojoin"
android:summary="@string/pref_autojoin_summary" android:summary="@string/pref_autojoin_summary"
android:title="@string/pref_autojoin"
/> />
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="@bool/indicate_received" android:defaultValue="@bool/indicate_received"