diff --git a/README.md b/README.md index 50f6533f..5d8d468f 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,8 @@ [![Download](https://api.bintray.com/packages/yuyakaido/maven/CardStackView/images/download.svg)](https://bintray.com/yuyakaido/maven/CardStackView/_latestVersion) [![AndroidArsenal](https://img.shields.io/badge/Android%20Arsenal-CardStackView-blue.svg?style=flat)](https://android-arsenal.com/details/1/6075) [![CircleCI](https://circleci.com/gh/yuyakaido/CardStackView.svg?style=svg)](https://circleci.com/gh/yuyakaido/CardStackView) +
+Buy Me A Coffee # Overview diff --git a/cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java b/cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java index 7193ddec..de7bc089 100644 --- a/cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java +++ b/cardstackview/src/main/java/com/yuyakaido/android/cardstackview/CardStackView.java @@ -81,4 +81,7 @@ private void initialize() { setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER); } -} + public CardStackLayoutManager getCardStackLayoutManager(){ + return (CardStackLayoutManager) getLayoutManager(); + } +} \ No newline at end of file diff --git a/sample/src/main/java/com/yuyakaido/android/cardstackview/sample/MainActivity.kt b/sample/src/main/java/com/yuyakaido/android/cardstackview/sample/MainActivity.kt index 6ea5ea48..b407f75f 100644 --- a/sample/src/main/java/com/yuyakaido/android/cardstackview/sample/MainActivity.kt +++ b/sample/src/main/java/com/yuyakaido/android/cardstackview/sample/MainActivity.kt @@ -3,8 +3,6 @@ package com.yuyakaido.android.cardstackview.sample import android.os.Bundle import android.util.Log import android.view.View -import android.view.animation.AccelerateInterpolator -import android.view.animation.DecelerateInterpolator import android.view.animation.LinearInterpolator import android.widget.TextView import androidx.appcompat.app.ActionBarDrawerToggle @@ -76,7 +74,14 @@ class MainActivity : AppCompatActivity(), CardStackListener { setSupportActionBar(toolbar) // DrawerLayout - val actionBarDrawerToggle = ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer) + val actionBarDrawerToggle = + ActionBarDrawerToggle( + this, + drawerLayout, + toolbar, + R.string.open_drawer, + R.string.close_drawer + ) actionBarDrawerToggle.syncState() drawerLayout.addDrawerListener(actionBarDrawerToggle) @@ -104,38 +109,30 @@ class MainActivity : AppCompatActivity(), CardStackListener { private fun setupButton() { val skip = findViewById(R.id.skip_button) skip.setOnClickListener { - val setting = SwipeAnimationSetting.Builder() - .setDirection(Direction.Left) - .setDuration(Duration.Normal.duration) - .setInterpolator(AccelerateInterpolator()) - .build() - manager.setSwipeAnimationSetting(setting) + updateCardStack(Direction.Left) cardStackView.swipe() } val rewind = findViewById(R.id.rewind_button) rewind.setOnClickListener { - val setting = RewindAnimationSetting.Builder() - .setDirection(Direction.Bottom) - .setDuration(Duration.Normal.duration) - .setInterpolator(DecelerateInterpolator()) - .build() - manager.setRewindAnimationSetting(setting) + updateCardStack(Direction.Bottom) cardStackView.rewind() } val like = findViewById(R.id.like_button) like.setOnClickListener { - val setting = SwipeAnimationSetting.Builder() - .setDirection(Direction.Right) - .setDuration(Duration.Normal.duration) - .setInterpolator(AccelerateInterpolator()) - .build() - manager.setSwipeAnimationSetting(setting) + updateCardStack(Direction.Right) cardStackView.swipe() } } + private fun updateCardStack(direction: Direction) { + val cardStackLayoutManager = cardStackView.getCardStackLayoutManager() + val swipeAnimationSetting = SwipeAnimationSetting.Builder().setDirection(direction).build() + cardStackLayoutManager.setSwipeAnimationSetting(swipeAnimationSetting) + cardStackView.setLayoutManager(cardStackLayoutManager) + } + private fun initialize() { manager.setStackFrom(StackFrom.None) manager.setVisibleCount(3) @@ -177,12 +174,13 @@ class MainActivity : AppCompatActivity(), CardStackListener { private fun addFirst(size: Int) { val old = adapter.getSpots() - val new = mutableListOf().apply { - addAll(old) - for (i in 0 until size) { - add(manager.topPosition, createSpot()) - } - } + val new = + mutableListOf().apply { + addAll(old) + for (i in 0 until size) { + add(manager.topPosition, createSpot()) + } + } val callback = SpotDiffCallback(old, new) val result = DiffUtil.calculateDiff(callback) adapter.setSpots(new) @@ -191,10 +189,11 @@ class MainActivity : AppCompatActivity(), CardStackListener { private fun addLast(size: Int) { val old = adapter.getSpots() - val new = mutableListOf().apply { - addAll(old) - addAll(List(size) { createSpot() }) - } + val new = + mutableListOf().apply { + addAll(old) + addAll(List(size) { createSpot() }) + } val callback = SpotDiffCallback(old, new) val result = DiffUtil.calculateDiff(callback) adapter.setSpots(new) @@ -207,12 +206,13 @@ class MainActivity : AppCompatActivity(), CardStackListener { } val old = adapter.getSpots() - val new = mutableListOf().apply { - addAll(old) - for (i in 0 until size) { - removeAt(manager.topPosition) - } - } + val new = + mutableListOf().apply { + addAll(old) + for (i in 0 until size) { + removeAt(manager.topPosition) + } + } val callback = SpotDiffCallback(old, new) val result = DiffUtil.calculateDiff(callback) adapter.setSpots(new) @@ -225,12 +225,13 @@ class MainActivity : AppCompatActivity(), CardStackListener { } val old = adapter.getSpots() - val new = mutableListOf().apply { - addAll(old) - for (i in 0 until size) { - removeAt(this.size - 1) - } - } + val new = + mutableListOf().apply { + addAll(old) + for (i in 0 until size) { + removeAt(this.size - 1) + } + } val callback = SpotDiffCallback(old, new) val result = DiffUtil.calculateDiff(callback) adapter.setSpots(new) @@ -239,24 +240,26 @@ class MainActivity : AppCompatActivity(), CardStackListener { private fun replace() { val old = adapter.getSpots() - val new = mutableListOf().apply { - addAll(old) - removeAt(manager.topPosition) - add(manager.topPosition, createSpot()) - } + val new = + mutableListOf().apply { + addAll(old) + removeAt(manager.topPosition) + add(manager.topPosition, createSpot()) + } adapter.setSpots(new) adapter.notifyItemChanged(manager.topPosition) } private fun swap() { val old = adapter.getSpots() - val new = mutableListOf().apply { - addAll(old) - val first = removeAt(manager.topPosition) - val last = removeAt(this.size - 1) - add(manager.topPosition, last) - add(first) - } + val new = + mutableListOf().apply { + addAll(old) + val first = removeAt(manager.topPosition) + val last = removeAt(this.size - 1) + add(manager.topPosition, last) + add(first) + } val callback = SpotDiffCallback(old, new) val result = DiffUtil.calculateDiff(callback) adapter.setSpots(new) @@ -273,17 +276,76 @@ class MainActivity : AppCompatActivity(), CardStackListener { private fun createSpots(): List { val spots = ArrayList() - spots.add(Spot(name = "Yasaka Shrine", city = "Kyoto", url = "https://source.unsplash.com/Xq1ntWruZQI/600x800")) - spots.add(Spot(name = "Fushimi Inari Shrine", city = "Kyoto", url = "https://source.unsplash.com/NYyCqdBOKwc/600x800")) - spots.add(Spot(name = "Bamboo Forest", city = "Kyoto", url = "https://source.unsplash.com/buF62ewDLcQ/600x800")) - spots.add(Spot(name = "Brooklyn Bridge", city = "New York", url = "https://source.unsplash.com/THozNzxEP3g/600x800")) - spots.add(Spot(name = "Empire State Building", city = "New York", url = "https://source.unsplash.com/USrZRcRS2Lw/600x800")) - spots.add(Spot(name = "The statue of Liberty", city = "New York", url = "https://source.unsplash.com/PeFk7fzxTdk/600x800")) - spots.add(Spot(name = "Louvre Museum", city = "Paris", url = "https://source.unsplash.com/LrMWHKqilUw/600x800")) - spots.add(Spot(name = "Eiffel Tower", city = "Paris", url = "https://source.unsplash.com/HN-5Z6AmxrM/600x800")) - spots.add(Spot(name = "Big Ben", city = "London", url = "https://source.unsplash.com/CdVAUADdqEc/600x800")) - spots.add(Spot(name = "Great Wall of China", city = "China", url = "https://source.unsplash.com/AWh9C-QjhE4/600x800")) + spots.add( + Spot( + name = "Yasaka Shrine", + city = "Kyoto", + url = "https://source.unsplash.com/Xq1ntWruZQI/600x800" + ) + ) + spots.add( + Spot( + name = "Fushimi Inari Shrine", + city = "Kyoto", + url = "https://source.unsplash.com/NYyCqdBOKwc/600x800" + ) + ) + spots.add( + Spot( + name = "Bamboo Forest", + city = "Kyoto", + url = "https://source.unsplash.com/buF62ewDLcQ/600x800" + ) + ) + spots.add( + Spot( + name = "Brooklyn Bridge", + city = "New York", + url = "https://source.unsplash.com/THozNzxEP3g/600x800" + ) + ) + spots.add( + Spot( + name = "Empire State Building", + city = "New York", + url = "https://source.unsplash.com/USrZRcRS2Lw/600x800" + ) + ) + spots.add( + Spot( + name = "The statue of Liberty", + city = "New York", + url = "https://source.unsplash.com/PeFk7fzxTdk/600x800" + ) + ) + spots.add( + Spot( + name = "Louvre Museum", + city = "Paris", + url = "https://source.unsplash.com/LrMWHKqilUw/600x800" + ) + ) + spots.add( + Spot( + name = "Eiffel Tower", + city = "Paris", + url = "https://source.unsplash.com/HN-5Z6AmxrM/600x800" + ) + ) + spots.add( + Spot( + name = "Big Ben", + city = "London", + url = "https://source.unsplash.com/CdVAUADdqEc/600x800" + ) + ) + spots.add( + Spot( + name = "Great Wall of China", + city = "China", + url = "https://source.unsplash.com/AWh9C-QjhE4/600x800" + ) + ) return spots } - }