Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix conflict of RecyclerView's and ViewPager's lifecycles #44

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,68 @@ public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder.getItemViewType() == VIEW_TYPE_NUMBER) {
NumberViewHolder vh1 = (NumberViewHolder) holder;
configureNumberButtonHolder(vh1, position);
bindNumberViewHolder(vh1);
} else if (holder.getItemViewType() == VIEW_TYPE_DELETE) {
DeleteViewHolder vh2 = (DeleteViewHolder) holder;
configureDeleteButtonHolder(vh2);
bindDeleteViewHolder(vh2);
}
}

private void bindNumberViewHolder(NumberViewHolder holder){
holder.getNumberButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnNumberClickListener != null) {
mOnNumberClickListener.onNumberClicked((Integer) v.getTag());
}
}
});
}

private void bindDeleteViewHolder(final DeleteViewHolder holder) {
if (mCustomizationOptionsBundle.isShowDeleteButton() && mPinLength > 0) {
holder.getDeleteButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnDeleteClickListener != null) {
mOnDeleteClickListener.onDeleteClicked();
}
}
});

holder.getDeleteButton().setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (mOnDeleteClickListener != null) {
mOnDeleteClickListener.onDeleteLongClicked();
}
return true;
}
});

holder.getDeleteButton().setOnTouchListener(new View.OnTouchListener() {
private Rect rect;

@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
holder.getButtonImage().setColorFilter(mCustomizationOptionsBundle
.getDeleteButtonPressesColor());
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
if (event.getAction() == MotionEvent.ACTION_UP) {
holder.getButtonImage().clearColorFilter();
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (!rect.contains(v.getLeft() + (int) event.getX(),
v.getTop() + (int) event.getY())) {
holder.getButtonImage().clearColorFilter();
}
}
return false;
}
});
}
}

Expand Down Expand Up @@ -184,14 +243,10 @@ public class NumberViewHolder extends RecyclerView.ViewHolder {
public NumberViewHolder(final View itemView) {
super(itemView);
mNumberButton = (Button) itemView.findViewById(R.id.button);
mNumberButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnNumberClickListener != null) {
mOnNumberClickListener.onNumberClicked((Integer) v.getTag());
}
}
});
}

public Button getNumberButton() {
return mNumberButton;
}
}

Expand All @@ -203,50 +258,14 @@ public DeleteViewHolder(final View itemView) {
super(itemView);
mDeleteButton = (LinearLayout) itemView.findViewById(R.id.button);
mButtonImage = (ImageView) itemView.findViewById(R.id.buttonImage);
}

if (mCustomizationOptionsBundle.isShowDeleteButton() && mPinLength > 0) {
mDeleteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mOnDeleteClickListener != null) {
mOnDeleteClickListener.onDeleteClicked();
}
}
});

mDeleteButton.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
if (mOnDeleteClickListener != null) {
mOnDeleteClickListener.onDeleteLongClicked();
}
return true;
}
});

mDeleteButton.setOnTouchListener(new View.OnTouchListener() {
private Rect rect;
public LinearLayout getDeleteButton() {
return mDeleteButton;
}

@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_DOWN) {
mButtonImage.setColorFilter(mCustomizationOptionsBundle
.getDeleteButtonPressesColor());
rect = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
}
if (event.getAction() == MotionEvent.ACTION_UP) {
mButtonImage.clearColorFilter();
}
if (event.getAction() == MotionEvent.ACTION_MOVE) {
if (!rect.contains(v.getLeft() + (int) event.getX(),
v.getTop() + (int) event.getY())) {
mButtonImage.clearColorFilter();
}
}
return false;
}
});
}
public ImageView getButtonImage() {
return mButtonImage;
}
}

Expand Down