Add null-check of swipe icon.
This commit is contained in:
committed by
Jannis Mattheis
parent
6b00bfb63c
commit
ed8689daa0
@@ -425,6 +425,7 @@ public class MessagesActivity extends AppCompatActivity
|
|||||||
|
|
||||||
Drawable drawable =
|
Drawable drawable =
|
||||||
ContextCompat.getDrawable(MessagesActivity.this, R.drawable.ic_delete);
|
ContextCompat.getDrawable(MessagesActivity.this, R.drawable.ic_delete);
|
||||||
|
icon = null;
|
||||||
if (drawable != null) {
|
if (drawable != null) {
|
||||||
icon = DrawableCompat.wrap(drawable.mutate());
|
icon = DrawableCompat.wrap(drawable.mutate());
|
||||||
DrawableCompat.setTint(icon, iconColorId);
|
DrawableCompat.setTint(icon, iconColorId);
|
||||||
@@ -457,48 +458,50 @@ public class MessagesActivity extends AppCompatActivity
|
|||||||
float dY,
|
float dY,
|
||||||
int actionState,
|
int actionState,
|
||||||
boolean isCurrentlyActive) {
|
boolean isCurrentlyActive) {
|
||||||
View itemView = viewHolder.itemView;
|
if (icon != null) {
|
||||||
|
View itemView = viewHolder.itemView;
|
||||||
|
|
||||||
int iconHeight = itemView.getHeight() / 3;
|
int iconHeight = itemView.getHeight() / 3;
|
||||||
double scale = iconHeight / (double) icon.getIntrinsicHeight();
|
double scale = iconHeight / (double) icon.getIntrinsicHeight();
|
||||||
int iconWidth = (int) (icon.getIntrinsicWidth() * scale);
|
int iconWidth = (int) (icon.getIntrinsicWidth() * scale);
|
||||||
|
|
||||||
int iconMarginLeftRight = 50;
|
int iconMarginLeftRight = 50;
|
||||||
int iconMarginTopBottom = (itemView.getHeight() - iconHeight) / 2;
|
int iconMarginTopBottom = (itemView.getHeight() - iconHeight) / 2;
|
||||||
int iconTop = itemView.getTop() + iconMarginTopBottom;
|
int iconTop = itemView.getTop() + iconMarginTopBottom;
|
||||||
int iconBottom = itemView.getBottom() - iconMarginTopBottom;
|
int iconBottom = itemView.getBottom() - iconMarginTopBottom;
|
||||||
|
|
||||||
if (dX > 0) {
|
if (dX > 0) {
|
||||||
// Swiping to the right
|
// Swiping to the right
|
||||||
int iconLeft = itemView.getLeft() + iconMarginLeftRight;
|
int iconLeft = itemView.getLeft() + iconMarginLeftRight;
|
||||||
int iconRight = itemView.getLeft() + iconMarginLeftRight + iconWidth;
|
int iconRight = itemView.getLeft() + iconMarginLeftRight + iconWidth;
|
||||||
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
|
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
|
||||||
|
|
||||||
background.setBounds(
|
background.setBounds(
|
||||||
itemView.getLeft(),
|
itemView.getLeft(),
|
||||||
itemView.getTop(),
|
itemView.getTop(),
|
||||||
itemView.getLeft() + ((int) dX),
|
itemView.getLeft() + ((int) dX),
|
||||||
itemView.getBottom());
|
itemView.getBottom());
|
||||||
} else if (dX < 0) {
|
} else if (dX < 0) {
|
||||||
// Swiping to the left
|
// Swiping to the left
|
||||||
int iconLeft = itemView.getRight() - iconMarginLeftRight - iconWidth;
|
int iconLeft = itemView.getRight() - iconMarginLeftRight - iconWidth;
|
||||||
int iconRight = itemView.getRight() - iconMarginLeftRight;
|
int iconRight = itemView.getRight() - iconMarginLeftRight;
|
||||||
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
|
icon.setBounds(iconLeft, iconTop, iconRight, iconBottom);
|
||||||
|
|
||||||
background.setBounds(
|
background.setBounds(
|
||||||
itemView.getRight() + ((int) dX),
|
itemView.getRight() + ((int) dX),
|
||||||
itemView.getTop(),
|
itemView.getTop(),
|
||||||
itemView.getRight(),
|
itemView.getRight(),
|
||||||
itemView.getBottom());
|
itemView.getBottom());
|
||||||
} else {
|
} else {
|
||||||
// View is unswiped
|
// View is unswiped
|
||||||
icon.setBounds(0, 0, 0, 0);
|
icon.setBounds(0, 0, 0, 0);
|
||||||
background.setBounds(0, 0, 0, 0);
|
background.setBounds(0, 0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
background.draw(c);
|
||||||
|
icon.draw(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
background.draw(c);
|
|
||||||
icon.draw(c);
|
|
||||||
|
|
||||||
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user