Closed vanshg closed 8 years ago
@vanshg did you find any way to swipe up/down for like/dislike?
I did.
Change the if statements in CardContainer to
if (cardModel.getOnCardDismissedListener() != null) {
if (targetX > 0 && (targetY < 1500 && targetY > -1500)) {
cardModel.getOnCardDismissedListener().onLike(cardModel);
}
else if (targetX < 0 && (targetY < 1500 && targetY > -1500)) {
cardModel.getOnCardDismissedListener().onDislike(cardModel);
}
else if (targetY < 0 && (targetX < 1000 && targetX > -1000)) {
cardModel.getOnCardDismissedListener().onUp(cardModel);
}
else if (targetY > 0 && (targetX < 700 && targetX > -700)) {
cardModel.getOnCardDismissedListener().onDown(cardModel);
}
else {
topCard.animate()
.setDuration(duration)
.setInterpolator(new DecelerateInterpolator())
.translationX(0)
.translationY(0)
.rotation(0);
return true;
}
You must also change the OnCardDismissedListener in CardModel.java to be defined as follows
public interface OnCardDismissedListener
{
void onLike(CardModel cardModel);
void onDislike(CardModel cardModel);
void onUp(CardModel cardModel);
void onDown(CardModel cardModel);
}
When you set your OnCardDismissedListener, simply define onUp and onDown as well as onLike and onDislike like so:
card.setOnCardDismissedListener(new CardModel.OnCardDismissedListener()
{
@Override
public void onLike(CardModel cardModel)
{
}
@Override
public void onDislike(CardModel cardModel)
{
}
@Override
public void onUp(CardModel cardModel)
{
}
@Override
public void onDown(CardModel cardModel)
{
});
i'll try the code. i need the up/down as well as left/right. for that i should define all four in the if statement above. Right?
The code i posted is for up/down as well as left/right
yeah, thanks.
i tried it now. made the changes specified above but up/down are still not working.
What error do you get?
No error. I am toasting a msg on up,left and right. The card doesn't get dismissed when I drag it to top.
vansh, can you help me in this regard?
Try logging the X and Y values right before the if statement and see what they are when you try to swipe the cards up and down and then adjust the values in the if statement accordingly. Other than trying that, I'm not sure
In addition to the swiping left and right to "like" or "dislike" something, is it possible to also add the ability to swipe up and down for other actions?