Skip to content

Commit

Permalink
Fixed divider
Browse files Browse the repository at this point in the history
Fixed swipeMenu
  • Loading branch information
AndroidLiba committed Mar 3, 2019
1 parent 08ac4ca commit 1c1ea76
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 83 deletions.
29 changes: 29 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public ViewHolder(ViewGroup parent) {
bubbleChartButton = findViewById(R.id.imagebutton_bubble);
bubbleChartButton.setOnClickListener(this);

contentView.setOnLongClickListener(new View.OnLongClickListener() {
contentView.setOnClickListener(new View.OnClickListener() {
@Override
public boolean onLongClick(View v) {
smoothOpenBeginMenu();
return true;
public void onClick(View v) {
smoothOpenLeftMenu();
// return true;
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,4 @@ public boolean isAttachedScrap() {

}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ protected StickyHeaderDecoration provideStickyHeaderDecoration(@Nullable StickyH
return new BaseStickyHeaderDecoration(adapter);
}


@Override
public void addView(View view, int index, ViewGroup.LayoutParams params) {
if (mFinishedInflate) {
Expand Down Expand Up @@ -400,6 +401,15 @@ public View transformTouchView(int touchPosition, View touchView) {
return touchView;
}

public void setDividerAlpha(float dividerAlpha) {
for (int i = 0; i < getItemDecorationCount(); i++) {
RecyclerView.ItemDecoration itemDecoration = getItemDecorationAt(i);
if (itemDecoration instanceof DividerItemDecoration) {
((DividerItemDecoration) itemDecoration).setDividerAlpha(dividerAlpha);
}
}
}

public void setPaginationCallback(OnPageRequestListener callback) {
RecyclerView.Adapter adapter = getAdapter();
if (adapter instanceof HeaderFooterWrapperAdapter) {
Expand Down Expand Up @@ -539,7 +549,11 @@ public abstract static class Adapter<VH extends RecyclerView.ViewHolder> extends

private RecyclerView recyclerView;

public boolean isShowDivided(int position) {
public boolean isDividerAllowedAbove(int position) {
return true;
}

public boolean isDividerAllowedBelow(int position) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,24 @@ public int getItemCount() {
}

@Override
public boolean isShowDivided(int position) {
public boolean isDividerAllowedAbove(int position) {
SparseArray<View> sectionArray = null;
if (isHeaderPosition(position)) sectionArray = mHeaderArray;
if (isFooterPosition(position)) sectionArray = mFooterArray;

if (sectionArray != null) {
return true;
}

if (mRealAdapter instanceof OmegaRecyclerView.Adapter) {
return ((OmegaRecyclerView.Adapter) mRealAdapter).isDividerAllowedAbove(position - mHeaderArray.size());
}

return super.isDividerAllowedAbove(position);
}

@Override
public boolean isDividerAllowedBelow(int position) {
SparseArray<View> sectionArray = null;
if (isHeaderPosition(position)) sectionArray = mHeaderArray;
if (isFooterPosition(position)) sectionArray = mFooterArray;
Expand All @@ -80,14 +97,14 @@ public boolean isShowDivided(int position) {
if (tag instanceof Boolean) {
return (boolean) tag;
}
return super.isShowDivided(position);
return super.isDividerAllowedBelow(position);
}

if (mRealAdapter instanceof OmegaRecyclerView.Adapter) {
return ((OmegaRecyclerView.Adapter) mRealAdapter).isShowDivided(position - mHeaderArray.size());
return ((OmegaRecyclerView.Adapter) mRealAdapter).isDividerAllowedBelow(position - mHeaderArray.size());
}

return super.isShowDivided(position);
return super.isDividerAllowedBelow(position);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
import com.omega_r.libs.omegarecyclerview.item_decoration.decoration_helpers.DividerDecorationHelper;

public class DividerItemDecoration extends BaseItemDecoration {

private final Drawable mDivider;
private final int mOffset;
private final float mDividerAlpha;

private float mDividerAlpha;
private Drawable mDivider;
private int mDividerSize;
private int mPaddingStart;
private int mPaddingEnd;
Expand Down Expand Up @@ -49,6 +49,14 @@ public void setPaddingEnd(int padding) {
mPaddingEnd = padding;
}

public void setDividerAlpha(float dividerAlpha) {
this.mDividerAlpha = dividerAlpha;
}

public void setDividerDrawable(@NonNull Drawable dividerDrawable) {
mDivider = dividerDrawable;
}

private void updateSize() {
if (mDividerSize < 0) {
switch (getOrientation()) {
Expand All @@ -63,7 +71,7 @@ private void updateSize() {
}

@Override
void getItemOffset(@NonNull Rect outRect, @NonNull RecyclerView parent, @NonNull DividerDecorationHelper helper, int position, int itemCount) {
public void getItemOffset(@NonNull Rect outRect, @NonNull RecyclerView parent, @NonNull DividerDecorationHelper helper, int position, int itemCount) {
if (position == 0 && isShowBeginDivider()) {
helper.setStart(outRect, mDividerSize);
}
Expand All @@ -86,20 +94,35 @@ public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull
final int childCount = parent.getChildCount();

if (childCount > 0) {
c.save();
DividerDecorationHelper helper = DividerDecorationHelper.getHelper(getOrientation(), parent);

mItemRect.set(parent.getPaddingLeft() + mPaddingStart,
parent.getPaddingTop() + mPaddingStart,
parent.getWidth() - parent.getPaddingRight() - mPaddingEnd,
parent.getHeight() - parent.getPaddingBottom() - mPaddingEnd);

if (parent.getClipToPadding()) {
mItemRect.set(parent.getPaddingLeft() + mPaddingStart,
parent.getPaddingTop() + mPaddingStart,
parent.getWidth() - parent.getPaddingRight() - mPaddingEnd,
parent.getHeight() - parent.getPaddingBottom() - mPaddingEnd);


helper.setStart(mItemRect, helper.getStart(mItemRect) - mPaddingStart);
helper.setEnd(mItemRect, helper.getEnd(mItemRect) + mPaddingEnd);
c.clipRect(mItemRect);

} else {
mItemRect.set(mPaddingStart, mPaddingStart,
parent.getWidth() - mPaddingEnd, parent.getHeight() - mPaddingEnd);
}
View child;

int offsetIndex = 0;

// show beginning divider
if (isShowBeginDivider()) {
child = parent.getChildAt(0);
if (isShowDivider(parent, getAdapterPosition(parent, child))) {
updateViewRect(child);
int adapterPosition = getAdapterPosition(parent, child);
if (adapterPosition == 0 && isShowDividerAbove(parent, 0)) {
offsetIndex = 1;
updateViewRect(parent, child);
helper.setStart(mItemRect, helper.getStart(mViewRect) - helper.getOffset(mOffset));
helper.setEnd(mItemRect, helper.getStart(mItemRect) - helper.getOffset(mDividerSize));
drawDivider(c, child, mItemRect);
Expand All @@ -108,10 +131,10 @@ public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull

// show middle dividers
if (isShowMiddleDivider()) {
for (int i = 1; i < childCount; i++) {
for (int i = offsetIndex; i < childCount; i++) {
child = parent.getChildAt(i);
if (isShowDivider(parent, getAdapterPosition(parent, child))) {
updateViewRect(child);
if (isShowDividerAbove(parent, getAdapterPosition(parent, child))) {
updateViewRect(parent, child);
helper.setStart(mItemRect, helper.getStart(mViewRect) - helper.getOffset(mOffset));
helper.setEnd(mItemRect, helper.getStart(mItemRect) - helper.getOffset(mDividerSize));
drawDivider(c, child, mItemRect);
Expand All @@ -122,17 +145,21 @@ public void onDrawOver(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull
// show end divider
if (isShowEndDivider()) {
child = parent.getChildAt(childCount - 1);
if (isShowDivider(parent, childCount - 1)) {
updateViewRect(child);
int adapterPosition = getAdapterPosition(parent, child);
int adapterCount = parent.getAdapter().getItemCount();
if (adapterPosition == adapterCount - 1 && isShowDividerBelow(parent, adapterPosition, adapterCount)) {
updateViewRect(parent, child);
helper.setStart(mItemRect, helper.getEnd(mViewRect) + helper.getOffset(mOffset));
helper.setEnd(mItemRect, helper.getStart(mItemRect) + helper.getOffset(mDividerSize));
drawDivider(c, child, mItemRect);
}
}

c.restore();
}
}

private void updateViewRect(View view) {
private void updateViewRect(RecyclerView parent, View view) {
view.getHitRect(mViewRect);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
mViewRect.left -= params.leftMargin;
Expand All @@ -149,10 +176,31 @@ private void drawDivider(Canvas canvas, View view, Rect rect) {
divider.draw(canvas);
}

private boolean isShowDivider(RecyclerView parent, int index) {
private boolean isShowDividerBelow(RecyclerView parent, int adapterPosition, int count) {
RecyclerView.Adapter adapter = parent.getAdapter();
if (adapter instanceof OmegaRecyclerView.Adapter) {
boolean allowedBelow = ((OmegaRecyclerView.Adapter) adapter).isDividerAllowedBelow(adapterPosition);
if (allowedBelow) {
return (adapterPosition + 1 == count)
|| ((OmegaRecyclerView.Adapter) adapter).isDividerAllowedAbove(adapterPosition + 1);

} else {
return false;
}
}
return true;
}

private boolean isShowDividerAbove(RecyclerView parent, int adapterPosition) {
RecyclerView.Adapter adapter = parent.getAdapter();
if (adapter instanceof OmegaRecyclerView.Adapter) {
return ((OmegaRecyclerView.Adapter) adapter).isShowDivided(index);
OmegaRecyclerView.Adapter omegaAdapter = (OmegaRecyclerView.Adapter) adapter;
boolean allowedBelow = adapterPosition == 0 || omegaAdapter.isDividerAllowedBelow(adapterPosition - 1);
if (allowedBelow) {
return omegaAdapter.isDividerAllowedAbove(adapterPosition);
} else {
return false;
}
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ public long getItemId(int position) {
return super.getItemId(position);
}

@Override
public boolean isDividerAllowedAbove(int position) {
if (position == super.getItemCount()) {
return position != 0;
}
return super.isDividerAllowedAbove(position);
}

@Override
public boolean isDividerAllowedBelow(int position) {
if (position == super.getItemCount()) {
return false;
}
return super.isDividerAllowedBelow(position);
}

@Override
public int getItemViewType(int position) {
if (mShowPagination != null && position == super.getItemCount()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ public void onAttachedToRecyclerView(RecyclerView recyclerView) {
mChildAdapter.onAttachedToRecyclerView(recyclerView);
}

@Override
public boolean isDividerAllowedAbove(int position) {
if (mChildAdapter instanceof OmegaRecyclerView.Adapter) {
return ((OmegaRecyclerView.Adapter) mChildAdapter).isDividerAllowedAbove(position);
}
return super.isDividerAllowedBelow(position);
}

@Override
public boolean isDividerAllowedBelow(int position) {
if (mChildAdapter instanceof OmegaRecyclerView.Adapter) {
return ((OmegaRecyclerView.Adapter) mChildAdapter).isDividerAllowedBelow(position);
}
return super.isDividerAllowedBelow(position);
}

@Override
public void onDetachedFromRecyclerView(RecyclerView recyclerView) {
mChildAdapter.onDetachedFromRecyclerView(recyclerView);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.omega_r.libs.omegarecyclerview.swipe_menu;

/**
* Created by Anton Knyazev on 03.03.2019.
*/
public enum SwipeDirection {

LEFT, RIGHT

}
Loading

0 comments on commit 1c1ea76

Please sign in to comment.