From 19c950cd7dfc07dd994505bc40035d1dce2245f9 Mon Sep 17 00:00:00 2001 From: Maxime Jallu Date: Fri, 29 Sep 2017 13:57:08 +0200 Subject: [PATCH 1/3] feat(adapter): add kotlin adapter --- adapter/build.gradle | 4 +- .../jmaxime/adapter/ArrayRecyclerAdapter.java | 131 ++++++++++ .../jmaxime/adapter/ArrayRecyclerAdapter.kt | 51 ---- .../jmaxime/adapter/DividerItemDecoration.kt | 12 +- .../jmaxime/adapter/RecyclerAdapter.java | 226 ++++++++++++++++++ .../jmaxime/adapter/RecyclerAdapter.kt | 192 --------------- .../jmaxime/factory/ViewHolderFactory.java | 33 ++- .../viewholder/RecyclerViewHolder.java | 139 +++++++++++ .../jmaxime/viewholder/RecyclerViewHolder.kt | 103 -------- adapter/src/main/res/drawable/no_image.png | Bin 0 -> 6140 bytes 10 files changed, 521 insertions(+), 370 deletions(-) create mode 100644 adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java delete mode 100644 adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt create mode 100644 adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java delete mode 100644 adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt create mode 100644 adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java delete mode 100644 adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt create mode 100644 adapter/src/main/res/drawable/no_image.png diff --git a/adapter/build.gradle b/adapter/build.gradle index 370bf52..de4e4a0 100644 --- a/adapter/build.gradle +++ b/adapter/build.gradle @@ -22,8 +22,8 @@ android { defaultConfig { minSdkVersion 23 targetSdkVersion 26 - versionCode 1 - versionName "1.0" + versionCode 1710291355 /*YYMMDDHHMM*/ + versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java new file mode 100644 index 0000000..b0b1c1d --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java @@ -0,0 +1,131 @@ +package com.android.jmaxime.adapter; + +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + + +import com.android.jmaxime.viewholder.RecyclerViewHolder; + +import java.util.List; + +/** + * @author Maxime Jallu + * @since 30/06/2016 + * + * Use this Class for :
+ * Crée un adapteur de recycler view de base + * @param Type d'item de la liste + * @param Type de ViewHolder doit extends de RecyclerViewHolder + */ +public abstract class ArrayRecyclerAdapter> extends RecyclerView.Adapter { + + private List mTList; + + /** + * Constructor + * @param TList list items for binding views + */ + public ArrayRecyclerAdapter(@NonNull final List TList) { + mTList = TList; + } + + @Override + public void onBindViewHolder(U holder, int position) { + holder.setItem(getItem(position)); + holder.setBound(false); + holder.bind(holder.getItem()); + holder.setBound(true); + } + + @Override + public int getItemCount() { + return mTList != null ? mTList.size() : 0; + } + + public U onCreateViewHolder(View view){ + return null; + } + + @Override + public U onCreateViewHolder(ViewGroup parent, int viewType) { + if(getLayoutRes(viewType) > 0) { + return onCreateViewHolder(LayoutInflater.from(parent.getContext()).inflate(getLayoutRes(viewType), parent, false)); + }else{ + throw new UnsupportedOperationException("onCreateViewHolder(ViewGroup parent, int viewType)"); + } + } + + @LayoutRes + protected int getLayoutRes(int viewType){ + return 0; + } + + /** + * Get Item + * @param position position founded + * @return instance to position + */ + public T getItem(int position){ + return mTList.get(position); + } + + /** + * 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). + * @param item element to be inserted + */ + public void addItem(T item){ + if (mTList != null) { + mTList.add(item); + notifyItemInserted(mTList.size()); + } + } + + /** + * 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). + * @param item element to be inserted + * @param position index at which the specified element is to be inserted + */ + public void addItem(T item, int position){ + if (mTList != null) { + position = Math.min(position, mTList.size()); + mTList.add(position, item); + notifyItemInserted(position); + } + } + + /** + * 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). + * @param position the index of the element to be removed + */ + public void removeItem(int position){ + if (mTList != null) { + mTList.remove(position); + notifyItemRemoved(position); + } + } + + /** + * Set new list items and notifyDataSetChanged() + * @link notifyDataSetChanged + * @param list new instance items list for bind views + */ + public void updateItems(@NonNull List list){ + mTList = list; + notifyDataSetChanged(); + } + + /** + * + * @return instance items list + */ + public List getTList() { + return mTList; + } +} diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt b/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt deleted file mode 100644 index 73be873..0000000 --- a/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.android.jmaxime.adapter - -import android.support.v7.widget.RecyclerView - -/** - * @author Maxime Jallu - * @since 30/06/2016 - * - * Create for CubeInStore - Android - * - * Use this Class for :

- * Crée un adapteur de recycler view de base - * @param Type d'item de la liste - * @param Type de ViewHolder doit extends de RecyclerViewHolder - **/ -abstract class ArrayRecyclerAdapter>(TList: List) : RecyclerView.Adapter() { - - var tList: List? = null - private set - - init { - tList = TList - } - - override fun onBindViewHolder(holder: U, position: Int) { - holder.bind(getItem(position)) - } - - override fun getItemCount(): Int { - return tList!!.size - } - - /** - * Get Item - * @param position position founded - * @return instance to position - */ - fun getItem(position: Int): T { - return tList!![position] - } - - /** - * Set new list items and notifyDataSetChanged() - * @link notifyDataSetChanged - * @param list new instance items list for bind views - */ - fun updateItems(list: List) { - tList = list - notifyDataSetChanged() - } -} diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/DividerItemDecoration.kt b/adapter/src/main/java/com/android/jmaxime/adapter/DividerItemDecoration.kt index 47cb619..3fa5dbe 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapter/DividerItemDecoration.kt +++ b/adapter/src/main/java/com/android/jmaxime/adapter/DividerItemDecoration.kt @@ -9,17 +9,7 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.view.View -/** - * @author Maxime Jallu - * @since 30/09/2016 - * - * - * Create for - Android - * - * - * Use this Class for :

- * ... {DOCUMENTATION} - */ + class DividerItemDecoration(context: Context, orientation: Int) : RecyclerView.ItemDecoration() { private val mDivider: Drawable? diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java new file mode 100644 index 0000000..6575cea --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java @@ -0,0 +1,226 @@ +package com.android.jmaxime.adapter; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.RecyclerView; +import android.view.ViewGroup; + + +import com.android.jmaxime.factory.ViewHolderFactory; +import com.android.jmaxime.interfaces.IAdapterChanged; +import com.android.jmaxime.interfaces.IBaseCommunication; +import com.android.jmaxime.interfaces.IViewType; +import com.android.jmaxime.viewholder.RecyclerViewHolder; + +import java.security.AccessControlException; +import java.util.ArrayList; +import java.util.List; + + +public class RecyclerAdapter extends RecyclerView.Adapter> { + + private List mTList; + private ViewHolderFactory mFactory; + private IAdapterChanged mAdapterChanged; + + public RecyclerAdapter() { + mTList = new ArrayList<>(); + } + + public RecyclerAdapter(ViewHolderFactory factory) { + this(new ArrayList<>(), factory); + } + + public RecyclerAdapter(Class> viewHolderType) { + this(new ArrayList<>(), viewHolderType, null); + } + + public RecyclerAdapter(Class> viewHolderType, @Nullable IBaseCommunication callback) { + this(new ArrayList<>(), viewHolderType, callback); + } + + public RecyclerAdapter(List TList, Class> viewHolderType) { + this(TList, viewHolderType, null); + } + + public RecyclerAdapter(List TList, Class> viewHolderType, @Nullable IBaseCommunication callback) { + this(TList, new ViewHolderFactory<>(viewHolderType, callback)); + } + + + public RecyclerAdapter(List TList, ViewHolderFactory factory) { + mTList = TList; + mFactory = factory; + } + + public void setFactory(ViewHolderFactory factory) { + mFactory = factory; + } + + @Override + public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (mFactory == null) { + throw new AccessControlException("mFactory is not instancied. thanks use setFactory() method."); + } + + return mFactory.createVH(parent, viewType); + } + + + @Override + public void onBindViewHolder(RecyclerViewHolder holder, int position) { + holder.setItem(getItem(position)); + holder.setBound(false); + holder.bind(holder.getItem()); + holder.setBound(true); + } + + @Override + public int getItemCount() { + return mTList != null ? mTList.size() : 0; + } + + /** + * Get Item + * + * @param position position founded + * @return instance to position + */ + public T getItem(int position) { + return mTList.get(position); + } + + @Override + public int getItemViewType(int position) { + if (getItem(position) != null && getItem(position) instanceof IViewType) { + return ((IViewType) getItem(position)).getItemViewType(); + } + return super.getItemViewType(position); + } + + public void putViewType(int viewType, Class> viewHolder){ + mFactory.putViewType(viewType, viewHolder); + } + + public boolean contains(final T obj) { + return mTList.contains(obj); + } + + protected void callChangedListener() { + if (mAdapterChanged != null) { + mAdapterChanged.onItemCountChange(getItemCount()); + } + } + + public void setOnAdapterChangedListener(IAdapterChanged adapterChanged) { + mAdapterChanged = adapterChanged; + } + + public void setCommunication(IBaseCommunication communication) { + mFactory.setCommunication(communication); + notifyDataSetChanged(); + } + + /** + * 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). + * + * @param item element to be inserted + */ + public void addItem(T item) { + if (mTList != null) { + mTList.add(item); + notifyItemInserted(mTList.size()); + } + } + + /** + * 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). + * + * @param item element to be inserted + * @param position index at which the specified element is to be inserted + */ + public void addItem(T item, int position) { + if (mTList != null) { + position = Math.min(position, mTList.size()); + mTList.add(position, item); + notifyItemInserted(position); + } + } + + /** + * 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). + * + * @param collection elements to be inserted + */ + public void addAll(List collection) { + if (mTList != null) { + mTList.addAll(collection); + int start = Math.max(0, (mTList.size() - collection.size()) - 1); + notifyItemRangeInserted(start, collection.size()); + } + } + + /** + * 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). + * + * @param collection elements to be inserted + * @param index position to be inserted first element of collection + */ + public void addAll(int index, List collection) { + if (mTList != null) { + mTList.addAll(index, collection); + int start = Math.max(0, (mTList.size() - collection.size()) - 1); + notifyItemRangeInserted(start, collection.size()); + } + } + + /** + * 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). + * + * @param item the element to be removed + */ + public void removeItem(T item) { + removeItem(getTList().indexOf(item)); + } + + /** + * 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). + * + * @param position the index of the element to be removed + */ + public void removeItem(int position) { + if (mTList != null && position > -1 && position < mTList.size()) { + mTList.remove(position); + notifyItemRemoved(position); + } + } + + /** + * Set new list items and notifyDataSetChanged() + * + * @param list new instance items list for bind views + * @link notifyDataSetChanged + */ + public void updateItems(@NonNull List list) { + mTList = list; + notifyDataSetChanged(); + } + + /** + * @return instance items list + */ + public List getTList() { + return mTList; + } + + public boolean isEmpty() { + return mTList == null || mTList.isEmpty(); + } +} + diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt b/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt deleted file mode 100644 index 345195c..0000000 --- a/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt +++ /dev/null @@ -1,192 +0,0 @@ -package com.android.jmaxime.adapter - -import android.support.v7.widget.RecyclerView -import android.view.LayoutInflater -import android.view.ViewGroup - -import com.android.jmaxime.factory.ViewHolderFactory -import com.android.jmaxime.interfaces.IAdapterChanged -import com.android.jmaxime.interfaces.IBaseCommunication -import com.android.jmaxime.interfaces.IViewType - -import java.security.AccessControlException -import java.util.ArrayList - -/** - * @author Maxime Jallu - * @since 03/05/2017 - * Use this Class for :

- * ... {DOCUMENTATION} - */ -class RecyclerAdapter : RecyclerView.Adapter> { - - private var mTList: MutableList? = null - private var mFactory: ViewHolderFactory? = null - private var mAdapterChanged: IAdapterChanged? = null - - constructor() { - mTList = ArrayList() - } - - constructor(factory: ViewHolderFactory) : this(ArrayList(), factory, null) {} - - constructor(viewHolderType: Class>) : this(ArrayList(), viewHolderType, null) {} - - constructor(viewHolderType: Class>, callback: IBaseCommunication?) : this(ArrayList(), viewHolderType, callback) {} - - @JvmOverloads constructor(TList: MutableList, viewHolderType: Class>, callback: IBaseCommunication? = null) : this(TList, ViewHolderFactory(viewHolderType), callback) {} - - constructor(TList: MutableList, factory: ViewHolderFactory, callback: IBaseCommunication?) { - mTList = TList - mFactory = factory - mFactory!!.communication = callback - } - - fun setFactory(factory: ViewHolderFactory) { - mFactory = factory - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder? { - if (mFactory == null) { - throw AccessControlException("mFactory is not instancied. thanks use setFactory() method.") - } - - return mFactory!!.createVH(LayoutInflater.from(parent.context) - .inflate(mFactory!! - .getLayoutRes(viewType), parent, false), viewType) - } - - - override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) { - holder.item = getItem(position) - holder.isBound = false - holder.bind(holder.item!!) - holder.isBound = true - } - - override fun getItemCount(): Int { - return if (mTList != null) mTList!!.size else 0 - } - - /** - * Get Item - * - * @param position position founded - * @return instance to position - */ - fun getItem(position: Int): T? { - return mTList!![position] - } - - override fun getItemViewType(position: Int): Int { - return if (getItem(position) != null && getItem(position) is IViewType) { - (getItem(position) as IViewType).getItemViewType() - } else super.getItemViewType(position) - } - - fun putViewType(viewType: Int, viewHolder: Class>) { - mFactory!!.putViewType(viewType, viewHolder) - } - - operator fun contains(obj: T): Boolean { - return mTList!!.contains(obj) - } - - protected fun callChangedListener() { - mAdapterChanged?.onItemCountChange(itemCount) - } - - fun setOnAdapterChangedListener(adapterChanged: IAdapterChanged?) { - mAdapterChanged = adapterChanged - } - - fun setCommunication(communication: IBaseCommunication?) { - mFactory!!.communication = communication - notifyDataSetChanged() - } - - /** - * 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). - * - * @param item element to be inserted - */ - fun addItem(item: T) { - if (mTList != null) { - mTList!!.add(item) - notifyItemInserted(mTList!!.size) - } - } - - /** - * 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). - * - * @param item element to be inserted - * @param position index at which the specified element is to be inserted - */ - fun addItem(item: T, position: Int) { - if (mTList != null) { - val pos = Math.min(position, mTList!!.size) - mTList!!.add(pos, item) - notifyItemInserted(pos) - } - } - - /** - * 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). - * - * @param collection elements to be inserted - */ - fun addAll(collection: List) { - if (mTList != null) { - mTList!!.addAll(collection) - val start = Math.max(0, mTList!!.size - collection.size - 1) - notifyItemRangeInserted(start, collection.size) - } - } - - /** - * 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). - * - * @param item the element to be removed - */ - fun removeItem(item: T) { - removeItem(tList!!.indexOf(item)) - } - - /** - * 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). - * - * @param position the index of the element to be removed - */ - fun removeItem(position: Int) { - if (mTList != null && position > -1 && position < mTList!!.size) { - mTList!!.removeAt(position) - notifyItemRemoved(position) - } - } - - /** - * Set new list items and notifyDataSetChanged() - * - * @param list new instance items list for bind views - * @link notifyDataSetChanged - */ - fun updateItems(list: MutableList) { - mTList = list - notifyDataSetChanged() - } - - /** - * @return instance items list - */ - val tList: List? - get() = mTList - - val isEmpty: Boolean - get() = mTList == null || mTList!!.isEmpty() -} 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 493adfa..f6717df 100644 --- a/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java +++ b/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java @@ -3,15 +3,17 @@ import android.annotation.SuppressLint; import android.support.annotation.LayoutRes; import android.util.Log; +import android.util.SparseArray; +import android.view.LayoutInflater; import android.view.View; +import android.view.ViewGroup; -import com.android.jmaxime.adapter.RecyclerViewHolder; import com.android.jmaxime.annotations.BindLayoutRes; import com.android.jmaxime.interfaces.IBaseCommunication; +import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; /** * @author Maxime Jallu @@ -24,20 +26,26 @@ public class ViewHolderFactory { private static final String TAG = ViewHolderFactory.class.getName(); private WeakReference mCommunication; private Class> mViewHolderType; - private HashMap>> mClassHashMap; + private SparseArray>> mClassHashMap; public ViewHolderFactory() { - this(null); + this(null, null); } @SuppressLint("UseSparseArrays") public ViewHolderFactory(Class> viewHolderType) { + this(viewHolderType, null); + } + + public ViewHolderFactory(Class> viewHolderType, IBaseCommunication callback) { mViewHolderType = viewHolderType; - mClassHashMap = new HashMap<>(); + mClassHashMap = new SparseArray<>(); + setCommunication(callback); } - public final RecyclerViewHolder createVH(View view, int viewType) { - RecyclerViewHolder ret = getInstance(view, viewType); + public final RecyclerViewHolder createVH(ViewGroup view, int viewType) { + RecyclerViewHolder ret = getInstance(LayoutInflater.from(view.getContext()) + .inflate(getLayoutRes(viewType), view, false), viewType); if (ret != null) { ret.setCommunication(getInterfaceCallback()); } @@ -48,6 +56,8 @@ public final RecyclerViewHolder createVH(View view, int viewType) { private RecyclerViewHolder getInstance(View view, int viewType) { RecyclerViewHolder ret = null; try { + /*prévention...*/ + getViewHolderType(viewType).getConstructor(View.class).setAccessible(true); ret = getViewHolderType(viewType).getConstructor(View.class).newInstance(view); } catch (InstantiationException e) { Log.i(TAG, "getInstance: "); @@ -56,7 +66,8 @@ private RecyclerViewHolder getInstance(View view, int viewType) { } catch (InvocationTargetException e) { Log.i(TAG, "getInstance: ", e); } catch (NoSuchMethodException e) { - Log.i(TAG, "not found constructor. La class suivante doit être en static ou ne pas être en inner class : " + getViewHolderType(viewType).getName(), e); + Log.i(TAG, "not found constructor. La class suivante doit être en static ou ne pas être en inner class : " + getViewHolderType(viewType) + .getName(), e); } return ret; } @@ -74,7 +85,7 @@ protected I getInterfaceCallback() { protected Class> getViewHolderType(int viewType) { Class> vm = mViewHolderType; - if (mClassHashMap.containsKey(viewType)) { + if (mClassHashMap.indexOfKey(viewType) > -1) { vm = mClassHashMap.get(viewType); } return vm; @@ -88,11 +99,11 @@ public void setCommunication(IBaseCommunication communication) { mCommunication = new WeakReference<>(communication); } - public final @LayoutRes int getLayoutRes(int viewType) { + final @LayoutRes int getLayoutRes(int viewType) { return getViewHolderType(viewType).getAnnotation(BindLayoutRes.class).value(); } - public void putViewType(int viewType, Class> viewHolder){ + public void putViewType(int viewType, Class> viewHolder) { mClassHashMap.put(viewType, viewHolder); } } diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java new file mode 100644 index 0000000..d506b78 --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java @@ -0,0 +1,139 @@ +package com.android.jmaxime.viewholder; + + +import android.annotation.SuppressLint; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.PluralsRes; +import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +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; + +/** + * @author Maxime Jallu + * @link ArrayRecyclerAdapter + *

+ * Tools this class:
+ *

+ * getContext() + * getColor(@ColorRes res) + * getDrawable(@DrawableRes res) + * @since 30/06/2016 + *

+ * Create for CubeInStore - Android (Decathlon) + *

+ * Use this Class for :
+ * make it easier ViewHolder adapter recyclerView, define T type of item + * Must to use in ArrayRecyclerAdapter + */ +public abstract class RecyclerViewHolder extends RecyclerView.ViewHolder { + + private T mItem; + private boolean isBound; + private IBaseCommunication mCommunication; + + /** + * This super() auto BindViews with ButterKnife
+ * + * ButterKnife.bind(this, itemView); + * + * + * @param itemView the Views holder + */ + @SuppressLint("NewApi") + public RecyclerViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } + + public abstract void bind(final T item); + + protected Context getContext() { + return itemView.getContext(); + } + + protected final String getString(@StringRes int stringRes) { + return getContext().getString(stringRes); + } + + protected final String getString(@StringRes int stringRes, String string) { + return getContext().getResources().getString(stringRes, string); + } + + protected final String getQuantityString(@PluralsRes int pluralRes, int quantity) { + return getContext().getResources().getQuantityString(pluralRes, quantity, quantity); + } + + protected final String getQuantityStringFormat(@PluralsRes int pluralRes, int quantity) { + return getContext().getResources().getQuantityString(pluralRes, quantity, quantity); + } + + protected final int getColor(@ColorRes int colorResId) { + return ContextCompat.getColor(getContext(), colorResId); + } + + protected final Drawable getDrawable(@DrawableRes int drawableResId) { + return ContextCompat.getDrawable(getContext(), 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); + } + + protected boolean isBound() { + return isBound; + } + + public void setBound(boolean bound) { + isBound = bound; + } + + public T getItem() { + return mItem; + } + + public void setItem(T item) { + mItem = item; + } + + protected final void onClickRemoveItem() { + getDispatcher().onDeleteClicked(getAdapterPosition(), getItem()); + } + + protected final void onClickEditItem() { + getDispatcher().onEditClicked(getAdapterPosition(), getItem()); + } + + protected > I getDispatcher() { + I i = null; + try { + //noinspection unchecked + i = (I) mCommunication; + } catch (ClassCastException e) { + Log.e("ViewHolderFactory", "getInterfaceCallback: ", e); + } + return i; + } + + public void setCommunication(IBaseCommunication interfaceCallback) { + mCommunication = interfaceCallback; + } +} + diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt deleted file mode 100644 index f42eeb6..0000000 --- a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt +++ /dev/null @@ -1,103 +0,0 @@ -package com.android.jmaxime.adapter - -import android.content.Context -import android.graphics.drawable.Drawable -import android.support.annotation.* -import android.support.v4.content.ContextCompat -import android.support.v7.widget.RecyclerView -import android.util.Log -import android.view.View -import android.widget.ImageView -import butterknife.ButterKnife -import com.android.jmaxime.interfaces.IBaseCommunication -import com.squareup.picasso.Picasso - -/** - * @author Maxime Jallu - * * - * @link ArrayRecyclerAdapter - * * Tools this class:

- * * - * * getContext() - * * getColor(@ColorRes res) - * * getDrawable(@DrawableRes res) - * * - * @since 30/06/2016 - * * - * * Create for CubeInStore - Android (Decathlon) - * * - * * Use this Class for :

- * * make it easier ViewHolder adapter recyclerView, define T type of item - * * Must to use in RecyclerAdapter - */ -abstract class RecyclerViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) { - - var item: T? = null - var isBound: Boolean = false - private var mCommunication: IBaseCommunication? = null - - init { - ButterKnife.bind(this, itemView) - } - - abstract fun bind(item: T) - - protected val context: Context get() = itemView.context - - protected fun getString(@StringRes stringRes: Int): String { - return context.getString(stringRes) - } - - protected fun getString(@StringRes stringRes: Int, string: String): String { - return context.resources.getString(stringRes, string) - } - - protected fun getQuantityString(@PluralsRes pluralRes: Int, quantity: Int): String { - return context.resources.getQuantityString(pluralRes, quantity, quantity) - } - - protected fun getQuantityStringFormat(@PluralsRes pluralRes: Int, quantity: Int): String { - return context.resources.getQuantityString(pluralRes, quantity, quantity) - } - - protected fun getColor(@ColorRes colorResId: Int): Int { - return ContextCompat.getColor(context, colorResId) - } - - protected fun getDrawable(@DrawableRes drawableResId: Int): Drawable { - return ContextCompat.getDrawable(context, drawableResId) - } - - fun showPicture(picture: ImageView, url: String) { - Picasso.with(picture.context) - .load(url) - .placeholder(R.drawable.ic_image_black_24dp) - .error(R.drawable.ic_image_black_24dp) - .fit() - .centerInside() - .into(picture) - } - - protected fun onClickRemoveItem() { - getDispatcher>()?.onDeleteClicked(adapterPosition, item!!) - } - - protected fun onClickEditItem() { - getDispatcher>()?.onEditClicked(adapterPosition, item!!) - } - - protected fun > getDispatcher(): I? { - var i: I? = null - try { - i = mCommunication as I? - } catch (e: ClassCastException) { - Log.e("ViewHolderFactory", "getInterfaceCallback: ", e) - } - - return i - } - - fun setCommunication(interfaceCallback: IBaseCommunication?) { - mCommunication = interfaceCallback - } -} diff --git a/adapter/src/main/res/drawable/no_image.png b/adapter/src/main/res/drawable/no_image.png new file mode 100644 index 0000000000000000000000000000000000000000..933366e5e59ae5769f6619380ea93a75676f85ae GIT binary patch literal 6140 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 Date: Fri, 29 Sep 2017 13:57:08 +0200 Subject: [PATCH 2/3] feat(adapter): add kotlin adapter --- adapter/build.gradle | 4 +- .../jmaxime/adapter/ArrayRecyclerAdapter.java | 131 ++++++++++ .../jmaxime/adapter/RecyclerAdapter.java | 226 ++++++++++++++++++ .../jmaxime/factory/ViewHolderFactory.java | 35 +-- .../jmaxime/viewholder/KRecyclerViewHolder.kt | 103 -------- .../viewholder/RecyclerViewHolder.java | 139 +++++++++++ .../jmaxime/adapters/ArrayRecyclerAdapter.kt | 51 ---- .../jmaxime/adapters/DividerItemDecoration.kt | 12 +- .../jmaxime/adapters/RecyclerAdapter.kt | 187 --------------- 9 files changed, 518 insertions(+), 370 deletions(-) create mode 100644 adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java create mode 100644 adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java delete mode 100644 adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt create mode 100644 adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt diff --git a/adapter/build.gradle b/adapter/build.gradle index 6411b5e..491d62b 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 1 - versionName "1.0" + versionCode 1710291355 /*YYMMDDHHMM*/ + versionName "1.1" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java new file mode 100644 index 0000000..b0b1c1d --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.java @@ -0,0 +1,131 @@ +package com.android.jmaxime.adapter; + +import android.support.annotation.LayoutRes; +import android.support.annotation.NonNull; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + + +import com.android.jmaxime.viewholder.RecyclerViewHolder; + +import java.util.List; + +/** + * @author Maxime Jallu + * @since 30/06/2016 + * + * Use this Class for :
+ * Crée un adapteur de recycler view de base + * @param Type d'item de la liste + * @param Type de ViewHolder doit extends de RecyclerViewHolder + */ +public abstract class ArrayRecyclerAdapter> extends RecyclerView.Adapter { + + private List mTList; + + /** + * Constructor + * @param TList list items for binding views + */ + public ArrayRecyclerAdapter(@NonNull final List TList) { + mTList = TList; + } + + @Override + public void onBindViewHolder(U holder, int position) { + holder.setItem(getItem(position)); + holder.setBound(false); + holder.bind(holder.getItem()); + holder.setBound(true); + } + + @Override + public int getItemCount() { + return mTList != null ? mTList.size() : 0; + } + + public U onCreateViewHolder(View view){ + return null; + } + + @Override + public U onCreateViewHolder(ViewGroup parent, int viewType) { + if(getLayoutRes(viewType) > 0) { + return onCreateViewHolder(LayoutInflater.from(parent.getContext()).inflate(getLayoutRes(viewType), parent, false)); + }else{ + throw new UnsupportedOperationException("onCreateViewHolder(ViewGroup parent, int viewType)"); + } + } + + @LayoutRes + protected int getLayoutRes(int viewType){ + return 0; + } + + /** + * Get Item + * @param position position founded + * @return instance to position + */ + public T getItem(int position){ + return mTList.get(position); + } + + /** + * 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). + * @param item element to be inserted + */ + public void addItem(T item){ + if (mTList != null) { + mTList.add(item); + notifyItemInserted(mTList.size()); + } + } + + /** + * 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). + * @param item element to be inserted + * @param position index at which the specified element is to be inserted + */ + public void addItem(T item, int position){ + if (mTList != null) { + position = Math.min(position, mTList.size()); + mTList.add(position, item); + notifyItemInserted(position); + } + } + + /** + * 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). + * @param position the index of the element to be removed + */ + public void removeItem(int position){ + if (mTList != null) { + mTList.remove(position); + notifyItemRemoved(position); + } + } + + /** + * Set new list items and notifyDataSetChanged() + * @link notifyDataSetChanged + * @param list new instance items list for bind views + */ + public void updateItems(@NonNull List list){ + mTList = list; + notifyDataSetChanged(); + } + + /** + * + * @return instance items list + */ + public List getTList() { + return mTList; + } +} diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java new file mode 100644 index 0000000..6575cea --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.java @@ -0,0 +1,226 @@ +package com.android.jmaxime.adapter; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.RecyclerView; +import android.view.ViewGroup; + + +import com.android.jmaxime.factory.ViewHolderFactory; +import com.android.jmaxime.interfaces.IAdapterChanged; +import com.android.jmaxime.interfaces.IBaseCommunication; +import com.android.jmaxime.interfaces.IViewType; +import com.android.jmaxime.viewholder.RecyclerViewHolder; + +import java.security.AccessControlException; +import java.util.ArrayList; +import java.util.List; + + +public class RecyclerAdapter extends RecyclerView.Adapter> { + + private List mTList; + private ViewHolderFactory mFactory; + private IAdapterChanged mAdapterChanged; + + public RecyclerAdapter() { + mTList = new ArrayList<>(); + } + + public RecyclerAdapter(ViewHolderFactory factory) { + this(new ArrayList<>(), factory); + } + + public RecyclerAdapter(Class> viewHolderType) { + this(new ArrayList<>(), viewHolderType, null); + } + + public RecyclerAdapter(Class> viewHolderType, @Nullable IBaseCommunication callback) { + this(new ArrayList<>(), viewHolderType, callback); + } + + public RecyclerAdapter(List TList, Class> viewHolderType) { + this(TList, viewHolderType, null); + } + + public RecyclerAdapter(List TList, Class> viewHolderType, @Nullable IBaseCommunication callback) { + this(TList, new ViewHolderFactory<>(viewHolderType, callback)); + } + + + public RecyclerAdapter(List TList, ViewHolderFactory factory) { + mTList = TList; + mFactory = factory; + } + + public void setFactory(ViewHolderFactory factory) { + mFactory = factory; + } + + @Override + public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + if (mFactory == null) { + throw new AccessControlException("mFactory is not instancied. thanks use setFactory() method."); + } + + return mFactory.createVH(parent, viewType); + } + + + @Override + public void onBindViewHolder(RecyclerViewHolder holder, int position) { + holder.setItem(getItem(position)); + holder.setBound(false); + holder.bind(holder.getItem()); + holder.setBound(true); + } + + @Override + public int getItemCount() { + return mTList != null ? mTList.size() : 0; + } + + /** + * Get Item + * + * @param position position founded + * @return instance to position + */ + public T getItem(int position) { + return mTList.get(position); + } + + @Override + public int getItemViewType(int position) { + if (getItem(position) != null && getItem(position) instanceof IViewType) { + return ((IViewType) getItem(position)).getItemViewType(); + } + return super.getItemViewType(position); + } + + public void putViewType(int viewType, Class> viewHolder){ + mFactory.putViewType(viewType, viewHolder); + } + + public boolean contains(final T obj) { + return mTList.contains(obj); + } + + protected void callChangedListener() { + if (mAdapterChanged != null) { + mAdapterChanged.onItemCountChange(getItemCount()); + } + } + + public void setOnAdapterChangedListener(IAdapterChanged adapterChanged) { + mAdapterChanged = adapterChanged; + } + + public void setCommunication(IBaseCommunication communication) { + mFactory.setCommunication(communication); + notifyDataSetChanged(); + } + + /** + * 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). + * + * @param item element to be inserted + */ + public void addItem(T item) { + if (mTList != null) { + mTList.add(item); + notifyItemInserted(mTList.size()); + } + } + + /** + * 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). + * + * @param item element to be inserted + * @param position index at which the specified element is to be inserted + */ + public void addItem(T item, int position) { + if (mTList != null) { + position = Math.min(position, mTList.size()); + mTList.add(position, item); + notifyItemInserted(position); + } + } + + /** + * 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). + * + * @param collection elements to be inserted + */ + public void addAll(List collection) { + if (mTList != null) { + mTList.addAll(collection); + int start = Math.max(0, (mTList.size() - collection.size()) - 1); + notifyItemRangeInserted(start, collection.size()); + } + } + + /** + * 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). + * + * @param collection elements to be inserted + * @param index position to be inserted first element of collection + */ + public void addAll(int index, List collection) { + if (mTList != null) { + mTList.addAll(index, collection); + int start = Math.max(0, (mTList.size() - collection.size()) - 1); + notifyItemRangeInserted(start, collection.size()); + } + } + + /** + * 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). + * + * @param item the element to be removed + */ + public void removeItem(T item) { + removeItem(getTList().indexOf(item)); + } + + /** + * 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). + * + * @param position the index of the element to be removed + */ + public void removeItem(int position) { + if (mTList != null && position > -1 && position < mTList.size()) { + mTList.remove(position); + notifyItemRemoved(position); + } + } + + /** + * Set new list items and notifyDataSetChanged() + * + * @param list new instance items list for bind views + * @link notifyDataSetChanged + */ + public void updateItems(@NonNull List list) { + mTList = list; + notifyDataSetChanged(); + } + + /** + * @return instance items list + */ + public List getTList() { + return mTList; + } + + public boolean isEmpty() { + return mTList == null || mTList.isEmpty(); + } +} + 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 5dab18b..f6717df 100644 --- a/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java +++ b/adapter/src/main/java/com/android/jmaxime/factory/ViewHolderFactory.java @@ -8,9 +8,9 @@ import android.view.View; import android.view.ViewGroup; -import com.android.jmaxime.viewholder.JRecyclerViewHolder; import com.android.jmaxime.annotations.BindLayoutRes; import com.android.jmaxime.interfaces.IBaseCommunication; +import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.lang.ref.WeakReference; import java.lang.reflect.InvocationTargetException; @@ -25,27 +25,27 @@ public class ViewHolderFactory { private static final String TAG = ViewHolderFactory.class.getName(); private WeakReference mCommunication; - private Class> mViewHolderType; - private SparseArray>> mClassHashMap; + private Class> mViewHolderType; + private SparseArray>> mClassHashMap; public ViewHolderFactory() { - this(null); + this(null, null); } @SuppressLint("UseSparseArrays") - public ViewHolderFactory(Class> viewHolderType) { + public ViewHolderFactory(Class> viewHolderType) { this(viewHolderType, null); } - public ViewHolderFactory(Class> viewHolderType, IBaseCommunication callback) { + public ViewHolderFactory(Class> viewHolderType, IBaseCommunication callback) { mViewHolderType = viewHolderType; mClassHashMap = new SparseArray<>(); setCommunication(callback); } - public final JRecyclerViewHolder createVH(ViewGroup view, int viewType) { - JRecyclerViewHolder ret = getInstance(LayoutInflater.from(view.getContext()) - .inflate(getLayoutRes(viewType), view, false), viewType); + public final RecyclerViewHolder createVH(ViewGroup view, int viewType) { + RecyclerViewHolder ret = getInstance(LayoutInflater.from(view.getContext()) + .inflate(getLayoutRes(viewType), view, false), viewType); if (ret != null) { ret.setCommunication(getInterfaceCallback()); } @@ -53,9 +53,11 @@ public final JRecyclerViewHolder createVH(ViewGroup view, int viewType) { } @SuppressWarnings("TryWithIdenticalCatches") - private JRecyclerViewHolder getInstance(View view, int viewType) { - JRecyclerViewHolder ret = null; + private RecyclerViewHolder getInstance(View view, int viewType) { + RecyclerViewHolder ret = null; try { + /*prévention...*/ + getViewHolderType(viewType).getConstructor(View.class).setAccessible(true); ret = getViewHolderType(viewType).getConstructor(View.class).newInstance(view); } catch (InstantiationException e) { Log.i(TAG, "getInstance: "); @@ -64,7 +66,8 @@ private JRecyclerViewHolder getInstance(View view, int viewType) { } catch (InvocationTargetException e) { Log.i(TAG, "getInstance: ", e); } catch (NoSuchMethodException e) { - Log.i(TAG, "not found constructor. La class suivante doit être en static ou ne pas être en inner class : " + getViewHolderType(viewType).getName(), e); + Log.i(TAG, "not found constructor. La class suivante doit être en static ou ne pas être en inner class : " + getViewHolderType(viewType) + .getName(), e); } return ret; } @@ -80,8 +83,8 @@ protected I getInterfaceCallback() { return i; } - protected Class> getViewHolderType(int viewType) { - Class> vm = mViewHolderType; + protected Class> getViewHolderType(int viewType) { + Class> vm = mViewHolderType; if (mClassHashMap.indexOfKey(viewType) > -1) { vm = mClassHashMap.get(viewType); } @@ -96,11 +99,11 @@ public void setCommunication(IBaseCommunication communication) { mCommunication = new WeakReference<>(communication); } - public final @LayoutRes int getLayoutRes(int viewType) { + final @LayoutRes int getLayoutRes(int viewType) { return getViewHolderType(viewType).getAnnotation(BindLayoutRes.class).value(); } - public void putViewType(int viewType, Class> viewHolder){ + public void putViewType(int viewType, Class> viewHolder) { mClassHashMap.put(viewType, viewHolder); } } diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt b/adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt deleted file mode 100644 index 03c30d8..0000000 --- a/adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt +++ /dev/null @@ -1,103 +0,0 @@ -package com.android.jmaxime.adapter - -import android.content.Context -import android.graphics.drawable.Drawable -import android.support.annotation.* -import android.support.v4.content.ContextCompat -import android.support.v7.widget.RecyclerView -import android.util.Log -import android.view.View -import android.widget.ImageView -import butterknife.ButterKnife -import com.android.jmaxime.interfaces.IBaseCommunication -import com.squareup.picasso.Picasso - -/** - * @author Maxime Jallu - * * - * @link ArrayRecyclerAdapter - * * Tools this class:

- * * - * * getContext() - * * getColor(@ColorRes res) - * * getDrawable(@DrawableRes res) - * * - * @since 30/06/2016 - * * - * * Create for CubeInStore - Android (Decathlon) - * * - * * Use this Class for :

- * * make it easier ViewHolder com.android.jmaxime.adapter recyclerView, define T type of item - * * Must to use in RecyclerAdapter - */ -abstract class KRecyclerViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) { - - var item: T? = null - var isBound: Boolean = false - private var mCommunication: IBaseCommunication? = null - - init { - ButterKnife.bind(this, itemView) - } - - abstract fun bind(item: T) - - protected val context: Context get() = itemView.context - - protected fun getString(@StringRes stringRes: Int): String { - return context.getString(stringRes) - } - - protected fun getString(@StringRes stringRes: Int, string: String): String { - return context.resources.getString(stringRes, string) - } - - protected fun getQuantityString(@PluralsRes pluralRes: Int, quantity: Int): String { - return context.resources.getQuantityString(pluralRes, quantity, quantity) - } - - protected fun getQuantityStringFormat(@PluralsRes pluralRes: Int, quantity: Int): String { - return context.resources.getQuantityString(pluralRes, quantity, quantity) - } - - protected fun getColor(@ColorRes colorResId: Int): Int { - return ContextCompat.getColor(context, colorResId) - } - - protected fun getDrawable(@DrawableRes drawableResId: Int): Drawable { - return ContextCompat.getDrawable(context, drawableResId) - } - - fun showPicture(picture: ImageView, url: String) { - Picasso.with(picture.context) - .load(url) - .placeholder(R.drawable.ic_image_black_24dp) - .error(R.drawable.ic_image_black_24dp) - .fit() - .centerInside() - .into(picture) - } - - protected fun onClickRemoveItem() { - getDispatcher>()?.onDeleteClicked(adapterPosition, item!!) - } - - protected fun onClickEditItem() { - getDispatcher>()?.onEditClicked(adapterPosition, item!!) - } - - protected fun > getDispatcher(): I? { - var i: I? = null - try { - i = mCommunication as I? - } catch (e: ClassCastException) { - Log.e("ViewHolderFactory", "getInterfaceCallback: ", e) - } - - return i - } - - fun setCommunication(interfaceCallback: IBaseCommunication?) { - mCommunication = interfaceCallback - } -} diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java new file mode 100644 index 0000000..d506b78 --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.java @@ -0,0 +1,139 @@ +package com.android.jmaxime.viewholder; + + +import android.annotation.SuppressLint; +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.support.annotation.ColorRes; +import android.support.annotation.DrawableRes; +import android.support.annotation.PluralsRes; +import android.support.annotation.StringRes; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +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; + +/** + * @author Maxime Jallu + * @link ArrayRecyclerAdapter + *

+ * Tools this class:
+ *

+ * getContext() + * getColor(@ColorRes res) + * getDrawable(@DrawableRes res) + * @since 30/06/2016 + *

+ * Create for CubeInStore - Android (Decathlon) + *

+ * Use this Class for :
+ * make it easier ViewHolder adapter recyclerView, define T type of item + * Must to use in ArrayRecyclerAdapter + */ +public abstract class RecyclerViewHolder extends RecyclerView.ViewHolder { + + private T mItem; + private boolean isBound; + private IBaseCommunication mCommunication; + + /** + * This super() auto BindViews with ButterKnife
+ * + * ButterKnife.bind(this, itemView); + * + * + * @param itemView the Views holder + */ + @SuppressLint("NewApi") + public RecyclerViewHolder(View itemView) { + super(itemView); + ButterKnife.bind(this, itemView); + } + + public abstract void bind(final T item); + + protected Context getContext() { + return itemView.getContext(); + } + + protected final String getString(@StringRes int stringRes) { + return getContext().getString(stringRes); + } + + protected final String getString(@StringRes int stringRes, String string) { + return getContext().getResources().getString(stringRes, string); + } + + protected final String getQuantityString(@PluralsRes int pluralRes, int quantity) { + return getContext().getResources().getQuantityString(pluralRes, quantity, quantity); + } + + protected final String getQuantityStringFormat(@PluralsRes int pluralRes, int quantity) { + return getContext().getResources().getQuantityString(pluralRes, quantity, quantity); + } + + protected final int getColor(@ColorRes int colorResId) { + return ContextCompat.getColor(getContext(), colorResId); + } + + protected final Drawable getDrawable(@DrawableRes int drawableResId) { + return ContextCompat.getDrawable(getContext(), 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); + } + + protected boolean isBound() { + return isBound; + } + + public void setBound(boolean bound) { + isBound = bound; + } + + public T getItem() { + return mItem; + } + + public void setItem(T item) { + mItem = item; + } + + protected final void onClickRemoveItem() { + getDispatcher().onDeleteClicked(getAdapterPosition(), getItem()); + } + + protected final void onClickEditItem() { + getDispatcher().onEditClicked(getAdapterPosition(), getItem()); + } + + protected > I getDispatcher() { + I i = null; + try { + //noinspection unchecked + i = (I) mCommunication; + } catch (ClassCastException e) { + Log.e("ViewHolderFactory", "getInterfaceCallback: ", e); + } + return i; + } + + public void setCommunication(IBaseCommunication interfaceCallback) { + mCommunication = interfaceCallback; + } +} + diff --git a/adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt deleted file mode 100644 index 2455df2..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt +++ /dev/null @@ -1,51 +0,0 @@ -package com.android.jmaxime.adapter - -import android.support.v7.widget.RecyclerView - -/** - * @author Maxime Jallu - * @since 30/06/2016 - * - * Create for CubeInStore - Android - * - * Use this Class for :

- * Crée un adapteur de recycler view de base - * @param Type d'item de la liste - * @param Type de ViewHolder doit extends de RecyclerViewHolder - **/ -abstract class ArrayRecyclerAdapter>(TList: List) : RecyclerView.Adapter() { - - var tList: List? = null - private set - - init { - tList = TList - } - - override fun onBindViewHolder(holder: U, position: Int) { - holder.bind(getItem(position)) - } - - override fun getItemCount(): Int { - return tList!!.size - } - - /** - * Get Item - * @param position position founded - * @return instance to position - */ - fun getItem(position: Int): T { - return tList!![position] - } - - /** - * Set new list items and notifyDataSetChanged() - * @link notifyDataSetChanged - * @param list new instance items list for bind views - */ - fun updateItems(list: List) { - tList = list - notifyDataSetChanged() - } -} diff --git a/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt index 47cb619..3fa5dbe 100644 --- a/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt +++ b/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt @@ -9,17 +9,7 @@ import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.RecyclerView import android.view.View -/** - * @author Maxime Jallu - * @since 30/09/2016 - * - * - * Create for - Android - * - * - * Use this Class for :

- * ... {DOCUMENTATION} - */ + class DividerItemDecoration(context: Context, orientation: Int) : RecyclerView.ItemDecoration() { private val mDivider: Drawable? diff --git a/adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt deleted file mode 100644 index 403e274..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt +++ /dev/null @@ -1,187 +0,0 @@ -package com.android.jmaxime.adapter - -import android.support.v7.widget.RecyclerView -import android.view.ViewGroup -import com.android.jmaxime.factory.ViewHolderFactory -import com.android.jmaxime.interfaces.IAdapterChanged -import com.android.jmaxime.interfaces.IBaseCommunication -import com.android.jmaxime.interfaces.IViewType -import java.security.AccessControlException -import java.util.* - -/** - * @author Maxime Jallu - * @since 03/05/2017 - * Use this Class for :

- * ... {DOCUMENTATION} - */ -class RecyclerAdapter : RecyclerView.Adapter> { - - private var mTList: MutableList? = null - private var mFactory: ViewHolderFactory? = null - private var mAdapterChanged: IAdapterChanged? = null - - constructor() { - mTList = ArrayList() - } - - constructor(factory: ViewHolderFactory) : this(ArrayList(), factory, null) {} - - constructor(viewHolderType: Class>) : this(ArrayList(), viewHolderType, null) {} - - constructor(viewHolderType: Class>, callback: IBaseCommunication?) : this(ArrayList(), viewHolderType, callback) {} - - @JvmOverloads constructor(TList: MutableList, viewHolderType: Class>, callback: IBaseCommunication? = null) : this(TList, ViewHolderFactory(viewHolderType), callback) {} - - constructor(TList: MutableList, factory: ViewHolderFactory, callback: IBaseCommunication?) { - mTList = TList - mFactory = factory - mFactory!!.communication = callback - } - - fun setFactory(factory: ViewHolderFactory) { - mFactory = factory - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KRecyclerViewHolder? { - if (mFactory == null) { - throw AccessControlException("mFactory is not instancied. thanks use setFactory() method.") - } - - return mFactory!!.createVH(parent, viewType) - } - - - override fun onBindViewHolder(holder: KRecyclerViewHolder, position: Int) { - holder.item = getItem(position) - holder.isBound = false - holder.bind(holder.item!!) - holder.isBound = true - } - - override fun getItemCount(): Int { - return if (mTList != null) mTList!!.size else 0 - } - - /** - * Get Item - * - * @param position position founded - * @return instance to position - */ - fun getItem(position: Int): T? { - return mTList!![position] - } - - override fun getItemViewType(position: Int): Int { - return if (getItem(position) != null && getItem(position) is IViewType) { - (getItem(position) as IViewType).getItemViewType() - } else super.getItemViewType(position) - } - - fun putViewType(viewType: Int, viewHolder: Class>) { - mFactory!!.putViewType(viewType, viewHolder) - } - - operator fun contains(obj: T): Boolean { - return mTList!!.contains(obj) - } - - protected fun callChangedListener() { - mAdapterChanged?.onItemCountChange(itemCount) - } - - fun setOnAdapterChangedListener(adapterChanged: IAdapterChanged?) { - mAdapterChanged = adapterChanged - } - - fun setCommunication(communication: IBaseCommunication?) { - mFactory!!.communication = communication - notifyDataSetChanged() - } - - /** - * 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). - * - * @param item element to be inserted - */ - fun addItem(item: T) { - if (mTList != null) { - mTList!!.add(item) - notifyItemInserted(mTList!!.size) - } - } - - /** - * 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). - * - * @param item element to be inserted - * @param position index at which the specified element is to be inserted - */ - fun addItem(item: T, position: Int) { - if (mTList != null) { - val pos = Math.min(position, mTList!!.size) - mTList!!.add(pos, item) - notifyItemInserted(pos) - } - } - - /** - * 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). - * - * @param collection elements to be inserted - */ - fun addAll(collection: List) { - if (mTList != null) { - mTList!!.addAll(collection) - val start = Math.max(0, mTList!!.size - collection.size - 1) - notifyItemRangeInserted(start, collection.size) - } - } - - /** - * 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). - * - * @param item the element to be removed - */ - fun removeItem(item: T) { - removeItem(tList!!.indexOf(item)) - } - - /** - * 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). - * - * @param position the index of the element to be removed - */ - fun removeItem(position: Int) { - if (mTList != null && position > -1 && position < mTList!!.size) { - mTList!!.removeAt(position) - notifyItemRemoved(position) - } - } - - /** - * Set new list items and notifyDataSetChanged() - * - * @param list new instance items list for bind views - * @link notifyDataSetChanged - */ - fun updateItems(list: MutableList) { - mTList = list - notifyDataSetChanged() - } - - /** - * @return instance items list - */ - val tList: List? - get() = mTList - - val isEmpty: Boolean - get() = mTList == null || mTList!!.isEmpty() -} From 1050159bde469c18ef59721cf1b13043eaa25fdb Mon Sep 17 00:00:00 2001 From: Maxime Jallu Date: Fri, 29 Sep 2017 14:18:22 +0200 Subject: [PATCH 3/3] feat(adapter): add kotlin adapter --- .../jmaxime/adapters/CheckableAdapter.java | 4 +- .../adapters/DividerItemDecoration.java | 201 ++++++++++++++++++ .../jmaxime/adapters/EasyPagerAdapter.java | 10 +- .../jmaxime/adapters/RecyclerAdapter.java | 18 +- .../jmaxime/interfaces/IAdapterChanged.java | 12 ++ .../interfaces/IBaseCommunication.java | 13 ++ .../android/jmaxime/interfaces/IViewType.java | 12 ++ .../interfaces/ViewCheckableCallback.java | 19 ++ .../viewholder/JRecyclerViewHolder.java | 138 ------------ .../jmaxime/adapters/DividerItemDecoration.kt | 89 -------- .../jmaxime/interfaces/IAdapterChanged.kt | 12 -- .../jmaxime/interfaces/IBaseCommunication.kt | 18 -- .../android/jmaxime/interfaces/IViewType.kt | 12 -- .../interfaces/ViewCheckableCallback.kt | 19 -- 14 files changed, 273 insertions(+), 304 deletions(-) create mode 100644 adapter/src/main/java/com/android/jmaxime/adapters/DividerItemDecoration.java create mode 100644 adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.java create mode 100644 adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.java create mode 100644 adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.java create mode 100644 adapter/src/main/java/com/android/jmaxime/interfaces/ViewCheckableCallback.java delete mode 100644 adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/interfaces/IAdapterChanged.kt delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/interfaces/IBaseCommunication.kt delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/interfaces/IViewType.kt delete mode 100644 adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt 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 d043e60..7745f9c 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java +++ b/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java @@ -2,7 +2,7 @@ import com.android.jmaxime.factory.ViewHolderFactory; import com.android.jmaxime.interfaces.ViewCheckableCallback; -import com.android.jmaxime.viewholder.JRecyclerViewHolder; +import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.util.HashMap; import java.util.List; @@ -18,7 +18,7 @@ public class CheckableAdapter extends RecyclerAdapter implements ViewCheck private HashMap mCheckedMap = new HashMap<>(); - public CheckableAdapter(Class> viewHolderType) { + public CheckableAdapter(Class> viewHolderType) { super(viewHolderType); setCommunication(this); } diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/DividerItemDecoration.java b/adapter/src/main/java/com/android/jmaxime/adapters/DividerItemDecoration.java new file mode 100644 index 0000000..be5698b --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/adapters/DividerItemDecoration.java @@ -0,0 +1,201 @@ +package com.android.jmaxime.adapters; + + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Rect; +import android.graphics.drawable.Drawable; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +@SuppressWarnings("WeakerAccess") +public class DividerItemDecoration extends RecyclerView.ItemDecoration { + + private static final String INVALID = "invalid orientation"; + private static final int[] ATTRS = new int[]{ + android.R.attr.listDivider + }; + + public static final int LIST_HORIZONTAL = LinearLayoutManager.HORIZONTAL; + public static final int LIST_VERTICAL = LinearLayoutManager.VERTICAL; + public static final int GRID_STROKE = 3; + public static final int GRID_FILL = 4; + private static Drawable mDivider; + private int mOrientation; + + /** + * Custom constructor + * + * @param context + * @param orientation + */ + public DividerItemDecoration(final Context context, final int orientation) { + final TypedArray a = context.obtainStyledAttributes(ATTRS); + if (mDivider == null){ + mDivider = a.getDrawable(0); + } + a.recycle(); + setOrientation(orientation); + } + + /** + * Set the orientation of the underlying grid / list + * + * @param orientation must be + * {@link com.android.jmaxime.adapters.DividerItemDecoration#LIST_HORIZONTAL} + * {@link com.android.jmaxime.adapters.DividerItemDecoration#LIST_VERTICAL} + * {@link com.android.jmaxime.adapters.DividerItemDecoration#GRID_STROKE} + * {@link com.android.jmaxime.adapters.DividerItemDecoration#GRID_FILL} + */ + public void setOrientation(final int orientation) { + if (orientation != LIST_HORIZONTAL && + orientation != LIST_VERTICAL && + orientation != GRID_STROKE && + orientation != GRID_FILL) { + throw new IllegalArgumentException(INVALID); + } + mOrientation = orientation; + } + + @Override + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { + super.onDraw(c, parent, state); + if (mDivider != null) { + switch (mOrientation) { + case LIST_VERTICAL: + drawVertical(c, parent); + break; + case LIST_HORIZONTAL: + drawHorizontal(c, parent); + break; + case GRID_FILL: + drawGridFill(c, parent); + break; + case GRID_STROKE: + drawGridStroke(c, parent); + break; + default: + throw new IllegalArgumentException(INVALID); + } + } + } + + /** + * Draw vertical divider in parent + * + * @param c canvas + * @param parent recycler view + */ + public void drawVertical(final Canvas c, final RecyclerView parent) { + final int left = parent.getPaddingLeft(); + final int right = parent.getWidth() - parent.getPaddingRight(); + + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child + .getLayoutParams(); + final int top = child.getBottom() + params.bottomMargin; + final int bottom = top + mDivider.getIntrinsicHeight(); + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } + + /** + * Draw horizontal divider in parent + * + * @param c Canvas + * @param parent Recycler view + */ + public void drawHorizontal(final Canvas c, final RecyclerView parent) { + final int top = parent.getPaddingTop(); + final int bottom = parent.getHeight() - parent.getPaddingBottom(); + + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child + .getLayoutParams(); + final int left = child.getRight() + params.rightMargin; + final int right = left + mDivider.getIntrinsicHeight(); + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } + + /** + * Remove both horizontal and vertical divider in parent + * + * @param c Canvas + * @param parent Recycler view + */ + public void drawGridStroke(final Canvas c, final RecyclerView parent) { + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child + .getLayoutParams(); + final int left = child.getLeft() - params.leftMargin; + final int right = child.getRight() + params.rightMargin; + final int top = child.getTop() - params.topMargin; + final int bottom = child.getBottom() + params.bottomMargin; + mDivider.setBounds(left, top, left + mDivider.getIntrinsicHeight(), bottom); + mDivider.draw(c); + mDivider.setBounds(right - mDivider.getIntrinsicHeight(), top, right, bottom); + mDivider.draw(c); + mDivider.setBounds(left, top, right, top + mDivider.getIntrinsicHeight()); + mDivider.draw(c); + mDivider.setBounds(left, bottom - mDivider.getIntrinsicHeight(), right, bottom); + mDivider.draw(c); + mDivider.draw(c); + } + } + + /** + * Draw both horizontal and vertical divider in parent + * + * @param c Canvas + * @param parent Recler view + */ + public void drawGridFill(final Canvas c, final RecyclerView parent) { + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child + .getLayoutParams(); + final int left = child.getLeft() - params.leftMargin; + final int right = child.getRight() + params.rightMargin; + final int top = child.getTop() - params.topMargin; + final int bottom = child.getBottom() + params.bottomMargin; + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } + + @Override + public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) { + super.getItemOffsets(outRect, view, parent, state); + if (mDivider != null) { + switch (mOrientation) { + case LIST_VERTICAL: + outRect.set(0, 0, 0, mDivider.getIntrinsicHeight()); + break; + case LIST_HORIZONTAL: + outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0); + break; + case GRID_FILL: + outRect.set(mDivider.getIntrinsicWidth(), mDivider.getIntrinsicWidth(), mDivider.getIntrinsicWidth(), mDivider.getIntrinsicWidth()); + break; + case GRID_STROKE: + outRect.set(0, 0, 0, 0); + break; + default: + throw new IllegalArgumentException(INVALID); + } + } + } +} + 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 99bbe01..9601b58 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java +++ b/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java @@ -6,7 +6,7 @@ import com.android.jmaxime.factory.ViewHolderFactory; import com.android.jmaxime.interfaces.IBaseCommunication; -import com.android.jmaxime.viewholder.JRecyclerViewHolder; +import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.util.ArrayList; import java.util.List; @@ -23,21 +23,21 @@ public class EasyPagerAdapter extends PagerAdapter { private final List mItems; private final ViewHolderFactory mFactory; - public EasyPagerAdapter(Class> viewHolder) { + public EasyPagerAdapter(Class> viewHolder) { this(new ArrayList<>(), viewHolder); } - public EasyPagerAdapter(List items, Class> viewHolder) { + public EasyPagerAdapter(List items, Class> viewHolder) { this(items, viewHolder, null); } - public EasyPagerAdapter(List items, Class> viewHolder, IBaseCommunication callback) { + public EasyPagerAdapter(List items, Class> viewHolder, IBaseCommunication callback) { mItems = items; mFactory = new ViewHolderFactory<>(viewHolder, callback); } @Override public Object instantiateItem(ViewGroup container, int position) { - JRecyclerViewHolder vh = mFactory.createVH(container, 0); + RecyclerViewHolder vh = mFactory.createVH(container, 0); vh.bind(mItems.get(position)); container.addView(vh.itemView); return vh.itemView; 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 6544a11..ce2f240 100644 --- a/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java +++ b/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java @@ -9,7 +9,7 @@ import com.android.jmaxime.interfaces.IAdapterChanged; import com.android.jmaxime.interfaces.IBaseCommunication; import com.android.jmaxime.interfaces.IViewType; -import com.android.jmaxime.viewholder.JRecyclerViewHolder; +import com.android.jmaxime.viewholder.RecyclerViewHolder; import java.security.AccessControlException; import java.util.ArrayList; @@ -24,7 +24,7 @@ * Use this Class for :
* ... {DOCUMENTATION} */ -public class RecyclerAdapter extends RecyclerView.Adapter> { +public class RecyclerAdapter extends RecyclerView.Adapter> { private List mTList; private ViewHolderFactory mFactory; @@ -38,19 +38,19 @@ public RecyclerAdapter(ViewHolderFactory factory) { this(new ArrayList<>(), factory); } - public RecyclerAdapter(Class> viewHolderType) { + public RecyclerAdapter(Class> viewHolderType) { this(new ArrayList<>(), viewHolderType, null); } - public RecyclerAdapter(Class> viewHolderType, @Nullable IBaseCommunication callback) { + public RecyclerAdapter(Class> viewHolderType, @Nullable IBaseCommunication callback) { this(new ArrayList<>(), viewHolderType, callback); } - public RecyclerAdapter(List TList, Class> viewHolderType) { + public RecyclerAdapter(List TList, Class> viewHolderType) { this(TList, viewHolderType, null); } - public RecyclerAdapter(List TList, Class> viewHolderType, @Nullable IBaseCommunication callback) { + public RecyclerAdapter(List TList, Class> viewHolderType, @Nullable IBaseCommunication callback) { this(TList, new ViewHolderFactory<>(viewHolderType, callback)); } @@ -65,7 +65,7 @@ public void setFactory(ViewHolderFactory factory) { } @Override - public JRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public RecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { if (mFactory == null) { throw new AccessControlException("mFactory is not instancied. thanks use setFactory() method."); } @@ -75,7 +75,7 @@ public JRecyclerViewHolder onCreateViewHolder(ViewGroup parent, int viewType) @Override - public void onBindViewHolder(JRecyclerViewHolder holder, int position) { + public void onBindViewHolder(RecyclerViewHolder holder, int position) { holder.setItem(getItem(position)); holder.setBound(false); holder.bind(holder.getItem()); @@ -105,7 +105,7 @@ public int getItemViewType(int position) { return super.getItemViewType(position); } - public void putViewType(int viewType, Class> viewHolder){ + public void putViewType(int viewType, Class> viewHolder){ mFactory.putViewType(viewType, viewHolder); } diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.java b/adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.java new file mode 100644 index 0000000..2957ebc --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.java @@ -0,0 +1,12 @@ +package com.android.jmaxime.interfaces; + +/** + * @author Maxime Jallu + * @since 29/09/2017 + *

+ * Use this Class for :
+ * {DOCUMENTATION} + */ +public interface IAdapterChanged { + void onItemCountChange(int count); +} diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.java b/adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.java new file mode 100644 index 0000000..f15f7ec --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.java @@ -0,0 +1,13 @@ +package com.android.jmaxime.interfaces; + + +public interface IBaseCommunication { + + default void onDeleteClicked(int position, T item) { + /*nothing*/ + } + + default void onEditClicked(int position, T item) { + /*nothing*/ + } +} diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.java b/adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.java new file mode 100644 index 0000000..b20fba8 --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.java @@ -0,0 +1,12 @@ +package com.android.jmaxime.interfaces; + +/** + * @author Maxime Jallu + * @since 29/09/2017 + *

+ * Use this Class for :
+ * {DOCUMENTATION} + */ +public interface IViewType { + int getItemViewType(); +} diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/ViewCheckableCallback.java b/adapter/src/main/java/com/android/jmaxime/interfaces/ViewCheckableCallback.java new file mode 100644 index 0000000..d182bfc --- /dev/null +++ b/adapter/src/main/java/com/android/jmaxime/interfaces/ViewCheckableCallback.java @@ -0,0 +1,19 @@ +package com.android.jmaxime.interfaces; + +import android.annotation.SuppressLint; + +/** + * @author Maxime Jallu + * @since 29/09/2017 + *

+ * Use this Class for :
+ * {DOCUMENTATION} + */ +@SuppressLint("NewApi") +public interface ViewCheckableCallback extends IBaseCommunication { + boolean isChecked(T item); + default boolean isCheckable(T item) { + return true; + } + void put(String key, boolean value); +} diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java b/adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java deleted file mode 100644 index cff531d..0000000 --- a/adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java +++ /dev/null @@ -1,138 +0,0 @@ -package com.android.jmaxime.viewholder; - - -import android.annotation.SuppressLint; -import android.content.Context; -import android.graphics.drawable.Drawable; -import android.support.annotation.ColorRes; -import android.support.annotation.DrawableRes; -import android.support.annotation.PluralsRes; -import android.support.annotation.StringRes; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.RecyclerView; -import android.util.Log; -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; - -/** - * @author Maxime Jallu - * @link ArrayRecyclerAdapter - *

- * Tools this class:
- *

- * getContext() - * getColor(@ColorRes res) - * getDrawable(@DrawableRes res) - * @since 30/06/2016 - *

- * Create for CubeInStore - Android (Decathlon) - *

- * Use this Class for :
- * make it easier ViewHolder com.android.jmaxime.adapter recyclerView, define T type of item - * Must to use in ArrayRecyclerAdapter - */ -public abstract class JRecyclerViewHolder extends RecyclerView.ViewHolder { - - private T mItem; - private boolean isBound; - private IBaseCommunication mCommunication; - - /** - * This super() auto BindViews with ButterKnife
- * - * ButterKnife.bind(this, itemView); - * - * - * @param itemView the Views holder - */ - @SuppressLint("NewApi") - public JRecyclerViewHolder(View itemView) { - super(itemView); - ButterKnife.bind(this, itemView); - } - - public abstract void bind(final T item); - - protected Context getContext() { - return itemView.getContext(); - } - - protected final String getString(@StringRes int stringRes) { - return getContext().getString(stringRes); - } - - protected final String getString(@StringRes int stringRes, String string) { - return getContext().getResources().getString(stringRes, string); - } - - protected final String getQuantityString(@PluralsRes int pluralRes, int quantity) { - return getContext().getResources().getQuantityString(pluralRes, quantity, quantity); - } - - protected final String getQuantityStringFormat(@PluralsRes int pluralRes, int quantity) { - return getContext().getResources().getQuantityString(pluralRes, quantity, quantity); - } - - protected final int getColor(@ColorRes int colorResId) { - return ContextCompat.getColor(getContext(), colorResId); - } - - protected final Drawable getDrawable(@DrawableRes int drawableResId) { - return ContextCompat.getDrawable(getContext(), 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); - } - - protected boolean isBound() { - return isBound; - } - - public void setBound(boolean bound) { - isBound = bound; - } - - public T getItem() { - return mItem; - } - - public void setItem(T item) { - mItem = item; - } - - protected final void onClickRemoveItem() { - getDispatcher().onDeleteClicked(getAdapterPosition(), getItem()); - } - - protected final void onClickEditItem() { - getDispatcher().onEditClicked(getAdapterPosition(), getItem()); - } - - protected > I getDispatcher() { - I i = null; - try { - //noinspection unchecked - i = (I) mCommunication; - } catch (ClassCastException e) { - Log.e("ViewHolderFactory", "getInterfaceCallback: ", e); - } - return i; - } - - public void setCommunication(IBaseCommunication interfaceCallback) { - mCommunication = interfaceCallback; - } -} diff --git a/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt deleted file mode 100644 index 3fa5dbe..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt +++ /dev/null @@ -1,89 +0,0 @@ -package com.android.jmaxime.adapter - -import android.content.Context -import android.content.res.TypedArray -import android.graphics.Canvas -import android.graphics.Rect -import android.graphics.drawable.Drawable -import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView -import android.view.View - - -class DividerItemDecoration(context: Context, orientation: Int) : RecyclerView.ItemDecoration() { - - private val mDivider: Drawable? - - private var mOrientation: Int = 0 - - init { - val a = context.obtainStyledAttributes(ATTRS) - mDivider = a.getDrawable(0) - a.recycle() - setOrientation(orientation) - } - - fun setOrientation(orientation: Int) { - if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) { - throw IllegalArgumentException("invalid orientation") - } - mOrientation = orientation - } - - override fun onDraw(c: Canvas?, parent: RecyclerView?) { - if (mOrientation == VERTICAL_LIST) { - drawVertical(c, parent) - } else { - drawHorizontal(c, parent) - } - } - - fun drawVertical(c: Canvas?, parent: RecyclerView?) { - val left = parent!!.paddingLeft - val right = parent.width - parent.paddingRight - - val childCount = parent.childCount - for (i in 0..childCount - 1) { - val child = parent.getChildAt(i) - val params = child - .layoutParams as RecyclerView.LayoutParams - val top = child.bottom + params.bottomMargin - val bottom = top + mDivider!!.intrinsicHeight - mDivider.setBounds(left, top, right, bottom) - mDivider.draw(c!!) - } - } - - fun drawHorizontal(c: Canvas?, parent: RecyclerView?) { - val top = parent!!.paddingTop - val bottom = parent.height - parent.paddingBottom - - val childCount = parent.childCount - for (i in 0..childCount - 1) { - val child = parent.getChildAt(i) - val params = child - .layoutParams as RecyclerView.LayoutParams - val left = child.right + params.rightMargin - val right = left + mDivider!!.intrinsicHeight - mDivider.setBounds(left, top, right, bottom) - mDivider.draw(c!!) - } - } - - override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State?) { - if (mOrientation == VERTICAL_LIST) { - outRect.set(0, 0, 0, mDivider!!.intrinsicHeight) - } else { - outRect.set(0, 0, mDivider!!.intrinsicWidth, 0) - } - } - - companion object { - - private val ATTRS = intArrayOf(android.R.attr.listDivider) - - val HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL - - val VERTICAL_LIST = LinearLayoutManager.VERTICAL - } -} diff --git a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IAdapterChanged.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IAdapterChanged.kt deleted file mode 100644 index fd447d7..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IAdapterChanged.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.android.jmaxime.interfaces - -/** - * @author Maxime Jallu - * @since 13/09/2017 - * - * Use this Class for :
- * {DOCUMENTATION} - */ -interface IAdapterChanged { - fun onItemCountChange(count: Int) -} \ No newline at end of file diff --git a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IBaseCommunication.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IBaseCommunication.kt deleted file mode 100644 index fa70d10..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IBaseCommunication.kt +++ /dev/null @@ -1,18 +0,0 @@ -package com.android.jmaxime.interfaces - -/** - * @author Maxime Jallu - * @since 10/05/2017 - * Use this Class for :

- * ... {DOCUMENTATION} - */ -interface IBaseCommunication { - - fun onDeleteClicked(position: Int, item : T) { - /*nothing*/ - } - - fun onEditClicked(position: Int, item: T) { - /*nothing*/ - } -} diff --git a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IViewType.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IViewType.kt deleted file mode 100644 index 6847bc0..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IViewType.kt +++ /dev/null @@ -1,12 +0,0 @@ -package com.android.jmaxime.interfaces - -/** - * @author Maxime Jallu - * @since 13/09/2017 - * - * Use this Class for :
- * {DOCUMENTATION} - */ -interface IViewType { - fun getItemViewType(): Int -} \ No newline at end of file diff --git a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt deleted file mode 100644 index 2c699bd..0000000 --- a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt +++ /dev/null @@ -1,19 +0,0 @@ -package com.android.jmaxime.interfaces - -import android.annotation.SuppressLint - -/** - * @author Maxime Jallu - * @since 26/09/2017 - * - * Use this Class for :
- * {DOCUMENTATION} - */ -interface ViewCheckableCallback : IBaseCommunication { - abstract fun isChecked(item: T): Boolean - @SuppressLint("NewApi") - fun isCheckable(item: T): Boolean { - return true - } - fun put(key: String, value: Boolean) -} \ No newline at end of file