Dbrant has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/168605

Change subject: Catch possible exception when clicking Preference with intent.
......................................................................

Catch possible exception when clicking Preference with intent.

If the device doesn't have a Browser app installed, it will throw an
exception when trying to launch a VIEW intent from a Preference.

Bug: 70528
Change-Id: I06e791f4eb5126ac5ddb0d850a2a91c84b18c058
---
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/settings/PreferenceMultiLine.java
3 files changed, 22 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia 
refs/changes/05/168605/1

diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index 54aea4b..5f34d8f 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -337,6 +337,7 @@
   <string name="toc_know_it">Button text to acknowledge instructions for 
opening Table of Contents drawer.</string>
   <string name="app_store_description">Description of the app as put up on the 
Google Play Store</string>
   <string name="alpha_update_notification_title">Title for notification when 
new alpha update is available.
+  <string name="error_browser_not_found">Message displayed when the device 
does not have a web browser app installed that can handle opening web pages 
outside the Wikipedia domain.</string>
 
 Followed by {{msg-wm|Wikipedia-android-strings-alpha update notification 
text}}.</string>
   <string name="alpha_update_notification_text">Text for notification when new 
alpha update is available.
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index adfe91e..b7b8010 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -250,6 +250,7 @@
     <string name="search_full_button">Within articles</string>
     <string name="toc_hint">Swipe left for sections, or use the menu button on 
the top right.</string>
     <string name="toc_know_it">Got it</string>
+    <string name="error_browser_not_found">Could not open web page (no browser 
app found).</string>
 
     <string name="app_store_description">Official Wikipedia App for Android. 
Wikipedia is the free encyclopedia containing more than 32 million articles in 
280 languages, and is the most comprehensive and widely used reference work 
humans have ever compiled. The app has been rewritten from scratch and is 
better than ever before.
 
diff --git 
a/wikipedia/src/main/java/org/wikipedia/settings/PreferenceMultiLine.java 
b/wikipedia/src/main/java/org/wikipedia/settings/PreferenceMultiLine.java
index 0cbda3b..dfa733f 100644
--- a/wikipedia/src/main/java/org/wikipedia/settings/PreferenceMultiLine.java
+++ b/wikipedia/src/main/java/org/wikipedia/settings/PreferenceMultiLine.java
@@ -1,10 +1,14 @@
 package org.wikipedia.settings;
 
+import android.content.ActivityNotFoundException;
 import android.content.Context;
 import android.preference.Preference;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.TextView;
+import android.widget.Toast;
+
+import org.wikipedia.R;
 
 public class PreferenceMultiLine extends Preference {
 
@@ -27,5 +31,21 @@
         if (textView != null) {
             textView.setSingleLine(false);
         }
+        // Intercept the click listener for this preference, and if the 
preference has an intent,
+        // launch the intent ourselves, so that we can catch the exception if 
the intent fails.
+        this.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+            @Override
+            public boolean onPreferenceClick(Preference preference) {
+                if (preference.getIntent() != null) {
+                    try {
+                        getContext().startActivity(preference.getIntent());
+                    } catch (ActivityNotFoundException e) {
+                        Toast.makeText(getContext(), 
getContext().getString(R.string.error_browser_not_found), 
Toast.LENGTH_LONG).show();
+                    }
+                    return true;
+                }
+                return false;
+            }
+        });
     }
 }

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I06e791f4eb5126ac5ddb0d850a2a91c84b18c058
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to