diff --git a/adapter/build.gradle b/adapter/build.gradle
index 370bf52..6411b5e 100644
--- a/adapter/build.gradle
+++ b/adapter/build.gradle
@@ -5,7 +5,7 @@ buildscript {
}
dependencies {
- classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.4-3"
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.1.50"
classpath 'me.tatarka:gradle-retrolambda:3.7.0'
}
}
@@ -16,10 +16,11 @@ apply plugin: 'kotlin-android'
android {
compileSdkVersion 26
- buildToolsVersion "26.0.0"
+ buildToolsVersion "26.0.1"
defaultConfig {
+// applicationId "com.android.jmaxime.com.android.jmaxime.adapter"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
@@ -37,24 +38,30 @@ android {
}
compileOptions {
- targetCompatibility 1.8
- sourceCompatibility 1.8
+ sourceCompatibility JavaVersion.VERSION_1_8
+ targetCompatibility JavaVersion.VERSION_1_8
+ }
+
+ sourceSets {
+ main.java.srcDirs += 'src/main/kotlin'
}
}
+def androidSupport = '26.1.0'
+
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
- implementation 'com.android.support:appcompat-v7:26.0.2'
+// implementation "com.android.support:appcompat-v7:$androidSupport"
testImplementation 'junit:junit:4.12'
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
exclude group: 'com.android.support', module: 'support-annotations'
})
- compile "org.jetbrains.kotlin:kotlin-stdlib:1.1.4-3"
- compile "com.android.support:appcompat-v7:26.0.2"
- compile "com.android.support:design:26.0.2"
+ 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.0.2'
- compile 'com.jakewharton:butterknife:8.4.0'
- annotationProcessor 'com.jakewharton:butterknife-compiler:8.4.0'
+ compile 'com.squareup.retrofit2:adapter-rxjava:2.3.0'
+ compile 'com.jakewharton:butterknife:8.8.1'
+ annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
}
diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java
new file mode 100644
index 0000000..d043e60
--- /dev/null
+++ b/adapter/src/main/java/com/android/jmaxime/adapters/CheckableAdapter.java
@@ -0,0 +1,52 @@
+package com.android.jmaxime.adapters;
+
+import com.android.jmaxime.factory.ViewHolderFactory;
+import com.android.jmaxime.interfaces.ViewCheckableCallback;
+import com.android.jmaxime.viewholder.JRecyclerViewHolder;
+
+import java.util.HashMap;
+import java.util.List;
+
+/**
+ * @author Maxime Jallu
+ * @since 26/09/2017
+ *
+ * Use this Class for :
+ * {DOCUMENTATION}
+ */
+public class CheckableAdapter extends RecyclerAdapter implements ViewCheckableCallback {
+
+ private HashMap mCheckedMap = new HashMap<>();
+
+ public CheckableAdapter(Class extends JRecyclerViewHolder> viewHolderType) {
+ super(viewHolderType);
+ setCommunication(this);
+ }
+
+ public CheckableAdapter(List TList, ViewHolderFactory factory) {
+ super(TList, factory);
+ setCommunication(this);
+ }
+
+ /**
+ * Clear map and add item to selected
+ * add selected position to sparseArray
+ *
+ * @param position
+ */
+ public void setSelected(int position) {
+ /*si plusieurs cellules sont checked alors on fera un notify complet*/
+ mCheckedMap.clear();
+ put(String.valueOf(getItem(position).hashCode()), true);
+ notifyDataSetChanged();
+ }
+
+ @Override public boolean isChecked(T item) {
+ String hashString = String.valueOf(item.hashCode());
+ return mCheckedMap.containsKey(hashString) ? mCheckedMap.get(hashString) : false;
+ }
+
+ @Override public void put(String key, boolean value) {
+ mCheckedMap.put(key, value);
+ }
+}
diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java
new file mode 100644
index 0000000..99bbe01
--- /dev/null
+++ b/adapter/src/main/java/com/android/jmaxime/adapters/EasyPagerAdapter.java
@@ -0,0 +1,64 @@
+package com.android.jmaxime.adapters;
+
+import android.support.v4.view.PagerAdapter;
+import android.view.View;
+import android.view.ViewGroup;
+
+import com.android.jmaxime.factory.ViewHolderFactory;
+import com.android.jmaxime.interfaces.IBaseCommunication;
+import com.android.jmaxime.viewholder.JRecyclerViewHolder;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Maxime Jallu
+ * @since 26/09/2017
+ *
+ * Use this Class for :
+ * {DOCUMENTATION}
+ */
+public class EasyPagerAdapter extends PagerAdapter {
+
+ private final List mItems;
+ private final ViewHolderFactory mFactory;
+
+ public EasyPagerAdapter(Class extends JRecyclerViewHolder> viewHolder) {
+ this(new ArrayList<>(), viewHolder);
+ }
+
+ public EasyPagerAdapter(List items, Class extends JRecyclerViewHolder> viewHolder) {
+ this(items, viewHolder, null);
+ }
+
+ public EasyPagerAdapter(List items, Class extends JRecyclerViewHolder> viewHolder, IBaseCommunication callback) {
+ mItems = items;
+ mFactory = new ViewHolderFactory<>(viewHolder, callback);
+ }
+
+ @Override public Object instantiateItem(ViewGroup container, int position) {
+ JRecyclerViewHolder vh = mFactory.createVH(container, 0);
+ vh.bind(mItems.get(position));
+ container.addView(vh.itemView);
+ return vh.itemView;
+ }
+
+ @Override
+ public boolean isViewFromObject(View view, Object object) {
+ return view == object;
+ }
+
+ @Override public int getCount() {
+ return mItems.size();
+ }
+
+ @Override
+ public void destroyItem(ViewGroup container, int position, Object object) {
+ container.removeView((View) object);
+ }
+
+ public void addAll(List medias) {
+ mItems.addAll(medias);
+ notifyDataSetChanged();
+ }
+}
\ No newline at end of file
diff --git a/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java b/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java
new file mode 100644
index 0000000..6544a11
--- /dev/null
+++ b/adapter/src/main/java/com/android/jmaxime/adapters/RecyclerAdapter.java
@@ -0,0 +1,217 @@
+package com.android.jmaxime.adapters;
+
+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.JRecyclerViewHolder;
+
+import java.security.AccessControlException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Maxime Jallu
+ * @since 03/05/2017
+ *
+ * Create for CubeInStore - Android (Decathlon)
+ *
+ * Use this Class for :
+ * ... {DOCUMENTATION}
+ */
+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 extends JRecyclerViewHolder> viewHolderType) {
+ this(new ArrayList<>(), viewHolderType, null);
+ }
+
+ public RecyclerAdapter(Class extends JRecyclerViewHolder> viewHolderType, @Nullable IBaseCommunication callback) {
+ this(new ArrayList<>(), viewHolderType, callback);
+ }
+
+ public RecyclerAdapter(List TList, Class extends JRecyclerViewHolder> viewHolderType) {
+ this(TList, viewHolderType, null);
+ }
+
+ public RecyclerAdapter(List TList, Class extends JRecyclerViewHolder> 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 JRecyclerViewHolder 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(JRecyclerViewHolder 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 extends JRecyclerViewHolder> 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 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 493adfa..5dab18b 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.viewholder.JRecyclerViewHolder;
import com.android.jmaxime.annotations.BindLayoutRes;
import com.android.jmaxime.interfaces.IBaseCommunication;
import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
/**
* @author Maxime Jallu
@@ -23,21 +25,27 @@ public class ViewHolderFactory {
private static final String TAG = ViewHolderFactory.class.getName();
private WeakReference mCommunication;
- private Class extends RecyclerViewHolder> mViewHolderType;
- private HashMap>> mClassHashMap;
+ private Class extends JRecyclerViewHolder> mViewHolderType;
+ private SparseArray>> mClassHashMap;
public ViewHolderFactory() {
this(null);
}
@SuppressLint("UseSparseArrays")
- public ViewHolderFactory(Class extends RecyclerViewHolder> viewHolderType) {
+ public ViewHolderFactory(Class extends JRecyclerViewHolder> viewHolderType) {
+ this(viewHolderType, null);
+ }
+
+ public ViewHolderFactory(Class extends JRecyclerViewHolder> 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 JRecyclerViewHolder createVH(ViewGroup view, int viewType) {
+ JRecyclerViewHolder ret = getInstance(LayoutInflater.from(view.getContext())
+ .inflate(getLayoutRes(viewType), view, false), viewType);
if (ret != null) {
ret.setCommunication(getInterfaceCallback());
}
@@ -45,8 +53,8 @@ public final RecyclerViewHolder createVH(View view, int viewType) {
}
@SuppressWarnings("TryWithIdenticalCatches")
- private RecyclerViewHolder getInstance(View view, int viewType) {
- RecyclerViewHolder ret = null;
+ private JRecyclerViewHolder getInstance(View view, int viewType) {
+ JRecyclerViewHolder ret = null;
try {
ret = getViewHolderType(viewType).getConstructor(View.class).newInstance(view);
} catch (InstantiationException e) {
@@ -72,9 +80,9 @@ protected I getInterfaceCallback() {
return i;
}
- protected Class extends RecyclerViewHolder> getViewHolderType(int viewType) {
- Class extends RecyclerViewHolder> vm = mViewHolderType;
- if (mClassHashMap.containsKey(viewType)) {
+ protected Class extends JRecyclerViewHolder> getViewHolderType(int viewType) {
+ Class extends JRecyclerViewHolder> vm = mViewHolderType;
+ if (mClassHashMap.indexOfKey(viewType) > -1) {
vm = mClassHashMap.get(viewType);
}
return vm;
@@ -92,7 +100,7 @@ public void setCommunication(IBaseCommunication communication) {
return getViewHolderType(viewType).getAnnotation(BindLayoutRes.class).value();
}
- public void putViewType(int viewType, Class extends RecyclerViewHolder> viewHolder){
+ public void putViewType(int viewType, Class extends JRecyclerViewHolder> viewHolder){
mClassHashMap.put(viewType, viewHolder);
}
}
diff --git a/adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java b/adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java
new file mode 100644
index 0000000..cff531d
--- /dev/null
+++ b/adapter/src/main/java/com/android/jmaxime/viewholder/JRecyclerViewHolder.java
@@ -0,0 +1,138 @@
+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/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt b/adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt
similarity index 93%
rename from adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt
rename to adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt
index f42eeb6..03c30d8 100644
--- a/adapter/src/main/java/com/android/jmaxime/viewholder/RecyclerViewHolder.kt
+++ b/adapter/src/main/java/com/android/jmaxime/viewholder/KRecyclerViewHolder.kt
@@ -27,10 +27,10 @@ import com.squareup.picasso.Picasso
* * Create for CubeInStore - Android (Decathlon)
* *
* * Use this Class for :
- * * make it easier ViewHolder adapter recyclerView, define T type of item
+ * * make it easier ViewHolder com.android.jmaxime.adapter recyclerView, define T type of item
* * Must to use in RecyclerAdapter
*/
-abstract class RecyclerViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {
+abstract class KRecyclerViewHolder constructor(itemView: View) : RecyclerView.ViewHolder(itemView) {
var item: T? = null
var isBound: Boolean = false
diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt
similarity index 90%
rename from adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt
rename to adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt
index 73be873..2455df2 100644
--- a/adapter/src/main/java/com/android/jmaxime/adapter/ArrayRecyclerAdapter.kt
+++ b/adapter/src/main/kotlin/com/android/jmaxime/adapters/ArrayRecyclerAdapter.kt
@@ -13,7 +13,7 @@ import android.support.v7.widget.RecyclerView
* @param Type d'item de la liste
* @param Type de ViewHolder doit extends de RecyclerViewHolder
**/
-abstract class ArrayRecyclerAdapter>(TList: List) : RecyclerView.Adapter() {
+abstract class ArrayRecyclerAdapter>(TList: List) : RecyclerView.Adapter() {
var tList: List? = null
private set
diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/DividerItemDecoration.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt
similarity index 100%
rename from adapter/src/main/java/com/android/jmaxime/adapter/DividerItemDecoration.kt
rename to adapter/src/main/kotlin/com/android/jmaxime/adapters/DividerItemDecoration.kt
diff --git a/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt b/adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt
similarity index 85%
rename from adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt
rename to adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt
index 345195c..403e274 100644
--- a/adapter/src/main/java/com/android/jmaxime/adapter/RecyclerAdapter.kt
+++ b/adapter/src/main/kotlin/com/android/jmaxime/adapters/RecyclerAdapter.kt
@@ -1,16 +1,13 @@
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
+import java.util.*
/**
* @author Maxime Jallu
@@ -18,7 +15,7 @@ import java.util.ArrayList
* Use this Class for :
* ... {DOCUMENTATION}
*/
-class RecyclerAdapter : RecyclerView.Adapter> {
+class RecyclerAdapter : RecyclerView.Adapter> {
private var mTList: MutableList? = null
private var mFactory: ViewHolderFactory? = null
@@ -30,11 +27,11 @@ class RecyclerAdapter : RecyclerView.Adapter> {
constructor(factory: ViewHolderFactory) : this(ArrayList(), factory, null) {}
- constructor(viewHolderType: Class>) : this(ArrayList(), viewHolderType, null) {}
+ constructor(viewHolderType: Class>) : this(ArrayList(), viewHolderType, null) {}
- constructor(viewHolderType: Class>, callback: IBaseCommunication?) : this(ArrayList(), viewHolderType, callback) {}
+ constructor(viewHolderType: Class>, callback: IBaseCommunication?) : this(ArrayList(), viewHolderType, callback) {}
- @JvmOverloads constructor(TList: MutableList, viewHolderType: Class>, callback: IBaseCommunication? = null) : this(TList, ViewHolderFactory(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
@@ -46,18 +43,16 @@ class RecyclerAdapter : RecyclerView.Adapter> {
mFactory = factory
}
- override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerViewHolder? {
+ override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): KRecyclerViewHolder? {
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)
+ return mFactory!!.createVH(parent, viewType)
}
- override fun onBindViewHolder(holder: RecyclerViewHolder, position: Int) {
+ override fun onBindViewHolder(holder: KRecyclerViewHolder, position: Int) {
holder.item = getItem(position)
holder.isBound = false
holder.bind(holder.item!!)
@@ -84,7 +79,7 @@ class RecyclerAdapter : RecyclerView.Adapter> {
} else super.getItemViewType(position)
}
- fun putViewType(viewType: Int, viewHolder: Class>) {
+ fun putViewType(viewType: Int, viewHolder: Class>) {
mFactory!!.putViewType(viewType, viewHolder)
}
diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IAdapterChanged.kt
similarity index 100%
rename from adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.kt
rename to adapter/src/main/kotlin/com/android/jmaxime/interfaces/IAdapterChanged.kt
diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IBaseCommunication.kt
similarity index 100%
rename from adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.kt
rename to adapter/src/main/kotlin/com/android/jmaxime/interfaces/IBaseCommunication.kt
diff --git a/adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/IViewType.kt
similarity index 100%
rename from adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.kt
rename to adapter/src/main/kotlin/com/android/jmaxime/interfaces/IViewType.kt
diff --git a/adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt
new file mode 100644
index 0000000..2c699bd
--- /dev/null
+++ b/adapter/src/main/kotlin/com/android/jmaxime/interfaces/ViewCheckableCallback.kt
@@ -0,0 +1,19 @@
+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
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 0000000..933366e
Binary files /dev/null and b/adapter/src/main/res/drawable/no_image.png differ