jenkins-bot has submitted this change and it was merged.

Change subject: Location-aware link previews.
......................................................................


Location-aware link previews.

This adds a button to "Get directions" to the link preview that pops up
when tapping on a map marker. The button fires an Intent with a "geo:" Uri
that should be picked up by the default Maps app installed on the device.

Note: this patch does not implement the "Get directions" menu item in the
link preview's overflow menu (to be shown when the link preview is invoked
from a regular link in an article that has a location). This will be done
in a subsequent patch.

Bug: T119215
Change-Id: I9d59321e89982d79c8255960a01325259d1b3d9b
---
M app/src/main/java/org/wikipedia/nearby/NearbyFragment.java
M app/src/main/java/org/wikipedia/page/PageActivity.java
M app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
M app/src/main/java/org/wikipedia/util/UriUtil.java
M app/src/main/res/layout/dialog_link_preview.xml
M app/src/main/res/layout/dialog_link_preview_overlay.xml
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
8 files changed, 90 insertions(+), 17 deletions(-)

Approvals:
  Mholloway: Looks good to me, approved
  Niedzielski: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/app/src/main/java/org/wikipedia/nearby/NearbyFragment.java 
b/app/src/main/java/org/wikipedia/nearby/NearbyFragment.java
index fd226e9..f3e973d 100644
--- a/app/src/main/java/org/wikipedia/nearby/NearbyFragment.java
+++ b/app/src/main/java/org/wikipedia/nearby/NearbyFragment.java
@@ -183,7 +183,7 @@
                 NearbyPage page = findNearbyPageFromMarker(marker);
                 if (page != null) {
                     PageTitle title = new PageTitle(page.getTitle(), site, 
page.getThumblUrl());
-                    ((PageActivity) getActivity()).showLinkPreview(title, 
HistoryEntry.SOURCE_NEARBY);
+                    ((PageActivity) getActivity()).showLinkPreview(title, 
HistoryEntry.SOURCE_NEARBY, page.getLocation());
                     return true;
                 } else {
                     return false;
diff --git a/app/src/main/java/org/wikipedia/page/PageActivity.java 
b/app/src/main/java/org/wikipedia/page/PageActivity.java
index 46f6d28..8934a66 100644
--- a/app/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/app/src/main/java/org/wikipedia/page/PageActivity.java
@@ -45,6 +45,7 @@
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
+import android.location.Location;
 import android.net.Uri;
 import android.os.Build;
 import android.os.Bundle;
@@ -697,8 +698,12 @@
     }
 
     public void showLinkPreview(PageTitle title, int entrySource) {
+        showLinkPreview(title, entrySource, null);
+    }
+
+    public void showLinkPreview(PageTitle title, int entrySource, @Nullable 
Location location) {
         if 
(getSupportFragmentManager().findFragmentByTag(LINK_PREVIEW_FRAGMENT_TAG) == 
null) {
-            DialogFragment linkPreview = LinkPreviewDialog.newInstance(title, 
entrySource);
+            DialogFragment linkPreview = LinkPreviewDialog.newInstance(title, 
entrySource, location);
             linkPreview.show(getSupportFragmentManager(), 
LINK_PREVIEW_FRAGMENT_TAG);
         }
     }
diff --git 
a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java 
b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
index c2bebf1..fd541cc 100755
--- a/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
+++ b/app/src/main/java/org/wikipedia/page/linkpreview/LinkPreviewDialog.java
@@ -19,11 +19,15 @@
 import org.wikipedia.server.PageSummary;
 import org.wikipedia.util.ApiUtil;
 import org.wikipedia.util.FeedbackUtil;
+import org.wikipedia.util.UriUtil;
 import org.wikipedia.views.ViewUtil;
 
+import android.content.ActivityNotFoundException;
 import android.content.DialogInterface;
+import android.location.Location;
 import android.os.Bundle;
 import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.PopupMenu;
 import android.text.TextUtils;
 import android.util.Log;
@@ -56,6 +60,7 @@
 
     private PageTitle pageTitle;
     private int entrySource;
+    @Nullable private Location location;
 
     private LinkPreviewFunnel funnel;
     private LinkPreviewContents contents;
@@ -79,11 +84,21 @@
         }
     };
 
-    public static LinkPreviewDialog newInstance(PageTitle title, int 
entrySource) {
+    private View.OnClickListener getDirectionsListener = new 
View.OnClickListener() {
+        @Override
+        public void onClick(View v) {
+            goToExternalMapsApp();
+        }
+    };
+
+    public static LinkPreviewDialog newInstance(PageTitle title, int 
entrySource, @Nullable Location location) {
         LinkPreviewDialog dialog = new LinkPreviewDialog();
         Bundle args = new Bundle();
         args.putParcelable("title", title);
         args.putInt("entrySource", entrySource);
+        if (location != null) {
+            args.putParcelable("location", location);
+        }
         dialog.setArguments(args);
         return dialog;
     }
@@ -101,6 +116,7 @@
         boolean shouldLoadImages = app.isImageDownloadEnabled();
         pageTitle = getArguments().getParcelable("title");
         entrySource = getArguments().getInt("entrySource");
+        location = getArguments().getParcelable("location");
 
         View rootView = inflater.inflate(R.layout.dialog_link_preview, 
container);
         progressBar = (ProgressBar) 
rootView.findViewById(R.id.link_preview_progress);
@@ -110,6 +126,13 @@
         Button goButton = (Button) 
overlayRootView.findViewById(R.id.link_preview_go_button);
         goButton.setOnClickListener(goToPageListener);
         goButton.setText(getStringForArticleLanguage(pageTitle, 
R.string.button_continue_to_article));
+
+        Button directionsButton = (Button) 
overlayRootView.findViewById(R.id.link_preview_directions_button);
+        if (location != null) {
+            directionsButton.setOnClickListener(getDirectionsListener);
+        } else {
+            directionsButton.setVisibility(View.GONE);
+        }
 
         TextView titleText = (TextView) 
rootView.findViewById(R.id.link_preview_title);
         titleText.setText(pageTitle.getDisplayText());
@@ -366,4 +389,15 @@
             super(activity);
         }
     }
+
+    private void goToExternalMapsApp() {
+        if (location != null) {
+            try {
+                dismiss();
+                UriUtil.sendGeoIntent(getActivity(), location, 
pageTitle.getDisplayText());
+            } catch (ActivityNotFoundException e) {
+                FeedbackUtil.showMessage(getActivity(), 
R.string.error_no_maps_app);
+            }
+        }
+    }
 }
diff --git a/app/src/main/java/org/wikipedia/util/UriUtil.java 
b/app/src/main/java/org/wikipedia/util/UriUtil.java
index e9b9043..4b47b9a 100644
--- a/app/src/main/java/org/wikipedia/util/UriUtil.java
+++ b/app/src/main/java/org/wikipedia/util/UriUtil.java
@@ -3,7 +3,9 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.location.Location;
 import android.net.Uri;
+import android.support.annotation.NonNull;
 import android.support.v7.app.AlertDialog;
 import android.text.TextUtils;
 import android.util.Log;
@@ -92,6 +94,16 @@
         }
     }
 
+    public static void sendGeoIntent(final Context context, @NonNull Location 
location, String placeName) {
+        String geoStr = "geo:";
+        geoStr += Double.toString(location.getLatitude()) + ","
+                + Double.toString(location.getLongitude());
+        if (!TextUtils.isEmpty(placeName)) {
+            geoStr += "?q=" + Uri.encode(placeName);
+        }
+        context.startActivity(new Intent(Intent.ACTION_VIEW, 
Uri.parse(geoStr)));
+    }
+
     private UriUtil() {
 
     }
diff --git a/app/src/main/res/layout/dialog_link_preview.xml 
b/app/src/main/res/layout/dialog_link_preview.xml
index 5668f8f..3a2f953 100755
--- a/app/src/main/res/layout/dialog_link_preview.xml
+++ b/app/src/main/res/layout/dialog_link_preview.xml
@@ -33,8 +33,8 @@
                 android:minHeight="64dp">
                 <ImageView
                     android:id="@+id/link_preview_thumbnail"
-                    android:layout_width="48dp"
-                    android:layout_height="48dp"
+                    android:layout_width="@dimen/defaultListItemSize"
+                    android:layout_height="@dimen/defaultListItemSize"
                     android:layout_margin="16dp"
                     android:layout_gravity="center_vertical"
                     android:contentDescription="@null"
@@ -49,10 +49,10 @@
                     style="@style/RtlAwareTextView"
                     android:textColor="?attr/link_preview_text_color"
                     android:paddingBottom="4dp"
-                    android:textSize="22sp"
+                    android:textSize="20sp"
                     android:fontFamily="serif"
                     android:lineSpacingMultiplier="0.9"
-                    android:maxLines="2"
+                    android:maxLines="3"
                     android:ellipsize="end"
                     tools:text="Lorem ipsum" />
                 <ImageView
diff --git a/app/src/main/res/layout/dialog_link_preview_overlay.xml 
b/app/src/main/res/layout/dialog_link_preview_overlay.xml
index 949b8b0..09855f7 100644
--- a/app/src/main/res/layout/dialog_link_preview_overlay.xml
+++ b/app/src/main/res/layout/dialog_link_preview_overlay.xml
@@ -1,14 +1,32 @@
 <?xml version="1.0" encoding="utf-8"?>
-<Button
+<LinearLayout
     xmlns:android="http://schemas.android.com/apk/res/android";
-    android:id="@+id/link_preview_go_button"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_gravity="bottom"
-    android:paddingTop="16dp"
-    android:paddingBottom="16dp"
-    android:textColor="?attr/link_color"
-    android:background="?attr/link_preview_button_background"
-    style="@style/Widget.AppCompat.Button.Borderless"
-    android:textSize="@dimen/abc_text_size_menu_material"
-    android:text="@string/button_continue_to_article"/>
\ No newline at end of file
+    android:orientation="horizontal">
+    <Button
+        android:id="@+id/link_preview_directions_button"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:paddingTop="16dp"
+        android:paddingBottom="16dp"
+        android:textColor="@color/gray_highlight"
+        android:background="?attr/link_preview_button_background"
+        style="@style/Widget.AppCompat.Button.Borderless"
+        android:textSize="@dimen/abc_text_size_menu_material"
+        android:text="@string/button_get_directions"/>
+    <Button
+        android:id="@+id/link_preview_go_button"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        android:layout_weight="1"
+        android:paddingTop="16dp"
+        android:paddingBottom="16dp"
+        android:textColor="?attr/link_color"
+        android:background="?attr/link_preview_button_background"
+        style="@style/Widget.AppCompat.Button.Borderless"
+        android:textSize="@dimen/abc_text_size_menu_material"
+        android:text="@string/button_continue_to_article"/>
+</LinearLayout>
\ No newline at end of file
diff --git a/app/src/main/res/values-qq/strings.xml 
b/app/src/main/res/values-qq/strings.xml
index 02a2bb6..d949677 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -367,6 +367,8 @@
   <string name="address_copied">Message shown after copying a link to the 
system clipboard.</string>
   <string name="text_copied">Message shown after copying text to the system 
clipboard.</string>
   <string name="button_continue_to_article">Button to continue to the full 
article from the current link preview.</string>
+  <string name="button_get_directions">Button to obtain directions to the 
location specified in the link preview.</string>
+  <string name="error_no_maps_app">Error displayed when the device does not 
have any apps installed that are capable of providing directions to a 
location.</string>
   <string name="preference_title_show_link_previews">Title of the preference 
for enabling or disabling link previews.</string>
   <string name="preference_summary_show_link_previews">Description of the 
preference for enabling or disabling link previews.</string>
   <string name="nav_item_donate">Text in navigation sidebar that when tapped 
leads to a web page where the user may donate to Wikipedia.</string>
diff --git a/app/src/main/res/values/strings.xml 
b/app/src/main/res/values/strings.xml
index e8d6ae3..20ec72f 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -287,7 +287,9 @@
     <string name="format_error_server_code">Code: \"%s\"</string>
     <string name="address_copied">Address copied to clipboard.</string>
     <string name="text_copied">Text copied to clipboard.</string>
-    <string name="button_continue_to_article">Continue to article</string>
+    <string name="button_continue_to_article">Read article</string>
+    <string name="button_get_directions">Get directions</string>
+    <string name="error_no_maps_app">Could not find any apps that provide 
directions.</string>
     <string name="preference_title_show_link_previews">Show link 
previews</string>
     <string name="preference_summary_show_link_previews">Show a quick preview 
of articles when tapping on links.</string>
     <string name="nav_item_donate">Support Wikipedia</string>

-- 
To view, visit https://gerrit.wikimedia.org/r/256266
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I9d59321e89982d79c8255960a01325259d1b3d9b
Gerrit-PatchSet: 4
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: BearND <bsitzm...@wikimedia.org>
Gerrit-Reviewer: Brion VIBBER <br...@wikimedia.org>
Gerrit-Reviewer: Dbrant <dbr...@wikimedia.org>
Gerrit-Reviewer: Mholloway <mhollo...@wikimedia.org>
Gerrit-Reviewer: Niedzielski <sniedziel...@wikimedia.org>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to