Skip to content

Commit

Permalink
Merge pull request #10 from MaximeJallu/fix_dependences
Browse files Browse the repository at this point in the history
Fix dependences
  • Loading branch information
MaximeJallu authored Oct 2, 2017
2 parents 507629a + 28b5717 commit 08780d5
Show file tree
Hide file tree
Showing 8 changed files with 93 additions and 27 deletions.
8 changes: 2 additions & 6 deletions adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ android {
// applicationId "com.android.jmaxime.com.android.jmaxime.adapter"
minSdkVersion 23
targetSdkVersion 26
versionCode 1710291830 /*YYMMDDHHMM*/
versionName "1.3"
versionCode 1711021045 /*YYMMDDHHMM*/
versionName "1.4"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,7 @@
import java.util.HashMap;
import java.util.List;

/**
* @author Maxime Jallu
* @since 26/09/2017
* <p>
* Use this Class for : <br/>
* {DOCUMENTATION}
*/

public class CheckableAdapter<T> extends RecyclerAdapter<T> implements ViewCheckableCallback<T> {

private HashMap<String, Boolean> mCheckedMap = new HashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -61,7 +63,10 @@ public RecyclerViewHolder<T> onCreateViewHolder(ViewGroup parent, int viewType)
throw new AccessControlException("mFactory is not instancied. thanks use setFactory() method.");
}

return mFactory.createVH(parent, viewType);
RecyclerViewHolder<T> vh = mFactory.createVH(parent, viewType);
/*used for decorator. Sample ButterKnife*/
vh.initBinding();
return vh;
}


Expand Down Expand Up @@ -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).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -25,6 +28,8 @@ public class ViewHolderFactory<T> {

private static final String TAG = ViewHolderFactory.class.getName();
private WeakReference<IBaseCommunication> mCommunication;
private WeakReference<ShowPictureDecorator> mDecoratorWeakReference;
private WeakReference<InitViewHolderDecorator> mInitViewDecoratorWeakReference;
private Class<? extends RecyclerViewHolder<T>> mViewHolderType;
private SparseArray<Class<? extends RecyclerViewHolder<T>>> mClassHashMap;

Expand All @@ -37,17 +42,27 @@ public ViewHolderFactory(Class<? extends RecyclerViewHolder<T>> viewHolderType)
this(viewHolderType, null);
}

public ViewHolderFactory(Class<? extends RecyclerViewHolder<T>> viewHolderType, IBaseCommunication callback) {
public ViewHolderFactory(Class<? extends RecyclerViewHolder<T>> viewHolderType, @Nullable IBaseCommunication callback) {
this(viewHolderType, callback, null, null);
}

public ViewHolderFactory(Class<? extends RecyclerViewHolder<T>> viewHolderType,
@Nullable IBaseCommunication callback, @Nullable InitViewHolderDecorator holderDecorator,
@Nullable ShowPictureDecorator pictureDecorator) {
mViewHolderType = viewHolderType;
mClassHashMap = new SparseArray<>();
setCommunication(callback);
setInitViewDecorator(holderDecorator);
setShowPictureDecorator(pictureDecorator);
}

public final RecyclerViewHolder<T> createVH(ViewGroup view, int viewType) {
RecyclerViewHolder<T> ret = getInstance(LayoutInflater.from(view.getContext())
.inflate(getLayoutRes(viewType), view, false), viewType);
if (ret != null) {
ret.setCommunication(getInterfaceCallback());
ret.setInitViewDecorator(mInitViewDecoratorWeakReference.get());
ret.setPictureDecorator(mDecoratorWeakReference.get());
}
return ret;
}
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.android.jmaxime.interfaces;

import android.view.View;

/**
* @author Maxime Jallu
* @since 02/10/2017
* <p>
* Use this Class for : <br/>
* {DOCUMENTATION}
*/
public interface InitViewHolderDecorator {
void initBinding(View view);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.android.jmaxime.interfaces;

import android.widget.ImageView;

public interface ShowPictureDecorator {
void showPicture(ImageView picture, String url);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,6 +39,8 @@ public abstract class RecyclerViewHolder<T> extends RecyclerView.ViewHolder {

private T mItem;
private boolean isBound;
private InitViewHolderDecorator mDecorator;
private ShowPictureDecorator mPictureDecorator;
private IBaseCommunication<T> mCommunication;

/**
Expand All @@ -54,7 +54,12 @@ public abstract class RecyclerViewHolder<T> extends RecyclerView.ViewHolder {
@SuppressLint("NewApi")
public RecyclerViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}

public void initBinding() {
if (mDecorator != null) {
mDecorator.initBinding(itemView);
}
}

public abstract void bind(final T item);
Expand Down Expand Up @@ -88,19 +93,23 @@ 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);
}
}

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;
}
Expand Down

0 comments on commit 08780d5

Please sign in to comment.