Mholloway has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/332647 )

Change subject: [DEMO] Picasso Captcha loading success
......................................................................

[DEMO] Picasso Captcha loading success

Bug: T155535
Change-Id: I67befde14d0542a2c57ae367828e6c07de0daa3c
---
M app/build.gradle
M app/src/main/java/org/wikipedia/captcha/CaptchaHandler.java
M app/src/main/res/layout/group_captcha.xml
3 files changed, 62 insertions(+), 6 deletions(-)


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

diff --git a/app/build.gradle b/app/build.gradle
index 7407fd8..cf1dd98 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -198,6 +198,7 @@
     }
     compile 'net.hockeyapp.android:HockeySDK:4.0.1'
     compile 'org.apache.commons:commons-lang3:3.5'
+    compile 'com.squareup.picasso:picasso:2.5.2'
 
     apt "com.jakewharton:butterknife-compiler:$butterKnifeVersion"
 
diff --git a/app/src/main/java/org/wikipedia/captcha/CaptchaHandler.java 
b/app/src/main/java/org/wikipedia/captcha/CaptchaHandler.java
index 7e675cf..bc5b141 100644
--- a/app/src/main/java/org/wikipedia/captcha/CaptchaHandler.java
+++ b/app/src/main/java/org/wikipedia/captcha/CaptchaHandler.java
@@ -10,18 +10,21 @@
 import android.support.v7.app.AppCompatActivity;
 import android.view.View;
 import android.widget.EditText;
+import android.widget.ImageView;
 import android.widget.TextView;
 
 import com.facebook.drawee.backends.pipeline.Fresco;
 import com.facebook.drawee.controller.BaseControllerListener;
 import com.facebook.drawee.view.SimpleDraweeView;
 import com.facebook.imagepipeline.image.ImageInfo;
+import com.squareup.picasso.Picasso;
 
 import org.mediawiki.api.json.RequestBuilder;
 import org.wikipedia.R;
 import org.wikipedia.WikipediaApp;
 import org.wikipedia.dataclient.WikiSite;
 import org.wikipedia.util.FeedbackUtil;
+import org.wikipedia.util.log.L;
 import org.wikipedia.views.ViewAnimations;
 
 import retrofit2.Call;
@@ -30,7 +33,7 @@
     private final Activity activity;
     private final View captchaContainer;
     private final View captchaProgress;
-    private final SimpleDraweeView captchaImage;
+    private final ImageView captchaImage;
     private final EditText captchaText;
     private final WikiSite wiki;
     private final View primaryView;
@@ -49,7 +52,7 @@
         this.prevTitle = prevTitle;
 
         captchaContainer = activity.findViewById(R.id.captcha_container);
-        captchaImage = (SimpleDraweeView) 
activity.findViewById(R.id.captcha_image);
+        captchaImage = (ImageView) activity.findViewById(R.id.captcha_image);
         captchaText = (EditText) activity.findViewById(R.id.captcha_text);
         captchaProgress = activity.findViewById(R.id.captcha_image_progress);
         TextView submitButton = (TextView) 
activity.findViewById(R.id.captcha_submit_button);
@@ -128,11 +131,59 @@
         handleCaptcha(false);
     }
 
+    private class CaptchaCallback implements com.squareup.picasso.Callback {
+
+        private boolean isReload;
+
+        CaptchaCallback(boolean isReload) {
+            this.isReload = isReload;
+        }
+
+        @Override
+        public void onSuccess() {
+            
((AppCompatActivity)activity).getSupportActionBar().setTitle(R.string.title_captcha);
+            if (progressDialog.isShowing()) {
+                progressDialog.hide();
+            }
+
+            // for our Dark theme, show a "negative image" of the captcha!
+            final int maxColorVal = 255;
+            if (WikipediaApp.getInstance().isCurrentThemeDark()) {
+                float[] colorMatrixNegative = {
+                        -1.0f, 0, 0, 0, maxColorVal, //red
+                        0, -1.0f, 0, 0, maxColorVal, //green
+                        0, 0, -1.0f, 0, maxColorVal, //blue
+                        0, 0, 0, 1.0f, 0 //alpha
+                };
+                captchaImage.getDrawable().setColorFilter(new 
ColorMatrixColorFilter(colorMatrixNegative));
+            } else {
+                captchaImage.getDrawable().clearColorFilter();
+            }
+
+            // In case there was a captcha attempt before
+            captchaText.setText("");
+            if (!isReload) {
+                ViewAnimations.crossFade(primaryView, captchaContainer);
+            }
+        }
+
+        @Override
+        public void onError() {
+            //FeedbackUtil.showError(activity, throwable);
+            L.e("BAD NEWS MAN");
+        }
+    }
+
     private void handleCaptcha(final boolean isReload) {
         if (captchaResult == null) {
             return;
         }
-        captchaImage.setController(Fresco.newDraweeControllerBuilder()
+        //String test = captchaResult.getCaptchaUrl(wiki);
+        Picasso.with(activity)
+                .load(captchaResult.getCaptchaUrl(wiki))
+                .into(captchaImage, new CaptchaCallback(isReload));
+
+        /*captchaImage.setController(Fresco.newDraweeControllerBuilder()
                 .setUri(captchaResult.getCaptchaUrl(wiki))
                 .setAutoPlayAnimations(true)
                 .setControllerListener(new BaseControllerListener<ImageInfo>() 
{
@@ -163,8 +214,13 @@
                             ViewAnimations.crossFade(primaryView, 
captchaContainer);
                         }
                     }
+
+                    @Override public void onFailure(String id, Throwable 
throwable) {
+                        FeedbackUtil.showError(activity, throwable);
+                        L.e(throwable);
+                    }
                 })
-                .build());
+                .build());*/
     }
 
     public void hideCaptcha() {
diff --git a/app/src/main/res/layout/group_captcha.xml 
b/app/src/main/res/layout/group_captcha.xml
index 67eaf57..770270b 100644
--- a/app/src/main/res/layout/group_captcha.xml
+++ b/app/src/main/res/layout/group_captcha.xml
@@ -24,14 +24,13 @@
     <FrameLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content">
-        <com.facebook.drawee.view.SimpleDraweeView
+        <ImageView
             style="@style/SimpleDraweeViewPlaceholder"
             android:id="@+id/captcha_image"
             android:layout_gravity="center_horizontal"
             android:layout_width="240dp"
             android:layout_height="80dp"
             android:background="@null"
-            app:actualImageScaleType="fitCenter"
             android:contentDescription="@string/captcha_image" />
         <ProgressBar
                 android:id="@+id/captcha_image_progress"

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I67befde14d0542a2c57ae367828e6c07de0daa3c
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Mholloway <mhollo...@wikimedia.org>

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

Reply via email to