Niedzielski has uploaded a new change for review.

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

Change subject: Add Butter Knife
......................................................................

Add Butter Knife

The Android app wants to do more with native Views. A tool that is
helpful in eliminating some of the boilerplate of native Views is Butter
Knife. This dependency increases the size of the dev release apk from
4201830B to 4220733B, about ~18KiB.

To verify that the library is working properly, one usage of it is made
in ArticleHeaderView.

Change-Id: I08af3779dba038f4e349a68f1e600782cda1fc52
---
M app/build.gradle
M app/proguard-rules.pro
A app/src/main/assets/licenses/ButterKnife
M app/src/main/java/org/wikipedia/page/PageFragment.java
M app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
M app/src/main/java/org/wikipedia/views/ViewUtil.java
M app/src/main/res/values/credits.xml
7 files changed, 47 insertions(+), 33 deletions(-)


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

diff --git a/app/build.gradle b/app/build.gradle
index 829b7d9..9cbe2d0 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -126,6 +126,11 @@
     lintOptions {
         disable 'MissingTranslation'
         warning 'NewApi' // until 
https://code.google.com/p/android/issues/detail?id=137195 is released
+        disable 'InvalidPackage' // required by Butter Knife
+    }
+
+    packagingOptions {
+        exclude 'META-INF/services/javax.annotation.processing.Processor' // 
required by Butter Knife
     }
 }
 
@@ -157,6 +162,7 @@
     compile 'com.mobsandgeeks:android-saripaar:1.0.3'
     compile 'com.github.chrisbanes.photoview:library:1.2.3'
     compile 'com.github.ryanjohn1:onboarding:1.0.3'
+    compile 'com.jakewharton:butterknife:7.0.1'
     compile 'com.jakewharton:disklrucache:2.0.2'
     compile('com.mapbox.mapboxsdk:mapbox-android-sdk:0.7.4@aar') {
         transitive = true
diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro
index 4aeae09..71292cd 100644
--- a/app/proguard-rules.pro
+++ b/app/proguard-rules.pro
@@ -49,6 +49,20 @@
 -keepattributes Exceptions
 # --- /Retrofit ---
 
+# --- Butter Knife ---
+-keep class butterknife.** { *; }
+-dontwarn butterknife.internal.**
+-keep class **$$ViewBinder { *; }
+
+-keepclasseswithmembernames class * {
+    @butterknife.* <fields>;
+}
+
+-keepclasseswithmembernames class * {
+    @butterknife.* <methods>;
+}
+# --- /Butter Knife ---
+
 # --- Gson ---
 # 
https://github.com/google/gson/blob/master/examples/android-proguard-example/proguard.cfg
 
diff --git a/app/src/main/assets/licenses/ButterKnife 
b/app/src/main/assets/licenses/ButterKnife
new file mode 100644
index 0000000..5a0cb31
--- /dev/null
+++ b/app/src/main/assets/licenses/ButterKnife
@@ -0,0 +1,13 @@
+Copyright 2013 Jake Wharton
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/page/PageFragment.java 
b/app/src/main/java/org/wikipedia/page/PageFragment.java
index 8bfd426..e2d0b8e 100755
--- a/app/src/main/java/org/wikipedia/page/PageFragment.java
+++ b/app/src/main/java/org/wikipedia/page/PageFragment.java
@@ -77,7 +77,7 @@
 
 import javax.net.ssl.SSLException;
 
-import static org.wikipedia.views.ViewUtil.findView;
+import static butterknife.ButterKnife.findById;
 
 public class PageFragment extends Fragment implements BackPressedHandler {
     public static final int TOC_ACTION_SHOW = 0;
@@ -344,7 +344,7 @@
         tocHandler = new ToCHandler(getPageActivity(), tocDrawer, bridge);
 
         // TODO: initialize View references in onCreateView().
-        articleHeaderView = findView(getView(), R.id.page_header_view);
+        articleHeaderView = findById(getView(), R.id.page_header_view);
         leadImagesHandler = new LeadImagesHandler(this, bridge, webView, 
articleHeaderView);
         searchBarHideHandler = getPageActivity().getSearchBarHideHandler();
         searchBarHideHandler.setScrollView(webView);
diff --git a/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java 
b/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
index fbac51c..6f0f8e4 100644
--- a/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
+++ b/app/src/main/java/org/wikipedia/views/ArticleHeaderView.java
@@ -3,19 +3,20 @@
 import android.annotation.TargetApi;
 import android.content.Context;
 import android.os.Build;
-import android.support.annotation.IdRes;
 import android.util.AttributeSet;
-import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 
 import org.wikipedia.R;
 import org.wikipedia.page.leadimages.ImageViewWithFace;
 
+import butterknife.Bind;
+import butterknife.ButterKnife;
+
 public class ArticleHeaderView extends FrameLayout {
-    private ImageViewWithFace image;
-    private ImageView placeholder;
-    private AppTextView text;
+    @Bind(R.id.image) ImageViewWithFace image;
+    @Bind(R.id.placeholder) ImageView placeholder;
+    @Bind(R.id.text) AppTextView text;
 
     public ArticleHeaderView(Context context) {
         super(context);
@@ -52,21 +53,10 @@
 
     private void init() {
         inflate();
-        findViews();
+        ButterKnife.bind(this);
     }
 
     private void inflate() {
         inflate(getContext(), R.layout.view_article_header, this);
-    }
-
-    private void findViews() {
-        // TODO: replace manual assignments with Butter Knife annotations.
-        image = findView(R.id.image);
-        placeholder = findView(R.id.placeholder);
-        text = findView(R.id.text);
-    }
-
-    private <T extends View> T findView(@IdRes int id) {
-        return ViewUtil.findView(this, id);
     }
 }
\ No newline at end of file
diff --git a/app/src/main/java/org/wikipedia/views/ViewUtil.java 
b/app/src/main/java/org/wikipedia/views/ViewUtil.java
index 34457b8..2a6eb5c 100644
--- a/app/src/main/java/org/wikipedia/views/ViewUtil.java
+++ b/app/src/main/java/org/wikipedia/views/ViewUtil.java
@@ -1,11 +1,8 @@
 package org.wikipedia.views;
 
 import android.annotation.TargetApi;
-import android.app.Activity;
 import android.graphics.drawable.Drawable;
 import android.os.Build;
-import android.support.annotation.IdRes;
-import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.view.View;
 import android.view.ViewManager;
@@ -35,16 +32,6 @@
     public static void setBottomPaddingDp(View view, int padding) {
         view.setPadding(view.getPaddingLeft(), view.getPaddingTop(), 
view.getPaddingRight(),
                 (int) (padding * 
view.getContext().getResources().getDisplayMetrics().density));
-    }
-
-    @Nullable public static <T extends View> T findView(@NonNull View view, 
@IdRes int id) {
-        //noinspection unchecked
-        return (T) view.findViewById(id);
-    }
-
-    @Nullable public static <T extends View> T findView(@NonNull Activity 
activity, @IdRes int id) {
-        //noinspection unchecked
-        return (T) activity.findViewById(id);
     }
 
     public static void setAnimationMatrix(View view, Animation animation) {
diff --git a/app/src/main/res/values/credits.xml 
b/app/src/main/res/values/credits.xml
index 94b5649..9983142 100644
--- a/app/src/main/res/values/credits.xml
+++ b/app/src/main/res/values/credits.xml
@@ -1,7 +1,11 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources xmlns:tools="http://schemas.android.com/tools"; 
tools:ignore="MissingTranslation">
     <string name="contributors_list">Adam Baso, Amir E. Aharoni, Anirudh S, 
Bernd Sitzmann, Brion Vibber, Dan Garry, Dmitry Brant, Elena Tonkovidova, Kenan 
Wang, Maryana Pinchuk, Matanya Moses, Max Semenik, Michael Holloway, Moiz Syed, 
Monte Hurd, Mun May Tee, Nicole Borrelli, Niklas Laxström, Rummana Yasmeen, 
Stephen Niedzielski, Thomas PT, Tomasz Finc, Vibha Bamba, Yuvi Panda</string>
-    <string name="libraries_list"><a 
href="https://github.com/JakeWharton/DiskLruCache";>DiskLruCache</a>
+    <string name="libraries_list"><a 
href="https://github.com/JakeWharton/ButterKnife";>ButterKnife</a>
+        <!-- 
https://github.com/JakeWharton/ButterKnife/blob/master/LICENSE.txt -->
+        (<a href="file:///android_asset/licenses/ButterKnife">license</a>),
+
+        <a href="https://github.com/JakeWharton/DiskLruCache";>DiskLruCache</a>
         <!-- 
https://github.com/JakeWharton/DiskLruCache/blob/master/LICENSE.txt -->
         (<a href="file:///android_asset/licenses/DiskLruCache">license</a>),
 

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: I08af3779dba038f4e349a68f1e600782cda1fc52
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Niedzielski <sniedziel...@wikimedia.org>

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

Reply via email to