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

Change subject: Fix crash when highlighting text for sharing.
......................................................................


Fix crash when highlighting text for sharing.

Be more permissive when finding the "copy" and "share" context items
that the WebView provides. Should cover more API levels.

If we're unable to find the context items, then fail gracefully by
falling back on the default context actions.

Also fixed minor style issue for correctly setting text color for
action modes.

Bug: T91767
Change-Id: I6da051fc9f7274c99e5ba78a642431d28797b6ce
---
M wikipedia/res/values/styles.xml
M 
wikipedia/src/main/java/org/wikipedia/page/snippet/TextSelectedShareAdapter.java
2 files changed, 20 insertions(+), 4 deletions(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikipedia/res/values/styles.xml b/wikipedia/res/values/styles.xml
index 5910550..c9fd6ad 100644
--- a/wikipedia/res/values/styles.xml
+++ b/wikipedia/res/values/styles.xml
@@ -39,6 +39,16 @@
         <item name="background">@color/actionbar_background</item>
         <item name="android:background">@color/actionbar_background</item>
         <item name="backgroundSplit">@color/actionbar_background</item>
+        <item name="titleTextStyle">@style/AppTheme.ActionModeTitleStyle</item>
+        <item 
name="subtitleTextStyle">@style/AppTheme.ActionModeSubtitleStyle</item>
+    </style>
+
+    <style name="AppTheme.ActionModeTitleStyle" 
parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
+        <item name="android:textColor">@android:color/white</item>
+    </style>
+
+    <style name="AppTheme.ActionModeSubtitleStyle" 
parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Subtitle">
+        <item name="android:textColor">@android:color/white</item>
     </style>
 
     <style name="AppTheme.SearchViewStyle" 
parent="@style/Widget.AppCompat.SearchView">
diff --git 
a/wikipedia/src/main/java/org/wikipedia/page/snippet/TextSelectedShareAdapter.java
 
b/wikipedia/src/main/java/org/wikipedia/page/snippet/TextSelectedShareAdapter.java
index 7250f8a..38c4f7b 100644
--- 
a/wikipedia/src/main/java/org/wikipedia/page/snippet/TextSelectedShareAdapter.java
+++ 
b/wikipedia/src/main/java/org/wikipedia/page/snippet/TextSelectedShareAdapter.java
@@ -66,12 +66,12 @@
 
         // Find the context menu item for copying text to the clipboard...
         // The most practical way to do this seems to be to get the resource 
name of the
-        // menu item, and see if it resembles "action_menu_copy", which 
appears to remain
+        // menu item, and see if it contains "copy", which appears to remain
         // consistent throughout the various APIs.
         for (int i = 0; i < menu.size(); i++) {
             String resourceName
                     = 
getActivity().getResources().getResourceName(menu.getItem(i).getItemId());
-            if (resourceName.contains("action_menu_copy")) {
+            if (resourceName.contains("copy")) {
                 copyMenuItem = menu.getItem(i);
                 break;
             }
@@ -79,17 +79,23 @@
 
         // Find the context menu item for sharing text...
         // The most practical way to do this seems to be to get the resource 
name of the
-        // menu item, and see if it resembles "action_menu_share", which 
appears to remain
+        // menu item, and see if it contains "share", which appears to remain
         // consistent throughout the various APIs.
         for (int i = 0; i < menu.size(); i++) {
             String resourceName
                     = 
getActivity().getResources().getResourceName(menu.getItem(i).getItemId());
-            if (resourceName.contains("action_menu_share")) {
+            if (resourceName.contains("share")) {
                 shareItem = menu.getItem(i);
                 break;
             }
         }
 
+        // if we were unable to find the Copy or Share items, then we won't be 
able to offer
+        // our custom Share functionality, so just fall back to the WebView's 
default sharing.
+        if (copyMenuItem == null || shareItem == null) {
+            return;
+        }
+
         // intercept share menu...
         shareItem.setOnMenuItemClickListener(new 
MenuItem.OnMenuItemClickListener() {
             @Override

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I6da051fc9f7274c99e5ba78a642431d28797b6ce
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to