From 1cc9473f3748e730ad2dcadab65a2589feae97ff Mon Sep 17 00:00:00 2001 From: Maxime Jallu Date: Mon, 2 Oct 2017 10:49:40 +0200 Subject: [PATCH 1/2] fix(dependence): remove dependence butterknife and picasso --- adapter/build.gradle | 10 ++--- .../jmaxime/adapters/EasyPagerAdapter.java | 10 +++++ .../jmaxime/adapters/RecyclerAdapter.java | 15 ++++++- .../jmaxime/factory/ViewHolderFactory.java | 25 ++++++++++- .../interfaces/InitViewHolderDecorator.java | 14 +++++++ .../interfaces/ShowPictureDecorator.java | 7 ++++ .../viewholder/RecyclerViewHolder.java | 41 +++++++++++++------ 7 files changed, 103 insertions(+), 19 deletions(-) create mode 100644 adapter/src/main/java/com/android/jmaxime/interfaces/InitViewHolderDecorator.java create mode 100644 adapter/src/main/java/com/android/jmaxime/interfaces/ShowPictureDecorator.java diff --git a/adapter/build.gradle b/adapter/build.gradle index e6833cf..7b80d3e 100644 --- a/adapter/build.gradle +++ b/adapter/build.gradle @@ -23,8 +23,8 @@ android { // applicationId "com.android.jmaxime.com.android.jmaxime.adapter" minSdkVersion 23 targetSdkVersion 26 - versionCode 1710291743 /*YYMMDDHHMM*/ - versionName "1.2" + versionCode 1711021045 /*YYMMDDHHMM*/ + versionName "1.4" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -60,8 +60,8 @@ dependencies { // compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.50" compile "com.android.support:appcompat-v7:$androidSupport" compile "com.android.support:design:$androidSupport" - compile 'com.squareup.picasso:picasso:2.5.2' +// compile 'com.squareup.picasso:picasso:2.5.2' // compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0' - compile 'com.jakewharton:butterknife:8.8.1' - annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' +// compile 'com.jakewharton:butterknife:8.8.1' +// annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' } diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java index 9601b58..843556f 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java +++ b/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java @@ -6,6 +6,8 @@ import com.android.jmaxime.factory.ViewHolderFactory; import com.android.jmaxime.interfaces.IBaseCommunication; +import com.android.jmaxime.interfaces.InitViewHolderDecorator; +import com.android.jmaxime.interfaces.ShowPictureDecorator; import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.util.ArrayList; @@ -52,6 +54,14 @@ public boolean isViewFromObject(View view, Object object) { return mItems.size(); } + public void attachInitHolderDecorator(InitViewHolderDecorator holderDecorator) { + mFactory.setInitViewDecorator(holderDecorator); + } + + public void attachShowPictureDecorator(ShowPictureDecorator pictureDecorator) { + mFactory.setShowPictureDecorator(pictureDecorator); + } + @Override public void destroyItem(ViewGroup container, int position, Object object) { container.removeView((View) object); diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java index c819166..1f77f37 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java +++ b/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java @@ -9,6 +9,8 @@ import com.android.jmaxime.interfaces.IAdapterChanged; import com.android.jmaxime.interfaces.IBaseCommunication; import com.android.jmaxime.interfaces.IViewType; +import com.android.jmaxime.interfaces.InitViewHolderDecorator; +import com.android.jmaxime.interfaces.ShowPictureDecorator; import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.security.AccessControlException; @@ -61,7 +63,10 @@ public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) throw new AccessControlException("mFactory is not instancied. thanks use setFactory() method."); } - return mFactory.createVH(parent, viewType); + RecyclerViewHolder vh = mFactory.createVH(parent, viewType); + /*used for decorator. Sample ButterKnife*/ + vh.initBinding(); + return vh; } @@ -119,6 +124,14 @@ public void setCommunication(IBaseCommunication communication) { notifyDataSetChanged(); } + public void attachInitHolderDecorator(InitViewHolderDecorator holderDecorator) { + mFactory.setInitViewDecorator(holderDecorator); + } + + public void attachShowPictureDecorator(ShowPictureDecorator pictureDecorator) { + mFactory.setShowPictureDecorator(pictureDecorator); + } + /** * Inserts the specified element at the specified position in this list (optional operation). * Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices). diff --git a/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java b/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java index f6717df..b4a9e6e 100644 --- a/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java +++ b/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java @@ -2,6 +2,7 @@ import android.annotation.SuppressLint; import android.support.annotation.LayoutRes; +import android.support.annotation.Nullable; import android.util.Log; import android.util.SparseArray; import android.view.LayoutInflater; @@ -10,6 +11,8 @@ import com.android.jmaxime.annotations.BindLayoutRes; import com.android.jmaxime.interfaces.IBaseCommunication; +import com.android.jmaxime.interfaces.InitViewHolderDecorator; +import com.android.jmaxime.interfaces.ShowPictureDecorator; import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.lang.ref.WeakReference; @@ -25,6 +28,8 @@ public class ViewHolderFactory { private static final String TAG = ViewHolderFactory.class.getName(); private WeakReference mCommunication; + private WeakReference mDecoratorWeakReference; + private WeakReference mInitViewDecoratorWeakReference; private Class> mViewHolderType; private SparseArray>> mClassHashMap; @@ -37,10 +42,18 @@ public ViewHolderFactory(Class> viewHolderType) this(viewHolderType, null); } - public ViewHolderFactory(Class> viewHolderType, IBaseCommunication callback) { + public ViewHolderFactory(Class> viewHolderType, @Nullable IBaseCommunication callback) { + this(viewHolderType, callback, null, null); + } + + public ViewHolderFactory(Class> viewHolderType, + @Nullable IBaseCommunication callback, @Nullable InitViewHolderDecorator holderDecorator, + @Nullable ShowPictureDecorator pictureDecorator) { mViewHolderType = viewHolderType; mClassHashMap = new SparseArray<>(); setCommunication(callback); + setInitViewDecorator(holderDecorator); + setShowPictureDecorator(pictureDecorator); } public final RecyclerViewHolder createVH(ViewGroup view, int viewType) { @@ -48,6 +61,8 @@ public final RecyclerViewHolder createVH(ViewGroup view, int viewType) { .inflate(getLayoutRes(viewType), view, false), viewType); if (ret != null) { ret.setCommunication(getInterfaceCallback()); + ret.setInitViewDecorator(mInitViewDecoratorWeakReference.get()); + ret.setPictureDecorator(mDecoratorWeakReference.get()); } return ret; } @@ -99,6 +114,14 @@ public void setCommunication(IBaseCommunication communication) { mCommunication = new WeakReference<>(communication); } + public void setShowPictureDecorator(@Nullable ShowPictureDecorator decoratorWeakReference) { + mDecoratorWeakReference = new WeakReference<>(decoratorWeakReference); + } + + public void setInitViewDecorator(@Nullable InitViewHolderDecorator initViewDecoratorWeakReference) { + mInitViewDecoratorWeakReference = new WeakReference<>(initViewDecoratorWeakReference); + } + final @LayoutRes int getLayoutRes(int viewType) { return getViewHolderType(viewType).getAnnotation(BindLayoutRes.class).value(); } diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/InitViewHolderDecorator.java b/adapter/src/main/java/com/android/jmaxime/interfaces/InitViewHolderDecorator.java new file mode 100644 index 0000000..7917029 --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/interfaces/InitViewHolderDecorator.java @@ -0,0 +1,14 @@ +package com.android.jmaxime.interfaces; + +import android.view.View; + +/** + * @author Maxime Jallu + * @since 02/10/2017 + *

+ * Use this Class for :
+ * {DOCUMENTATION} + */ +public interface InitViewHolderDecorator { + void initBinding(View view); +} diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/ShowPictureDecorator.java b/adapter/src/main/java/com/android/jmaxime/interfaces/ShowPictureDecorator.java new file mode 100644 index 0000000..906d06c --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/interfaces/ShowPictureDecorator.java @@ -0,0 +1,7 @@ +package com.android.jmaxime.interfaces; + +import android.widget.ImageView; + +public interface ShowPictureDecorator { + void showPicture(ImageView picture, String url); +} diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java index d506b78..680afc3 100644 --- a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java +++ b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java @@ -14,11 +14,9 @@ import android.view.View; import android.widget.ImageView; -import com.android.jmaxime.adapter.R; import com.android.jmaxime.interfaces.IBaseCommunication; -import com.squareup.picasso.Picasso; - -import butterknife.ButterKnife; +import com.android.jmaxime.interfaces.InitViewHolderDecorator; +import com.android.jmaxime.interfaces.ShowPictureDecorator; /** * @author Maxime Jallu @@ -41,6 +39,8 @@ public abstract class RecyclerViewHolder extends RecyclerView.ViewHolder { private T mItem; private boolean isBound; + private InitViewHolderDecorator mDecorator; + private ShowPictureDecorator mPictureDecorator; private IBaseCommunication mCommunication; /** @@ -54,7 +54,13 @@ public abstract class RecyclerViewHolder extends RecyclerView.ViewHolder { @SuppressLint("NewApi") public RecyclerViewHolder(View itemView) { super(itemView); - ButterKnife.bind(this, itemView); +// ButterKnife.bind(this, itemView); + } + + public void initBinding() { + if (mDecorator != null) { + mDecorator.initBinding(itemView); + } } public abstract void bind(final T item); @@ -88,19 +94,30 @@ protected final Drawable getDrawable(@DrawableRes int drawableResId) { } protected final void showPicture(ImageView picture, String url) { - Picasso.with(picture.getContext()) - .load(url) - .placeholder(R.drawable.no_image) - .error(R.drawable.no_image) - .fit() - .centerInside() - .into(picture); + if (mPictureDecorator != null) { + mPictureDecorator.showPicture(picture, url); + } +// Picasso.with(picture.getContext()) +// .load(url) +// .placeholder(R.drawable.no_image) +// .error(R.drawable.no_image) +// .fit() +// .centerInside() +// .into(picture); } protected boolean isBound() { return isBound; } + public void setInitViewDecorator(InitViewHolderDecorator decorator) { + mDecorator = decorator; + } + + public void setPictureDecorator(ShowPictureDecorator pictureDecorator) { + mPictureDecorator = pictureDecorator; + } + public void setBound(boolean bound) { isBound = bound; } From 842d5817d847e840b7080a204e7c57952099492f Mon Sep 17 00:00:00 2001 From: Maxime Jallu Date: Mon, 2 Oct 2017 12:13:00 +0200 Subject: [PATCH 2/2] fix(dependence): remove dependence butterknife and picasso --- adapter/build.gradle | 4 ---- .../com/android/jmaxime/adapters/CheckableAdapter.java | 8 +------- .../android/jmaxime/viewholder/RecyclerViewHolder.java | 8 -------- 3 files changed, 1 insertion(+), 19 deletions(-) diff --git a/adapter/build.gradle b/adapter/build.gradle index 7b80d3e..aae897f 100644 --- a/adapter/build.gradle +++ b/adapter/build.gradle @@ -60,8 +60,4 @@ dependencies { // compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.50" compile "com.android.support:appcompat-v7:$androidSupport" compile "com.android.support:design:$androidSupport" -// compile 'com.squareup.picasso:picasso:2.5.2' -// compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0' -// compile 'com.jakewharton:butterknife:8.8.1' -// annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1' } diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java index 7745f9c..8ac7176 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java +++ b/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java @@ -7,13 +7,7 @@ import java.util.HashMap; import java.util.List; -/** - * @author Maxime Jallu - * @since 26/09/2017 - *

- * Use this Class for :
- * {DOCUMENTATION} - */ + public class CheckableAdapter extends RecyclerAdapter implements ViewCheckableCallback { private HashMap mCheckedMap = new HashMap<>(); diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java index 680afc3..9496d59 100644 --- a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java +++ b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java @@ -54,7 +54,6 @@ public abstract class RecyclerViewHolder extends RecyclerView.ViewHolder { @SuppressLint("NewApi") public RecyclerViewHolder(View itemView) { super(itemView); -// ButterKnife.bind(this, itemView); } public void initBinding() { @@ -97,13 +96,6 @@ protected final void showPicture(ImageView picture, String url) { if (mPictureDecorator != null) { mPictureDecorator.showPicture(picture, url); } -// Picasso.with(picture.getContext()) -// .load(url) -// .placeholder(R.drawable.no_image) -// .error(R.drawable.no_image) -// .fit() -// .centerInside() -// .into(picture); } protected boolean isBound() {