Skip to content

Commit

Permalink
feat(adapter): add kotlin adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxime Jallu committed Sep 29, 2017
1 parent 078c705 commit 19c950c
Show file tree
Hide file tree
Showing 10 changed files with 521 additions and 370 deletions.
4 changes: 2 additions & 2 deletions adapter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
Original file line number Diff line number Diff line change
@@ -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 : <br/>
* Crée un adapteur de recycler view de base
* @param <T> Type d'item de la liste
* @param <U> Type de ViewHolder doit extends de RecyclerViewHolder
*/
public abstract class ArrayRecyclerAdapter<T, U extends RecyclerViewHolder<T>> extends RecyclerView.Adapter<U> {

private List<T> mTList;

/**
* Constructor
* @param TList list items for binding views
*/
public ArrayRecyclerAdapter(@NonNull final List<T> 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<T> list){
mTList = list;
notifyDataSetChanged();
}

/**
*
* @return instance items list
*/
public List<T> getTList() {
return mTList;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 : <br></br>
* ... {DOCUMENTATION}
*/

class DividerItemDecoration(context: Context, orientation: Int) : RecyclerView.ItemDecoration() {

private val mDivider: Drawable?
Expand Down
Loading

0 comments on commit 19c950c

Please sign in to comment.