-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from AlanCheen/feature/animation
Feature/animation
- Loading branch information
Showing
20 changed files
with
375 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
app/src/main/java/me/yifeiyuan/flapdev/testcases/AnimationTestcase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package me.yifeiyuan.flapdev.testcases | ||
|
||
import android.view.Menu | ||
import android.view.MenuInflater | ||
import android.view.MenuItem | ||
import android.view.View | ||
import jp.wasabeef.recyclerview.animators.ScaleInAnimator | ||
import me.yifeiyuan.flap.animation.* | ||
import me.yifeiyuan.flapdev.R | ||
import me.yifeiyuan.flapdev.components.SimpleTextModel | ||
|
||
/** | ||
* 测试动画功能 | ||
* | ||
* 更推荐使用 https://github.com/wasabeef/recyclerview-animators | ||
* 除了 minSdk 指定 21 有点高外。 | ||
* | ||
* Created by 程序亦非猿 on 2022/8/29. | ||
*/ | ||
class AnimationTestcase : BaseTestcaseFragment() { | ||
|
||
private val alphaInAdapterAnimation = AlphaInAdapterAnimation() | ||
private val scaleInAdapterAnimation = ScaleInAdapterAnimation() | ||
private val slideInRightAdapterAnimation = SlideInRightAdapterAnimation() | ||
private val slideInLeftAdapterAnimation = SlideInLeftAdapterAnimation() | ||
private val slideInBottomAdapterAnimation = SlideInBottomAdapterAnimation() | ||
|
||
lateinit var currentAdapterAnimation: BaseAdapterAnimation | ||
|
||
override fun onInit(view: View) { | ||
super.onInit(view) | ||
|
||
setHasOptionsMenu(true) | ||
|
||
adapter.doOnPreload { | ||
loadMoreData(20) | ||
} | ||
|
||
currentAdapterAnimation = slideInBottomAdapterAnimation | ||
currentAdapterAnimation.attachToAdapter(adapter) | ||
|
||
recyclerView.addItemDecoration(spaceItemDecoration) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { | ||
inflater.inflate(R.menu.animation, menu) | ||
} | ||
|
||
override fun onOptionsItemSelected(item: MenuItem): Boolean { | ||
when (item.itemId) { | ||
R.id.resetData -> { | ||
resetData() | ||
} | ||
R.id.slideInLeft -> { | ||
resetAdapterAnimation() | ||
currentAdapterAnimation = slideInLeftAdapterAnimation | ||
currentAdapterAnimation.attachToAdapter(adapter) | ||
} | ||
R.id.slideInRight -> { | ||
resetAdapterAnimation() | ||
currentAdapterAnimation = slideInRightAdapterAnimation | ||
currentAdapterAnimation.attachToAdapter(adapter) | ||
} | ||
R.id.scaleIn -> { | ||
resetAdapterAnimation() | ||
currentAdapterAnimation = scaleInAdapterAnimation | ||
currentAdapterAnimation.attachToAdapter(adapter) | ||
} | ||
R.id.alphaIn -> { | ||
resetAdapterAnimation() | ||
currentAdapterAnimation = alphaInAdapterAnimation | ||
currentAdapterAnimation.attachToAdapter(adapter) | ||
} | ||
R.id.slideInBottom -> { | ||
resetAdapterAnimation() | ||
currentAdapterAnimation = slideInBottomAdapterAnimation | ||
currentAdapterAnimation.attachToAdapter(adapter) | ||
} | ||
|
||
R.id.animators -> { | ||
resetAdapterAnimation() | ||
recyclerView.itemAnimator = ScaleInAnimator() | ||
} | ||
R.id.addOne -> { | ||
val newOne = SimpleTextModel("New one") | ||
adapter.insertDataAt(1, newOne) | ||
} | ||
R.id.removeOne -> { | ||
adapter.removeDataAt(1) | ||
} | ||
} | ||
return super.onOptionsItemSelected(item) | ||
} | ||
|
||
private fun resetData() { | ||
adapter.setDataAndNotify(createRefreshData()) | ||
currentAdapterAnimation.reset() | ||
} | ||
|
||
private fun resetAdapterAnimation() { | ||
currentAdapterAnimation.let { | ||
it.reset() | ||
adapter.unregisterAdapterHook(it) | ||
} | ||
recyclerView.itemAnimator = null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
<item | ||
android:id="@+id/resetData" | ||
android:title="重置数据" /> | ||
<item | ||
android:id="@+id/slideInRight" | ||
android:title="SlideInRight" /> | ||
<item | ||
android:id="@+id/slideInLeft" | ||
android:title="SlideInLeft" /> | ||
<item | ||
android:id="@+id/slideInBottom" | ||
android:title="SlideInBottom" /> | ||
<item | ||
android:id="@+id/alphaIn" | ||
android:title="AlphaIn" /> | ||
|
||
<item | ||
android:id="@+id/scaleIn" | ||
android:title="ScaleIn" /> | ||
<item | ||
android:id="@+id/animators" | ||
android:title="使用 recyclerview-animators" /> | ||
|
||
<item | ||
android:id="@+id/addOne" | ||
android:title="增加一个" app:showAsAction="always"/> | ||
|
||
<item | ||
android:id="@+id/removeOne" | ||
android:title="删除一个" app:showAsAction="always"/> | ||
</menu> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
flap/src/main/java/me/yifeiyuan/flap/animation/AlphaInAdapterAnimation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.yifeiyuan.flap.animation | ||
|
||
import android.animation.Animator | ||
import android.animation.ObjectAnimator | ||
import android.view.View | ||
import me.yifeiyuan.flap.Component | ||
|
||
/** | ||
* Created by 程序亦非猿 on 2022/8/29. | ||
* | ||
* @since 3.0.7 | ||
*/ | ||
class AlphaInAdapterAnimation(var startAlpha: Float = 0f) : BaseAdapterAnimation() { | ||
|
||
override fun createAnimator(view: View, component: Component<*>, data: Any, position: Int): Animator { | ||
return ObjectAnimator.ofFloat(view, "alpha", startAlpha, 1f) | ||
} | ||
|
||
} |
Oops, something went wrong.