From 949b77c353d4bd1499b846ce475b73e7d983f00b Mon Sep 17 00:00:00 2001 From: Daniel Gultsch Date: Tue, 1 May 2018 12:55:11 +0200 Subject: [PATCH] make show location depend on plugin setting --- src/main/AndroidManifest.xml | 197 +++++++++--------- .../services/NotificationService.java | 2 +- .../ui/adapter/MessageAdapter.java | 2 +- .../siacs/conversations/utils/GeoHelper.java | 56 +++-- 4 files changed, 135 insertions(+), 122 deletions(-) diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 4e40ac435..0c850f3ff 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -1,62 +1,74 @@ + xmlns:tools="http://schemas.android.com/tools" + package="eu.siacs.conversations"> - - - - - - - - - - - - - + + + + + + + + + + + + + - - - + + + - + + tools:node="remove"/> - + - - + + - + - + - - - - + + + + + @@ -65,71 +77,61 @@ android:label="@string/search_messages"/> + android:configChanges="orientation|screenSize" + android:theme="@style/ConversationsTheme.Dialog"/> - - - - - - - - - - + android:label="@string/title_activity_show_location"/> - + - + + android:minWidth="300dp" + android:windowSoftInputMode="stateHidden"/> + android:windowSoftInputMode="stateAlwaysHidden"/> - + - - + + - + - + - - + + - - - - + + + + - + - + - - + + - + + android:label="@string/title_activity_settings"/> + android:label="@string/title_activity_choose_contact"/> + android:label="@string/title_activity_block_list"/> + android:label="@string/change_password_on_server"/> + android:launchMode="singleTask"/> + android:launchMode="singleTop"/> + android:windowSoftInputMode="stateHidden|adjustResize"/> + android:windowSoftInputMode="stateHidden"/> + android:windowSoftInputMode="stateHidden"/> + android:windowSoftInputMode="stateHidden"/> - + - + - + - + - + - + - + - + - + + android:value=".services.ContactChooserTargetService"/> + android:windowSoftInputMode="stateAlwaysHidden"/> + android:value="eu.siacs.conversations.ui.SettingsActivity"/> - - + + - + - + - + @@ -247,18 +249,19 @@ android:grantUriPermissions="true"> + android:resource="@xml/file_paths"/> - - + diff --git a/src/main/java/eu/siacs/conversations/services/NotificationService.java b/src/main/java/eu/siacs/conversations/services/NotificationService.java index 6cec6c9eb..550f63758 100644 --- a/src/main/java/eu/siacs/conversations/services/NotificationService.java +++ b/src/main/java/eu/siacs/conversations/services/NotificationService.java @@ -603,7 +603,7 @@ public class NotificationService { } private PendingIntent createShowLocationIntent(final Message message) { - Iterable intents = GeoHelper.createGeoIntentsFromMessage(message); + Iterable intents = GeoHelper.createGeoIntentsFromMessage(mXmppConnectionService, message); for (Intent intent : intents) { if (intent.resolveActivity(mXmppConnectionService.getPackageManager()) != null) { return PendingIntent.getActivity(mXmppConnectionService, generateRequestCode(message.getConversation(), 18), intent, PendingIntent.FLAG_UPDATE_CURRENT); diff --git a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java index 77dac289e..6a2c83d9c 100644 --- a/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java +++ b/src/main/java/eu/siacs/conversations/ui/adapter/MessageAdapter.java @@ -965,7 +965,7 @@ public class MessageAdapter extends ArrayAdapter implements CopyTextVie } public void showLocation(Message message) { - for (Intent intent : GeoHelper.createGeoIntentsFromMessage(message)) { + for (Intent intent : GeoHelper.createGeoIntentsFromMessage(activity, message)) { if (intent.resolveActivity(getContext().getPackageManager()) != null) { getContext().startActivity(intent); return; diff --git a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java index a2df7737e..0d627f872 100644 --- a/src/main/java/eu/siacs/conversations/utils/GeoHelper.java +++ b/src/main/java/eu/siacs/conversations/utils/GeoHelper.java @@ -1,6 +1,7 @@ package eu.siacs.conversations.utils; import android.app.Activity; +import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.net.Uri; @@ -18,32 +19,34 @@ import eu.siacs.conversations.entities.Conversation; import eu.siacs.conversations.entities.Conversational; import eu.siacs.conversations.entities.Message; import eu.siacs.conversations.ui.ShareLocationActivity; +import eu.siacs.conversations.ui.ShowLocationActivity; public class GeoHelper { private static final String SHARE_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.request"; + private static final String SHOW_LOCATION_PACKAGE_NAME = "eu.siacs.conversations.location.show"; 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 isLocationPluginInstalled(Context context) { + return new Intent(SHARE_LOCATION_PACKAGE_NAME).resolveActivity(context.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 boolean isLocationPluginInstalledAndDesired(Context context) { + SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); + final boolean configured = preferences.getBoolean("use_share_location_plugin", context.getResources().getBoolean(R.bool.use_share_location_plugin)); + return configured && isLocationPluginInstalled(context); } - public static Intent getFetchIntent(Activity activity) { - if (isLocationPluginInstalledAndDesired(activity)) { + public static Intent getFetchIntent(Context context) { + if (isLocationPluginInstalledAndDesired(context)) { return new Intent(SHARE_LOCATION_PACKAGE_NAME); } else { - return new Intent(activity, ShareLocationActivity.class); + return new Intent(context, ShareLocationActivity.class); } } - public static ArrayList createGeoIntentsFromMessage(Message message) { + public static ArrayList createGeoIntentsFromMessage(Context context, Message message) { final ArrayList intents = new ArrayList<>(); Matcher matcher = GEO_URI.matcher(message.getBody()); if (!matcher.matches()) { @@ -75,22 +78,29 @@ public class GeoHelper { label = ""; } - Intent locationPluginIntent = new Intent("eu.siacs.conversations.location.show"); - locationPluginIntent.putExtra("latitude",latitude); - locationPluginIntent.putExtra("longitude",longitude); - if (message.getStatus() != Message.STATUS_RECEIVED) { - locationPluginIntent.putExtra("jid",conversation.getAccount().getJid().toString()); - locationPluginIntent.putExtra("name",conversation.getAccount().getJid().getLocal()); - } else { - Contact contact = message.getContact(); - if (contact != null) { - locationPluginIntent.putExtra("name", contact.getDisplayName()); - locationPluginIntent.putExtra("jid", contact.getJid().toString()); + if (isLocationPluginInstalledAndDesired(context)) { + Intent locationPluginIntent = new Intent(SHOW_LOCATION_PACKAGE_NAME); + locationPluginIntent.putExtra("latitude", latitude); + locationPluginIntent.putExtra("longitude", longitude); + if (message.getStatus() != Message.STATUS_RECEIVED) { + locationPluginIntent.putExtra("jid", conversation.getAccount().getJid().toString()); + locationPluginIntent.putExtra("name", conversation.getAccount().getJid().getLocal()); } else { - locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart())); + Contact contact = message.getContact(); + if (contact != null) { + locationPluginIntent.putExtra("name", contact.getDisplayName()); + locationPluginIntent.putExtra("jid", contact.getJid().toString()); + } else { + locationPluginIntent.putExtra("name", UIHelper.getDisplayedMucCounterpart(message.getCounterpart())); + } } + intents.add(locationPluginIntent); + } else { + Intent intent = new Intent(context, ShowLocationActivity.class); + intent.putExtra("latitude", latitude); + intent.putExtra("longitude", longitude); + intents.add(intent); } - intents.add(locationPluginIntent); Intent geoIntent = new Intent(Intent.ACTION_VIEW); geoIntent.setData(Uri.parse("geo:" + String.valueOf(latitude) + "," + String.valueOf(longitude) + "?q=" + String.valueOf(latitude) + "," + String.valueOf(longitude) + label));