diff --git a/.idea/gradle.xml b/.idea/gradle.xml
index d607bb7..540ad44 100644
--- a/.idea/gradle.xml
+++ b/.idea/gradle.xml
@@ -3,10 +3,9 @@
-
+
diff --git a/app/src/main/java/com/daprlabs/swipedeck/SwipeDeckActivity.java b/app/src/main/java/com/daprlabs/swipedeck/SwipeDeckActivity.java
index 9ca4523..bf08428 100644
--- a/app/src/main/java/com/daprlabs/swipedeck/SwipeDeckActivity.java
+++ b/app/src/main/java/com/daprlabs/swipedeck/SwipeDeckActivity.java
@@ -28,29 +28,31 @@ protected void onCreate(Bundle savedInstanceState) {
cardStack = (SwipeDeck) findViewById(R.id.swipe_deck);
final ArrayList testData = new ArrayList<>();
+ testData.add("0");
testData.add("1");
testData.add("2");
testData.add("3");
testData.add("4");
- testData.add("5");
final SwipeDeckAdapter adapter = new SwipeDeckAdapter(testData, this);
cardStack.setAdapter(adapter);
cardStack.setEventCallback(new SwipeDeck.SwipeEventCallback() {
@Override
- public void cardSwipedLeft() {
- Log.i("MainActivity", "card was swiped left");
+ public void cardSwipedLeft(int position) {
+ Log.i("MainActivity", "card was swiped left, position in adapter: " + position);
}
@Override
- public void cardSwipedRight() {
- Log.i("MainActivity", "card was swiped right");
+ public void cardSwipedRight(int position) {
+ Log.i("MainActivity", "card was swiped right, position in adapter: " + position);
}
@Override
- public void cardClicked() {
- Log.i("MainActivity", "card was clicked");
+ public void cardClicked(int position) {
+ Log.i("MainActivity", "card was clicked, position in adapter: " + position);
+ //example of how to get the item that was clicked / swiped / etc
+ Log.i("MainActivity", (String)adapter.getItem(position));
}
@Override
@@ -66,11 +68,10 @@ public void cardsDepleted() {
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- testData.add("");
+ testData.add("a sample object. in this case a string.");
adapter.notifyDataSetChanged();
}
});
-
}
@Override
diff --git a/cardstack/build.gradle b/cardstack/build.gradle
index f0260d4..5c96e26 100644
--- a/cardstack/build.gradle
+++ b/cardstack/build.gradle
@@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/aaronbond/Swipe-Deck'
gitUrl = 'https://github.com/aaronbond/Swipe-Deck.git'
- libraryVersion = '0.0.7'
+ libraryVersion = '0.1.0'
developerId = 'aaronbond'
developerName = 'Aaron Bond'
@@ -31,8 +31,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 23
- versionCode 7
- versionName "0.0.7"
+ versionCode 8
+ versionName "0.1.0"
}
buildTypes {
release {
diff --git a/cardstack/src/main/java/com/daprlabs/cardstack/SwipeDeck.java b/cardstack/src/main/java/com/daprlabs/cardstack/SwipeDeck.java
index 1cddd76..944132b 100644
--- a/cardstack/src/main/java/com/daprlabs/cardstack/SwipeDeck.java
+++ b/cardstack/src/main/java/com/daprlabs/cardstack/SwipeDeck.java
@@ -182,7 +182,7 @@ private void addNextCard() {
nextAdapterCard++;
}
setZTranslations();
- setupTopCard();
+ setupTopCard(nextAdapterCard);
}
private void setZTranslations() {
@@ -192,7 +192,6 @@ private void setZTranslations() {
}
}
-
/**
* Adds a view as a child view and takes care of measuring it
*
@@ -268,9 +267,14 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
}
- private void setupTopCard() {
+ private void setupTopCard(final int cardPosition) {
final View child = getChildAt(0);
+ //this calculation is to get the correct position in the adapter of the current top card
+ //the card position on setup top card is currently always the bottom card in the view
+ //at any given time.
+ int childCount = getChildCount();
+ final int pos = cardPosition - childCount;
int initialX = paddingLeft;
int initialY = paddingTop;
@@ -281,20 +285,20 @@ private void setupTopCard() {
@Override
public void cardSwipedLeft() {
removeTopCard();
+ if(eventCallback != null)eventCallback.cardSwipedLeft(pos);
addNextCard();
- if(eventCallback != null)eventCallback.cardSwipedLeft();
}
@Override
public void cardSwipedRight() {
removeTopCard();
addNextCard();
- if(eventCallback != null)eventCallback.cardSwipedRight();
+ if(eventCallback != null)eventCallback.cardSwipedRight(pos);
}
@Override
public void cardClicked() {
- if(eventCallback != null)eventCallback.cardClicked();
+ if(eventCallback != null)eventCallback.cardClicked(pos);
}
}, initialX, initialY, ROTATION_DEGREES, OPACITY_END);
@@ -329,9 +333,10 @@ public void setRightImage(int imageResource){
}
public interface SwipeEventCallback {
- void cardSwipedLeft();
- void cardSwipedRight();
- void cardClicked();
+ //returning the object position in the adapter
+ void cardSwipedLeft(int position);
+ void cardSwipedRight(int position);
+ void cardClicked(int position);
void cardsDepleted();
}