-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maxime Jallu
committed
Sep 29, 2017
1 parent
4ab328a
commit 1050159
Showing
14 changed files
with
273 additions
and
304 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
201 changes: 201 additions & 0 deletions
201
adapter/src/main/java/com/android/jmaxime/adapters/DividerItemDecoration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
adapter/src/main/java/com/android/jmaxime/interfaces/IAdapterChanged.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.android.jmaxime.interfaces; | ||
|
||
/** | ||
* @author Maxime Jallu | ||
* @since 29/09/2017 | ||
* <p> | ||
* Use this Class for : <br/> | ||
* {DOCUMENTATION} | ||
*/ | ||
public interface IAdapterChanged { | ||
void onItemCountChange(int count); | ||
} |
13 changes: 13 additions & 0 deletions
13
adapter/src/main/java/com/android/jmaxime/interfaces/IBaseCommunication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.android.jmaxime.interfaces; | ||
|
||
|
||
public interface IBaseCommunication<T> { | ||
|
||
default void onDeleteClicked(int position, T item) { | ||
/*nothing*/ | ||
} | ||
|
||
default void onEditClicked(int position, T item) { | ||
/*nothing*/ | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
adapter/src/main/java/com/android/jmaxime/interfaces/IViewType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.android.jmaxime.interfaces; | ||
|
||
/** | ||
* @author Maxime Jallu | ||
* @since 29/09/2017 | ||
* <p> | ||
* Use this Class for : <br/> | ||
* {DOCUMENTATION} | ||
*/ | ||
public interface IViewType { | ||
int getItemViewType(); | ||
} |
19 changes: 19 additions & 0 deletions
19
adapter/src/main/java/com/android/jmaxime/interfaces/ViewCheckableCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.android.jmaxime.interfaces; | ||
|
||
import android.annotation.SuppressLint; | ||
|
||
/** | ||
* @author Maxime Jallu | ||
* @since 29/09/2017 | ||
* <p> | ||
* Use this Class for : <br/> | ||
* {DOCUMENTATION} | ||
*/ | ||
@SuppressLint("NewApi") | ||
public interface ViewCheckableCallback<T> extends IBaseCommunication<T> { | ||
boolean isChecked(T item); | ||
default boolean isCheckable(T item) { | ||
return true; | ||
} | ||
void put(String key, boolean value); | ||
} |
Oops, something went wrong.