[MediaWiki-commits] [Gerrit] Share a fact - change (apps...wikipedia)

2015-01-07 Thread Dbrant (Code Review)
Dbrant has submitted this change and it was merged.

Change subject: Share a fact
..


Share a fact

- Refactored the GalleryActivity's image sharing code to be reusable.
- Reused it for Share a fact
- Currently it uses the lead image as the image to be share,
   plus the mainly static teaser text.

Change-Id: Ib78821dcb772c9b5811f1c8f2bbdefb77a826844
---
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
M wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java
M wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
A wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java
7 files changed, 131 insertions(+), 50 deletions(-)

Approvals:
  Dbrant: Looks good to me, approved



diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index a2ea87d..0d4adc6 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -379,4 +379,8 @@
   string name=gallery_menu_saveLabel for menu item to save the current 
image to the Media collection on the local device./string
   string name=gallery_save_errorError message shown when there was a 
problem with saving the image to the local device. The \%s\ symbol is 
replaced with the actual error message from the system./string
   string name=gallery_save_successToast message shown when the current 
image was saved successfully to the local device./string
+  string name=snippet_share_introIntro text included as part of the shared 
text snippet, aka Tweet-a-fact. This message has two parameters. Please keep 
the parameters exactly as in the original English message.
+* The first parameter is the title of the page the text snippet is from.
+* The second parameter is an HTML link to the page.
+  /string
 /resources
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index 608fca5..9f285e7 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -288,4 +288,5 @@
 string name=gallery_menu_saveSave to device/string
 string name=gallery_save_errorCould not save image: %s/string
 string name=gallery_save_successImage saved successfully./string
+string name=snippet_share_introInteresting fact on @Wikipedia about 
%1$s: %2$s/string
 /resources
diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java 
b/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
index 2a9083f..dd07945 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
@@ -21,6 +21,7 @@
 import org.wikipedia.settings.PrefKeys;
 import org.wikipedia.staticdata.MainPageNameData;
 import org.wikipedia.theme.ThemeChooserDialog;
+import org.wikipedia.util.ShareUtils;
 import org.wikipedia.zero.ZeroMessage;
 
 import com.squareup.otto.Bus;
@@ -36,6 +37,7 @@
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
+import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.BadParcelableException;
 import android.os.Build;
@@ -58,6 +60,7 @@
 import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class PageActivity extends ThemedActionBarActivity {
 public static final String ACTION_PAGE_FOR_TITLE = 
org.wikipedia.page_for_title;
@@ -790,15 +793,38 @@
 if (clipboard.hasPrimaryClip()
  clipboard.getPrimaryClip().getItemCount()  0) {
 
+CharSequence selectedText = 
clipboard.getPrimaryClip().getItemAt(0)
+.coerceToText(PageActivity.this);
+Log.d(Share,  Clipboard text:  + 
selectedText);
 
-// TODO: Pass the clipboard text to the Share 
handler!
-
-
-Log.d(Share,  Clipboard text:  + 
clipboard.getPrimaryClip()
-
.getItemAt(0).coerceToText(PageActivity.this));
-
+// Pass the clipboard text to the Share handler!
+shareSnippet(selectedText);
 }
 
clipboard.removePrimaryClipChangedListener(clipListener);
+}
+
+private void shareSnippet(CharSequence selectedText) {
+// TODO: create sharable image with selected text
+// currently only using lead image
+
+PageTitle title = getCurPageFragment().getTitle();
+String text = getString(R.string.snippet_share_intro,
+

[MediaWiki-commits] [Gerrit] Share a fact - change (apps...wikipedia)

2014-12-19 Thread BearND (Code Review)
BearND has uploaded a new change for review.

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

Change subject: Share a fact
..

Share a fact

- Refactored the GalleryActivity's image sharing code to be reusable.
- Reused it for Tweet a fact
- Currently it uses the lead image as the image to be share,
   plus the mainly static teaser text.

Change-Id: Ib78821dcb772c9b5811f1c8f2bbdefb77a826844
(cherry picked from commit 5f9e08b69572108e9669a55032903f8cbe052ea4)
---
M wikipedia/res/values-qq/strings.xml
M wikipedia/res/values/strings.xml
M wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
M wikipedia/src/main/java/org/wikipedia/page/PageViewFragmentInternal.java
M wikipedia/src/main/java/org/wikipedia/page/gallery/GalleryActivity.java
M wikipedia/src/main/java/org/wikipedia/page/leadimages/LeadImagesHandler.java
A wikipedia/src/main/java/org/wikipedia/util/ShareUtils.java
7 files changed, 124 insertions(+), 45 deletions(-)


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

diff --git a/wikipedia/res/values-qq/strings.xml 
b/wikipedia/res/values-qq/strings.xml
index 14b98d4..4bdedcf 100644
--- a/wikipedia/res/values-qq/strings.xml
+++ b/wikipedia/res/values-qq/strings.xml
@@ -379,4 +379,5 @@
   string name=gallery_menu_saveLabel for menu item to save the current 
image to the Media collection on the local device./string
   string name=gallery_save_errorError message shown when there was a 
problem with saving the image to the local device. The \%s\ symbol is 
replaced with the actual error message from the system./string
   string name=gallery_save_successToast message shown when the current 
image was saved successfully to the local device./string
+  string name=snippet_share_introIntro text included as part of the shared 
text snippet, aka Tweet-a-fact./string
 /resources
diff --git a/wikipedia/res/values/strings.xml b/wikipedia/res/values/strings.xml
index 1aa19ca..0a89938 100644
--- a/wikipedia/res/values/strings.xml
+++ b/wikipedia/res/values/strings.xml
@@ -289,4 +289,5 @@
 string name=gallery_menu_saveSave to device/string
 string name=gallery_save_errorCould not save image: %s/string
 string name=gallery_save_successImage saved successfully./string
+string name=snippet_share_introInteresting fact on @Wikipedia about 
%1$s: %2$s/string
 /resources
diff --git a/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java 
b/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
index f3d824f..00a5daa 100644
--- a/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
+++ b/wikipedia/src/main/java/org/wikipedia/page/PageActivity.java
@@ -21,6 +21,7 @@
 import org.wikipedia.settings.PrefKeys;
 import org.wikipedia.staticdata.MainPageNameData;
 import org.wikipedia.theme.ThemeChooserDialog;
+import org.wikipedia.util.ShareUtils;
 import org.wikipedia.zero.ZeroMessage;
 
 import com.squareup.otto.Bus;
@@ -33,6 +34,7 @@
 import android.content.Intent;
 import android.content.SharedPreferences;
 import android.content.res.Configuration;
+import android.graphics.Bitmap;
 import android.net.Uri;
 import android.os.BadParcelableException;
 import android.os.Build;
@@ -55,6 +57,7 @@
 import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.TextView;
+import android.widget.Toast;
 
 public class PageActivity extends ThemedActionBarActivity {
 public static final String ACTION_PAGE_FOR_TITLE = 
org.wikipedia.page_for_title;
@@ -748,12 +751,36 @@
 @Override
 public boolean onMenuItemClick(MenuItem item) {
 
-// TODO: implement sharing of image with quote!
+shareSnippet();
 
 if (webViewActionMode != null) {
 webViewActionMode.finish();
 }
 return true;
+}
+
+private void shareSnippet() {
+// TODO: create sharable image with selected text
+// currently only using lead image
+
+PageTitle title = getCurPageFragment().getTitle();
+String text = getString(R.string.snippet_share_intro,
+title.getDisplayText(),
+title.getCanonicalUri());
+
+Bitmap leadImageBitmap = 
getCurPageFragment().getLeadImageBitmap();
+
+if (leadImageBitmap != null) {
+ShareUtils.shareImage(PageActivity.this, 
leadImageBitmap, */*,
+title.getDisplayText(), text);
+} else {
+// TODO: remove if check once we build our own image
+// For now, as we're using the lead image we may not 
always have one,
+// esp. on the main page.
+