Repository: wasabeef/recyclerview-animators Branch: master Commit: 6c5c7748e86f Files: 73 Total size: 144.1 KB Directory structure: gitextract__i4k753b/ ├── .editorconfig ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE.md │ ├── PULL_REQUEST_TEMPLATE.md │ └── workflows/ │ └── gradle-build.yml ├── .gitignore ├── .idea/ │ ├── codeStyles/ │ │ ├── Project.xml │ │ └── codeStyleConfig.xml │ ├── encodings.xml │ ├── runConfigurations.xml │ └── vcs.xml ├── CHANGELOG.md ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── animators/ │ ├── build.gradle │ └── src/ │ ├── androidTest/ │ │ └── java/ │ │ └── jp/ │ │ └── wasabeef/ │ │ └── recyclerview/ │ │ └── ApplicationTest.java │ └── main/ │ ├── AndroidManifest.xml │ └── java/ │ └── jp/ │ └── wasabeef/ │ └── recyclerview/ │ ├── adapters/ │ │ ├── AlphaInAnimationAdapter.kt │ │ ├── AnimationAdapter.kt │ │ ├── ScaleInAnimationAdapter.kt │ │ ├── SlideInBottomAnimationAdapter.kt │ │ ├── SlideInLeftAnimationAdapter.kt │ │ └── SlideInRightAnimationAdapter.kt │ ├── animators/ │ │ ├── BaseItemAnimator.kt │ │ ├── FadeInAnimator.kt │ │ ├── FadeInDownAnimator.kt │ │ ├── FadeInLeftAnimator.kt │ │ ├── FadeInRightAnimator.kt │ │ ├── FadeInUpAnimator.kt │ │ ├── FlipInBottomXAnimator.kt │ │ ├── FlipInLeftYAnimator.kt │ │ ├── FlipInRightYAnimator.kt │ │ ├── FlipInTopXAnimator.kt │ │ ├── LandingAnimator.kt │ │ ├── OvershootInLeftAnimator.kt │ │ ├── OvershootInRightAnimator.kt │ │ ├── ScaleInAnimator.kt │ │ ├── ScaleInBottomAnimator.kt │ │ ├── ScaleInLeftAnimator.kt │ │ ├── ScaleInRightAnimator.kt │ │ ├── ScaleInTopAnimator.kt │ │ ├── SlideInDownAnimator.kt │ │ ├── SlideInLeftAnimator.kt │ │ ├── SlideInRightAnimator.kt │ │ ├── SlideInUpAnimator.kt │ │ └── holder/ │ │ └── AnimateViewHolder.kt │ └── internal/ │ └── ViewHelper.kt ├── build.gradle ├── example/ │ ├── build.gradle │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── jp/ │ │ └── wasabeef/ │ │ └── example/ │ │ └── recyclerview/ │ │ ├── AdapterSampleActivity.kt │ │ ├── AnimatorSampleActivity.kt │ │ ├── MainActivity.kt │ │ ├── MainAdapter.kt │ │ ├── MyAnimationAdapter.kt │ │ ├── MyAnimator.kt │ │ └── SampleData.kt │ └── res/ │ ├── layout/ │ │ ├── activity_adapter_sample.xml │ │ ├── activity_animator_sample.xml │ │ ├── activity_main.xml │ │ └── layout_list_item.xml │ └── values/ │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── signingConfigs/ ├── debug.gradle └── debug.keystore ================================================ FILE CONTENTS ================================================ ================================================ FILE: .editorconfig ================================================ [*.{kt,kts,java}] indent_size=2 max_line_length=off insert_final_newline=true [*.{kt,kts}] kotlin_imports_layout=ascii ================================================ FILE: .github/FUNDING.yml ================================================ # These are supported funding model platforms github: wasabeef # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] patreon: # Replace with a single Patreon username open_collective: # Replace with a single Open Collective username ko_fi: # Replace with a single Ko-fi username tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] ================================================ FILE: .github/ISSUE_TEMPLATE.md ================================================ # Future Task ## What is the motivation? ## What kind of solution can be considered? ## What do you want to discuss? *Please add relevant labels* ----- # Bug Reporting ## Steps to Reproduce ## Actual Results (include screenshots) ## Expected Results (include screenshots) ## URL ## OS details - Device: - OS: *Please add relevant labels* ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ ## What does this change? ## What is the value of this and can you measure success? ## Screenshots ================================================ FILE: .github/workflows/gradle-build.yml ================================================ name: "Gradle build" on: [push, pull_request] jobs: gradle: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/setup-java@v1 with: java-version: 1.8 - name: Build with Gradle run: ./gradlew build ================================================ FILE: .gitignore ================================================ # Mac OS .DS_store # Built application files *.apk *.ap_ # Files for the ART/Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ out/ # Gradle files .gradle/ build/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Android Studio Navigation editor temp files .navigation/ # Android Studio captures folder captures/ # IntelliJ *.iml .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml .idea/assetWizardSettings.xml .idea/dictionaries .idea/libraries .idea/caches .idea/misc.xml .idea/modules.xml .idea/navEditor.xml .idea/markdown* .idea/compiler.xml .idea/inspectionProfiles/Project_Default.xml .idea/jarRepositories.xml projectFilesBackup/ # Keystore files # Uncomment the following line if you do not want to check your keystore files in. #*.jks # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) google-services.json ================================================ FILE: .idea/codeStyles/Project.xml ================================================ ================================================ FILE: .idea/codeStyles/codeStyleConfig.xml ================================================ ================================================ FILE: .idea/encodings.xml ================================================ ================================================ FILE: .idea/runConfigurations.xml ================================================ ================================================ FILE: .idea/vcs.xml ================================================ ================================================ FILE: CHANGELOG.md ================================================ Change Log ========== Version 4.0.0 *(2020-08-27)* ---------------------------- Update: - Convert from all Java codes to Kotlin 1.3.72 - The minSdkVersion from 14 to 21 - The targetSdkVersion from 28 to 30 - The compileSdkVersion from 28 to 30 - Update project settings - Disable Jetifier - Add CodeStyle settings Version 3.0.0 *(2018-11-15)* ---------------------------- Update: - Migrate to AndroidX - Remove novoda-bintray-plugin - Fix a buf [#161](https://github.com/wasabeef/recyclerview-animators/pull/161) Version 2.3.0 *(2018-02-07)* ---------------------------- Update: - Compile & Target SDK Version 25 -> 27 - Build Tools 26.0.1 -> 27.0.3 - Support Library 25.3.1 -> 27.0.2 Version 2.2.7 *(2017-06-29)* ---------------------------- Update: - Support Library 25.3.0 -> 25.4.0 Version 2.2.6 *(2017-03-17)* ---------------------------- Feature: - [Changed Interpolator to DecelerateInterpolator #125](https://github.com/wasabeef/recyclerview-animators/pull/125) Update: - Build Tools 25 -> 25.0.2 - Support Library 24.2.0 -> 25.3.0 Bugfix: - [Fix animations not fully canceled on endAnimations() #86](https://github.com/wasabeef/recyclerview-animators/pull/86) Version 2.2.5 *(2016-12-02)* ---------------------------- Update: - Build Tools 24.0.2 -> 25 - Support Library 23.4.0 -> 24.2.0 Version 2.2.4 *(2016-08-03)* ---------------------------- Update: - Build Tools 23.0.1 -> 24.0.2 - Support Library 23.0.1 -> 23.4.0 Version 2.2.3 *(2016-04-19)* ---------------------------- Bug fix: [Dispatch onViewRecycled event to wrapped adapter #80](https://github.com/wasabeef/recyclerview-animators/pull/80) [Fix setStartDelay() is not reset by clear() #82](https://github.com/wasabeef/recyclerview-animators/pull/82) Update: Support library 23.2.1 Version 2.2.2 *(2016-04-05)* ---------------------------- Bug fix Version 2.2.1 *(2016-02-28)* ---------------------------- Bug fix: firstOnly Version 2.2.0 *(2016-01-29)* ---------------------------- Bug fix: [issue #64](https://github.com/wasabeef/recyclerview-animators/issues/64) by [@emartynov](https://github.com/wasabeef/recyclerview-animators/issues/64) Feature: [Motion Delay](https://github.com/wasabeef/recyclerview-animators/pull/66) by [@aphexcx](https://github.com/aphexcx) Version 2.1.0 *(2015-11-25)* ---------------------------- Move the adapters of the package. Added BaseItemAnimator#setInterpolator. Version 2.0.2 *(2015-11-24)* ---------------------------- Added AnimationAdapter#getIemId Fixed the getItemId() to return the nested adapter item id Version 2.0.1 *(2015-11-10)* ---------------------------- Bug fix registerAdapterDataObserver, unregisterAdapterDataObserver Version 2.0.0 *(2015-10-16)* ---------------------------- Support RecyclerView 23.1.0+ **Use 1.3.0 If you are using a 23.0.1 or below.** Version 1.3.0 *(2015-09-11)* ---------------------------- Added in ability to pass in interpolators to the four ItemAnimators. Thanks to [@craya1982](https://github.com/craya1982) Version 1.2.3 *(2015-09-07)* ---------------------------- Update support library. Version 1.2.2 *(2015-08-19)* ---------------------------- Add tension in OvershootAnimators. Version 1.2.1 *(2015-07-07)* ---------------------------- Update AnimationAdapter to allow grabbing the wrappedAdapter. Version 1.2.0 *(2015-04-15)* ---------------------------- Support Multiple animators for ViewHolders. Version 1.1.3 *(2015-04-08)* ---------------------------- Support Interpolator in AnimationAdapter. Version 1.1.2 *(2015-03-23)* ---------------------------- Supports multiple viewTypes. Version 1.1.1 *(2015-03-17)* ---------------------------- Improved reliability and speed. Version 1.1.0 *(2015-01-21)* ---------------------------- add RecyclerView.Adapter support. Version 1.0.3 *(2015-01-21)* ---------------------------- fix setting of pom.xml Version 1.0.2 *(2015-01-20)* ---------------------------- fix setting of pom.xml Version 1.0.1 *(2015-01-10)* ---------------------------- Attach a jar for non-Gradle Android users. Version 1.0.0 *(2015-01-05)* ---------------------------- Initial release. ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at dadadada.chop@gmail.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright {yyyy} {name of copyright owner} Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: README.md ================================================ RecyclerView Animators ======================

[![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-recyclerview--animators-brightgreen.svg?style=flat)](https://android-arsenal.com/details/1/1327) [![License](https://img.shields.io/badge/license-Apache%202-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/jp.wasabeef/recyclerview-animators/badge.svg)](https://search.maven.org/artifact/jp.wasabeef/recyclerview-animators) RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel free to use this. # Features * Animate addition and removal of [`ItemAnimator`](#itemanimator-1) * Appearance animations for items in [`RecyclerView.Adapter`](#recyclerviewadapter) # Demo ### ItemAnimator ### Adapters # How do I use it? ## Setup #### Gradle On your module's `build.gradle` file add this implementation statement to the `dependencies` section: ```groovy dependencies { // Kotlin implementation 'jp.wasabeef:recyclerview-animators:4.0.2' } ``` Also make sure that the `repositories` section includes not only `"mavenCentral()"` but also a `maven` section with the `"google()"` endpoint. ``` repositories { google() mavenCentral() jcenter() } ``` ## ItemAnimator ### Step 1 Set RecyclerView ItemAnimator. ```kotlin val recyclerView = findViewById(R.id.list) recyclerView.itemAnimator = SlideInLeftAnimator() ``` ```kotlin val recyclerView = findViewById(R.id.list) recyclerView.itemAnimator = SlideInUpAnimator(OvershootInterpolator(1f)) ``` ## Step 2 Please use the following `notifyItemChanged(int)` `notifyItemInserted(int)` `notifyItemRemoved(int)` `notifyItemRangeChanged(int, int)` `notifyItemRangeInserted(int, int)` `notifyItemRangeRemoved(int, int)` > If you want your animations to work, do not rely on calling `notifyDataSetChanged()`; > as it is the RecyclerView's default behavior, animations are not triggered to start inside this method. ```kotlin fun remove(position: Int) { dataSet.removeAt(position) notifyItemRemoved(position) } fun add(text: String, position: Int) { dataSet.add(position, text) notifyItemInserted(position) } ``` ### Advanced Step 3 You can change the durations. ```kotlin recyclerView.itemAnimator?.apply { addDuration = 1000 removeDuration = 100 moveDuration = 1000 changeDuration = 100 } ``` ### Advanced Step 4 Change the interpolator. ```kotlin recyclerView.itemAnimator = SlideInLeftAnimator().apply { setInterpolator(OvershootInterpolator()) } ``` ### Advanced Step 5 By implementing AnimateViewHolder, you can override preset animation. So, custom animation can be set depending on view holder. ```kotlin class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView), AnimateViewHolder { override fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) { // do something } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder, listener: ViewPropertyAnimatorListener) { itemView.animate().apply { translationY(-itemView.height * 0.3f) alpha(0f) duration = 300 setListener(listener) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { itemView.setTranslationY(-itemView.height * 0.3f) itemView.setAlpha(0f) } override fun animateAddImpl(holder: RecyclerView.ViewHolder, listener: ViewPropertyAnimatorListener) { itemView.animate().apply { translationY(0f) alpha(1f) duration = 300 setListener(listener) }.start() } } ``` ### Animators #### Cool `LandingAnimator` ##### Scale `ScaleInAnimator`, `ScaleInTopAnimator`, `ScaleInBottomAnimator` `ScaleInLeftAnimator`, `ScaleInRightAnimator` ##### Fade `FadeInAnimator`, `FadeInDownAnimator`, `FadeInUpAnimator` `FadeInLeftAnimator`, `FadeInRightAnimator` ##### Flip `FlipInTopXAnimator`, `FlipInBottomXAnimator` `FlipInLeftYAnimator`, `FlipInRightYAnimator` ##### Slide `SlideInLeftAnimator`, `SlideInRightAnimator`, `OvershootInLeftAnimator`, `OvershootInRightAnimator` `SlideInUpAnimator`, `SlideInDownAnimator` ## RecyclerView.Adapter ### Step 1 Set RecyclerView ItemAnimator. ```kotlin val recyclerView = findViewById(R.id.list) recyclerView.adapter = AlphaInAnimationAdapter(MyAdapter()) ``` #### Java ```java RecyclerView recyclerView = findViewById(R.id.list); recyclerView.setAdapter(new AlphaInAnimationAdapter(MyAdapter()); ``` ### Advanced Step 2 ```kotlin recyclerView.adapter = AlphaInAnimationAdapter(MyAdapter()).apply { // Change the durations. setDuration(1000) // Change the interpolator. setInterpolator(vershootInterpolator()) // Disable the first scroll mode. setFirstOnly(false) } ``` #### Java ```java AlphaInAnimationAdapter alphaInAnimationAdapter = new AlphaInAnimationAdapter(new MyAdapter()); alphaInAnimationAdapter.setDuration(1000); alphaInAnimationAdapter.setInterpolator(new OvershootInterpolator()); alphaInAnimationAdapter.setFirstOnly(false); ``` ### Advanced Step 3 Multiple Animations ```kotlin val alphaAdapter = AlphaInAnimationAdapter(MyAdapter()) recyclerView.adapter = ScaleInAnimationAdapter(alphaAdapter) ``` #### Java ```java recyclerView.setAdapter(new ScaleInAnimationAdapter(alphaInAnimationAdapter)); ``` ### Adapters #### Alpha `AlphaInAnimationAdapter` #### Scale `ScaleInAnimationAdapter` #### Slide `SlideInBottomAnimationAdapter` `SlideInRightAnimationAdapter`, `SlideInLeftAnimationAdapter` Applications using RecyclerView Animators --- Please [ping](mailto:dadadada.chop@gmail.com) me or send a pull request if you would like to be added here. Icon | Application ------------ | ------------- | [Ameba Ownd](https://play.google.com/store/apps/details?id=jp.co.cyberagent.madrid) | [QuitNow!](https://play.google.com/store/apps/details?id=com.EAGINsoftware.dejaloYa) | [AbemaTV](https://play.google.com/store/apps/details?id=tv.abema) | [CL](https://play.google.com/store/apps/details?id=com.cllive) Developed By ------- Daichi Furiya (Wasabeef) - Follow me on Twitter Contributions ------- Any contributions are welcome! Contributers ------- * [craya1982](https://github.com/craya1982) Thanks ------- * Inspired by `AndroidViewAnimations` in [daimajia](https://github.com/daimajia). License ------- Copyright 2020 Daichi Furiya / Wasabeef Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ================================================ FILE: animators/build.gradle ================================================ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' android { compileSdkVersion COMPILE_SDK_VERSION as int defaultConfig { minSdkVersion MIN_SDK_VERSION as int targetSdkVersion TARGET_SDK_VERSION as int } } dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "androidx.recyclerview:recyclerview:1.1.0" } ext { bintrayRepo = 'maven' bintrayName = 'recyclerview-animators' bintrayUserOrg = 'wasabeef' publishedGroupId = 'jp.wasabeef' libraryName = 'recyclerview-animators' artifact = 'recyclerview-animators' libraryDescription = 'Which provides simple Item animations to RecyclerView items' siteUrl = 'https://github.com/wasabeef/recyclerview-animators' gitUrl = 'https://github.com/wasabeef/recyclerview-animators.git' issueUrl = 'https://github.com/wasabeef/recyclerview-animators/issues' libraryVersion = VERSION_NAME developerId = 'wasabeef' developerName = 'Wasabeef' developerEmail = 'dadadada.chop@gmail.com' licenseName = 'The Apache Software License, Version 2.0' licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' allLicenses = ["Apache-2.0"] } // TODO: Close JCenter on May 1st https://jfrog.com/blog/into-the-sunset-bintray-jcenter-gocenter-and-chartcenter/ // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/bintray-v1.gradle' // apply from: 'https://gist.githubusercontent.com/wasabeef/cf14805bee509baf7461974582f17d26/raw/install-v1.gradle' apply from: 'https://gist.githubusercontent.com/wasabeef/2f2ae8d97b429e7d967128125dc47854/raw/maven-central-v1.gradle' ================================================ FILE: animators/src/androidTest/java/jp/wasabeef/recyclerview/ApplicationTest.java ================================================ package jp.wasabeef.recyclerview; import android.app.Application; import android.test.ApplicationTestCase; /** * Testing Fundamentals */ public class ApplicationTest extends ApplicationTestCase { public ApplicationTest() { super(Application.class); } } ================================================ FILE: animators/src/main/AndroidManifest.xml ================================================ ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/adapters/AlphaInAnimationAdapter.kt ================================================ package jp.wasabeef.recyclerview.adapters import android.animation.Animator import android.animation.ObjectAnimator import android.view.View import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class AlphaInAnimationAdapter @JvmOverloads constructor( adapter: RecyclerView.Adapter, private val from: Float = DEFAULT_ALPHA_FROM ) : AnimationAdapter(adapter) { override fun getAnimators(view: View): Array = arrayOf(ObjectAnimator.ofFloat(view, "alpha", from, 1f)) companion object { private const val DEFAULT_ALPHA_FROM = 0f } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/adapters/AnimationAdapter.kt ================================================ package jp.wasabeef.recyclerview.adapters import android.animation.Animator import android.view.View import android.view.ViewGroup import android.view.animation.Interpolator import android.view.animation.LinearInterpolator import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView.AdapterDataObserver import jp.wasabeef.recyclerview.internal.ViewHelper.clear /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ abstract class AnimationAdapter(wrapped: RecyclerView.Adapter) : RecyclerView.Adapter() { private var duration = 300 private var interpolator: Interpolator = LinearInterpolator() private var lastPosition = -1 private var isFirstOnly = true protected var adapter: RecyclerView.Adapter init { @Suppress("UNCHECKED_CAST") this.adapter = wrapped as RecyclerView.Adapter super.setHasStableIds(this.adapter.hasStableIds()) } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder { return adapter.onCreateViewHolder(parent, viewType) } override fun registerAdapterDataObserver(observer: AdapterDataObserver) { super.registerAdapterDataObserver(observer) adapter.registerAdapterDataObserver(observer) } override fun unregisterAdapterDataObserver(observer: AdapterDataObserver) { super.unregisterAdapterDataObserver(observer) adapter.unregisterAdapterDataObserver(observer) } override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { super.onAttachedToRecyclerView(recyclerView) adapter.onAttachedToRecyclerView(recyclerView) } override fun onDetachedFromRecyclerView(recyclerView: RecyclerView) { super.onDetachedFromRecyclerView(recyclerView) adapter.onDetachedFromRecyclerView(recyclerView) } override fun onViewAttachedToWindow(holder: RecyclerView.ViewHolder) { super.onViewAttachedToWindow(holder) adapter.onViewAttachedToWindow(holder) } override fun onViewDetachedFromWindow(holder: RecyclerView.ViewHolder) { super.onViewDetachedFromWindow(holder) adapter.onViewDetachedFromWindow(holder) } override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { adapter.onBindViewHolder(holder, position) val adapterPosition = holder.adapterPosition if (!isFirstOnly || adapterPosition > lastPosition) { for (anim in getAnimators(holder.itemView)) { anim.setDuration(duration.toLong()).start() anim.interpolator = interpolator } lastPosition = adapterPosition } else { clear(holder.itemView) } } override fun onViewRecycled(holder: RecyclerView.ViewHolder) { adapter.onViewRecycled(holder) super.onViewRecycled(holder) } override fun getItemCount(): Int { return adapter.itemCount } fun setDuration(duration: Int) { this.duration = duration } fun setInterpolator(interpolator: Interpolator) { this.interpolator = interpolator } fun setStartPosition(start: Int) { lastPosition = start } protected abstract fun getAnimators(view: View): Array fun setFirstOnly(firstOnly: Boolean) { isFirstOnly = firstOnly } override fun getItemViewType(position: Int): Int { return adapter.getItemViewType(position) } val wrappedAdapter: RecyclerView.Adapter get() = adapter override fun setHasStableIds(hasStableIds: Boolean) { super.setHasStableIds(hasStableIds) adapter.setHasStableIds(hasStableIds) } override fun getItemId(position: Int): Long { return adapter.getItemId(position) } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/adapters/ScaleInAnimationAdapter.kt ================================================ package jp.wasabeef.recyclerview.adapters import android.animation.Animator import android.animation.ObjectAnimator import android.view.View import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class ScaleInAnimationAdapter @JvmOverloads constructor( adapter: RecyclerView.Adapter, private val from: Float = DEFAULT_SCALE_FROM ) : AnimationAdapter(adapter) { override fun getAnimators(view: View): Array { val scaleX = ObjectAnimator.ofFloat(view, "scaleX", from, 1f) val scaleY = ObjectAnimator.ofFloat(view, "scaleY", from, 1f) return arrayOf(scaleX, scaleY) } companion object { private const val DEFAULT_SCALE_FROM = .5f } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/adapters/SlideInBottomAnimationAdapter.kt ================================================ package jp.wasabeef.recyclerview.adapters import android.animation.Animator import android.animation.ObjectAnimator import android.view.View import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInBottomAnimationAdapter( adapter: RecyclerView.Adapter ) : AnimationAdapter(adapter) { override fun getAnimators(view: View): Array = arrayOf( ObjectAnimator.ofFloat(view, "translationY", view.measuredHeight.toFloat(), 0f) ) } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/adapters/SlideInLeftAnimationAdapter.kt ================================================ package jp.wasabeef.recyclerview.adapters import android.animation.Animator import android.animation.ObjectAnimator import android.view.View import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInLeftAnimationAdapter( adapter: RecyclerView.Adapter ) : AnimationAdapter(adapter) { override fun getAnimators(view: View): Array = arrayOf( ObjectAnimator.ofFloat(view, "translationX", -view.rootView.width.toFloat(), 0f) ) } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/adapters/SlideInRightAnimationAdapter.kt ================================================ package jp.wasabeef.recyclerview.adapters import android.animation.Animator import android.animation.ObjectAnimator import android.view.View import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInRightAnimationAdapter( adapter: RecyclerView.Adapter ) : AnimationAdapter(adapter) { override fun getAnimators(view: View): Array = arrayOf( ObjectAnimator.ofFloat(view, "translationX", view.rootView.width.toFloat(), 0f) ) } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/BaseItemAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.animation.Animator import android.view.animation.DecelerateInterpolator import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.SimpleItemAnimator import jp.wasabeef.recyclerview.animators.holder.AnimateViewHolder import jp.wasabeef.recyclerview.internal.ViewHelper.clear import java.util.ArrayList import kotlin.math.abs /* * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ abstract class BaseItemAnimator : SimpleItemAnimator() { private val pendingRemovals = ArrayList() private val pendingAdditions = ArrayList() private val pendingMoves = ArrayList() private val pendingChanges = ArrayList() private val additionsList = ArrayList>() private val movesList = ArrayList>() private val changesList = ArrayList>() protected var addAnimations = ArrayList() private val moveAnimations = ArrayList() protected var removeAnimations = ArrayList() private val changeAnimations = ArrayList() protected var interpolator: Interpolator = DecelerateInterpolator() companion object { private const val DEBUG = false } init { supportsChangeAnimations = false } private class MoveInfo( var holder: RecyclerView.ViewHolder, var fromX: Int, var fromY: Int, var toX: Int, var toY: Int ) private class ChangeInfo private constructor( oldHolder: RecyclerView.ViewHolder, newHolder: RecyclerView.ViewHolder ) { var oldHolder: RecyclerView.ViewHolder? = oldHolder var newHolder: RecyclerView.ViewHolder? = newHolder var fromX = 0 var fromY = 0 var toX = 0 var toY = 0 constructor( oldHolder: RecyclerView.ViewHolder, newHolder: RecyclerView.ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int ) : this(oldHolder, newHolder) { this.fromX = fromX this.fromY = fromY this.toX = toX this.toY = toY } override fun toString(): String { return ("ChangeInfo{" + "oldHolder=" + oldHolder + ", newHolder=" + newHolder + ", fromX=" + fromX + ", fromY=" + fromY + ", toX=" + toX + ", toY=" + toY + '}') } } override fun runPendingAnimations() { val removalsPending = pendingRemovals.isNotEmpty() val movesPending = pendingMoves.isNotEmpty() val changesPending = pendingChanges.isNotEmpty() val additionsPending = pendingAdditions.isNotEmpty() if (!removalsPending && !movesPending && !additionsPending && !changesPending) { // nothing to animate return } // First, remove stuff for (holder in pendingRemovals) { doAnimateRemove(holder) } pendingRemovals.clear() // Next, move stuff if (movesPending) { val moves = ArrayList(pendingMoves) movesList.add(moves) pendingMoves.clear() val mover = Runnable { val removed = movesList.remove(moves) if (!removed) { // already canceled return@Runnable } for (moveInfo in moves) { animateMoveImpl( moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY ) } moves.clear() } if (removalsPending) { val view = moves[0].holder.itemView view.postOnAnimationDelayed(mover, removeDuration) } else { mover.run() } } // Next, change stuff, to run in parallel with move animations if (changesPending) { val changes = ArrayList(pendingChanges) changesList.add(changes) pendingChanges.clear() val changer = Runnable { val removed = changesList.remove(changes) if (!removed) { // already canceled return@Runnable } for (change in changes) { animateChangeImpl(change) } changes.clear() } if (removalsPending) { val holder = changes[0].oldHolder holder!!.itemView.postOnAnimationDelayed(changer, removeDuration) } else { changer.run() } } // Next, add stuff if (additionsPending) { val additions = ArrayList(pendingAdditions) additionsList.add(additions) pendingAdditions.clear() val adder = Runnable { val removed = additionsList.remove(additions) if (!removed) { // already canceled return@Runnable } for (holder in additions) { doAnimateAdd(holder) } additions.clear() } if (removalsPending || movesPending || changesPending) { val removeDuration = if (removalsPending) removeDuration else 0 val moveDuration = if (movesPending) moveDuration else 0 val changeDuration = if (changesPending) changeDuration else 0 val totalDelay = removeDuration + moveDuration.coerceAtLeast(changeDuration) val view = additions[0].itemView view.postOnAnimationDelayed(adder, totalDelay) } else { adder.run() } } } protected open fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) {} protected open fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) {} protected abstract fun animateRemoveImpl(holder: RecyclerView.ViewHolder) protected abstract fun animateAddImpl(holder: RecyclerView.ViewHolder) private fun preAnimateRemove(holder: RecyclerView.ViewHolder) { clear(holder.itemView) if (holder is AnimateViewHolder) { holder.preAnimateRemoveImpl(holder) } else { preAnimateRemoveImpl(holder) } } private fun preAnimateAdd(holder: RecyclerView.ViewHolder) { clear(holder.itemView) if (holder is AnimateViewHolder) { holder.preAnimateAddImpl(holder) } else { preAnimateAddImpl(holder) } } private fun doAnimateRemove(holder: RecyclerView.ViewHolder) { if (holder is AnimateViewHolder) { holder.animateRemoveImpl(holder, DefaultRemoveAnimatorListener(holder)) } else { animateRemoveImpl(holder) } removeAnimations.add(holder) } private fun doAnimateAdd(holder: RecyclerView.ViewHolder) { if (holder is AnimateViewHolder) { holder.animateAddImpl(holder, DefaultAddAnimatorListener(holder)) } else { animateAddImpl(holder) } addAnimations.add(holder) } override fun animateRemove(holder: RecyclerView.ViewHolder): Boolean { endAnimation(holder) preAnimateRemove(holder) pendingRemovals.add(holder) return true } protected fun getRemoveDelay(holder: RecyclerView.ViewHolder): Long { return abs(holder.oldPosition * removeDuration / 4) } override fun animateAdd(holder: RecyclerView.ViewHolder): Boolean { endAnimation(holder) preAnimateAdd(holder) pendingAdditions.add(holder) return true } protected fun getAddDelay(holder: RecyclerView.ViewHolder): Long { return abs(holder.adapterPosition * addDuration / 4) } override fun animateMove( holder: RecyclerView.ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int ): Boolean { var fX = fromX var fY = fromY val view = holder.itemView fX += holder.itemView.translationX.toInt() fY += holder.itemView.translationY.toInt() endAnimation(holder) val deltaX = toX - fX val deltaY = toY - fY if (deltaX == 0 && deltaY == 0) { dispatchMoveFinished(holder) return false } if (deltaX != 0) { view.translationX = -deltaX.toFloat() } if (deltaY != 0) { view.translationY = -deltaY.toFloat() } pendingMoves.add(MoveInfo(holder, fX, fY, toX, toY)) return true } private fun animateMoveImpl( holder: RecyclerView.ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int ) { val view = holder.itemView val deltaX = toX - fromX val deltaY = toY - fromY if (deltaX != 0) { view.animate().translationX(0f) } if (deltaY != 0) { view.animate().translationY(0f) } // TODO: make EndActions end listeners instead, since end actions aren't called when // vpas are canceled (and can't end them. why?) // need listener functionality in VPACompat for this. Ick. moveAnimations.add(holder) val animation = view.animate() animation.setDuration(moveDuration).setListener(object : AnimatorListenerAdapter() { override fun onAnimationStart(animator: Animator) { dispatchMoveStarting(holder) } override fun onAnimationCancel(animator: Animator) { if (deltaX != 0) { view.translationX = 0f } if (deltaY != 0) { view.translationY = 0f } } override fun onAnimationEnd(animator: Animator) { animation.setListener(null) dispatchMoveFinished(holder) moveAnimations.remove(holder) dispatchFinishedWhenDone() } }).start() } override fun animateChange( oldHolder: RecyclerView.ViewHolder, newHolder: RecyclerView.ViewHolder, fromX: Int, fromY: Int, toX: Int, toY: Int ): Boolean { if (oldHolder === newHolder) { // Don't know how to run change animations when the same view holder is re-used. // run a move animation to handle position changes. return animateMove(oldHolder, fromX, fromY, toX, toY) } val prevTranslationX = oldHolder.itemView.translationX val prevTranslationY = oldHolder.itemView.translationY val prevAlpha = oldHolder.itemView.alpha endAnimation(oldHolder) val deltaX = (toX - fromX - prevTranslationX).toInt() val deltaY = (toY - fromY - prevTranslationY).toInt() // recover prev translation state after ending animation oldHolder.itemView.translationX = prevTranslationX oldHolder.itemView.translationY = prevTranslationY oldHolder.itemView.alpha = prevAlpha // carry over translation values endAnimation(newHolder) newHolder.itemView.translationX = -deltaX.toFloat() newHolder.itemView.translationY = -deltaY.toFloat() newHolder.itemView.alpha = 0f pendingChanges.add(ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY)) return true } private fun animateChangeImpl(changeInfo: ChangeInfo) { val holder = changeInfo.oldHolder val view = holder?.itemView val newHolder = changeInfo.newHolder val newView = newHolder?.itemView if (view != null) { if (changeInfo.oldHolder != null) changeAnimations.add(changeInfo.oldHolder!!) val oldViewAnim = view.animate().setDuration( changeDuration ) oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX.toFloat()) oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY.toFloat()) oldViewAnim.alpha(0f).setListener(object : AnimatorListenerAdapter() { override fun onAnimationStart(animator: Animator) { dispatchChangeStarting(changeInfo.oldHolder, true) } override fun onAnimationEnd(animator: Animator) { oldViewAnim.setListener(null) view.alpha = 1f view.translationX = 0f view.translationY = 0f dispatchChangeFinished(changeInfo.oldHolder, true) if (changeInfo.oldHolder != null) changeAnimations.remove(changeInfo.oldHolder!!) dispatchFinishedWhenDone() } }).start() } if (newView != null) { if (changeInfo.newHolder != null) changeAnimations.add(changeInfo.newHolder!!) val newViewAnimation = newView.animate() newViewAnimation.translationX(0f).translationY(0f).setDuration(changeDuration).alpha(1f) .setListener(object : AnimatorListenerAdapter() { override fun onAnimationStart(animator: Animator) { dispatchChangeStarting(changeInfo.newHolder, false) } override fun onAnimationEnd(animator: Animator) { newViewAnimation.setListener(null) newView.alpha = 1f newView.translationX = 0f newView.translationY = 0f dispatchChangeFinished(changeInfo.newHolder, false) if (changeInfo.newHolder != null) changeAnimations.remove(changeInfo.newHolder!!) dispatchFinishedWhenDone() } }).start() } } private fun endChangeAnimation(infoList: MutableList, item: RecyclerView.ViewHolder) { for (i in infoList.indices.reversed()) { val changeInfo = infoList[i] if (endChangeAnimationIfNecessary(changeInfo, item)) { if (changeInfo.oldHolder == null && changeInfo.newHolder == null) { infoList.remove(changeInfo) } } } } private fun endChangeAnimationIfNecessary(changeInfo: ChangeInfo) { if (changeInfo.oldHolder != null) { endChangeAnimationIfNecessary(changeInfo, changeInfo.oldHolder) } if (changeInfo.newHolder != null) { endChangeAnimationIfNecessary(changeInfo, changeInfo.newHolder) } } private fun endChangeAnimationIfNecessary( changeInfo: ChangeInfo, item: RecyclerView.ViewHolder? ): Boolean { var oldItem = false when { changeInfo.newHolder === item -> { changeInfo.newHolder = null } changeInfo.oldHolder === item -> { changeInfo.oldHolder = null oldItem = true } else -> { return false } } item!!.itemView.alpha = 1f item.itemView.translationX = 0f item.itemView.translationY = 0f dispatchChangeFinished(item, oldItem) return true } override fun endAnimation(item: RecyclerView.ViewHolder) { val view = item.itemView // this will trigger end callback which should set properties to their target values. view.animate().cancel() // TODO if some other animations are chained to end, how do we cancel them as well? for (i in pendingMoves.indices.reversed()) { val moveInfo = pendingMoves[i] if (moveInfo.holder === item) { view.translationY = 0f view.translationX = 0f dispatchMoveFinished(item) pendingMoves.removeAt(i) } } endChangeAnimation(pendingChanges, item) if (pendingRemovals.remove(item)) { clear(item.itemView) dispatchRemoveFinished(item) } if (pendingAdditions.remove(item)) { clear(item.itemView) dispatchAddFinished(item) } for (i in changesList.indices.reversed()) { val changes = changesList[i] endChangeAnimation(changes, item) if (changes.isEmpty()) { changesList.removeAt(i) } } for (i in movesList.indices.reversed()) { val moves = movesList[i] for (j in moves.indices.reversed()) { val moveInfo = moves[j] if (moveInfo.holder === item) { view.translationY = 0f view.translationX = 0f dispatchMoveFinished(item) moves.removeAt(j) if (moves.isEmpty()) { movesList.removeAt(i) } break } } } for (i in additionsList.indices.reversed()) { val additions = additionsList[i] if (additions.remove(item)) { clear(item.itemView) dispatchAddFinished(item) if (additions.isEmpty()) { additionsList.removeAt(i) } } } // animations should be ended by the cancel above. check(!(removeAnimations.remove(item) && DEBUG)) { "after animation is cancelled, item should not be in " + "mRemoveAnimations list" } check(!(addAnimations.remove(item) && DEBUG)) { "after animation is cancelled, item should not be in " + "mAddAnimations list" } check(!(changeAnimations.remove(item) && DEBUG)) { "after animation is cancelled, item should not be in " + "mChangeAnimations list" } check(!(moveAnimations.remove(item) && DEBUG)) { "after animation is cancelled, item should not be in " + "mMoveAnimations list" } dispatchFinishedWhenDone() } override fun isRunning(): Boolean { return (pendingAdditions.isNotEmpty() || pendingChanges.isNotEmpty() || pendingMoves.isNotEmpty() || pendingRemovals.isNotEmpty() || moveAnimations.isNotEmpty() || removeAnimations.isNotEmpty() || addAnimations.isNotEmpty() || changeAnimations.isNotEmpty() || movesList.isNotEmpty() || additionsList.isNotEmpty() || changesList.isNotEmpty()) } /** * Check the state of currently pending and running animations. If there are none * pending/running, call #dispatchAnimationsFinished() to notify any * listeners. */ private fun dispatchFinishedWhenDone() { if (!isRunning) { dispatchAnimationsFinished() } } override fun endAnimations() { var count = pendingMoves.size for (i in count - 1 downTo 0) { val item = pendingMoves[i] val view = item.holder.itemView view.translationY = 0f view.translationX = 0f dispatchMoveFinished(item.holder) pendingMoves.removeAt(i) } count = pendingRemovals.size for (i in count - 1 downTo 0) { val item = pendingRemovals[i] dispatchRemoveFinished(item) pendingRemovals.removeAt(i) } count = pendingAdditions.size for (i in count - 1 downTo 0) { val item = pendingAdditions[i] clear(item.itemView) dispatchAddFinished(item) pendingAdditions.removeAt(i) } count = pendingChanges.size for (i in count - 1 downTo 0) { endChangeAnimationIfNecessary(pendingChanges[i]) } pendingChanges.clear() if (!isRunning) { return } var listCount = movesList.size for (i in listCount - 1 downTo 0) { val moves = movesList[i] count = moves.size for (j in count - 1 downTo 0) { val moveInfo = moves[j] val item = moveInfo.holder val view = item.itemView view.translationY = 0f view.translationX = 0f dispatchMoveFinished(moveInfo.holder) moves.removeAt(j) if (moves.isEmpty()) { movesList.remove(moves) } } } listCount = additionsList.size for (i in listCount - 1 downTo 0) { val additions = additionsList[i] count = additions.size for (j in count - 1 downTo 0) { val item = additions[j] val view = item.itemView view.alpha = 1f dispatchAddFinished(item) //this check prevent exception when removal already happened during finishing animation if (j < additions.size) { additions.removeAt(j) } if (additions.isEmpty()) { additionsList.remove(additions) } } } listCount = changesList.size for (i in listCount - 1 downTo 0) { val changes = changesList[i] count = changes.size for (j in count - 1 downTo 0) { endChangeAnimationIfNecessary(changes[j]) if (changes.isEmpty()) { changesList.remove(changes) } } } cancelAll(removeAnimations) cancelAll(moveAnimations) cancelAll(addAnimations) cancelAll(changeAnimations) dispatchAnimationsFinished() } private fun cancelAll(viewHolders: List) { for (i in viewHolders.indices.reversed()) { viewHolders[i].itemView.animate().cancel() } } open class AnimatorListenerAdapter : Animator.AnimatorListener { override fun onAnimationStart(animator: Animator) {} override fun onAnimationEnd(animator: Animator) {} override fun onAnimationCancel(animator: Animator) {} override fun onAnimationRepeat(animator: Animator) {} } inner class DefaultAddAnimatorListener(var viewHolder: RecyclerView.ViewHolder) : AnimatorListenerAdapter() { override fun onAnimationStart(animator: Animator) { dispatchAddStarting(viewHolder) } override fun onAnimationCancel(animator: Animator) { clear(viewHolder.itemView) } override fun onAnimationEnd(animator: Animator) { clear(viewHolder.itemView) dispatchAddFinished(viewHolder) addAnimations.remove(viewHolder) dispatchFinishedWhenDone() } } protected inner class DefaultRemoveAnimatorListener(var viewHolder: RecyclerView.ViewHolder) : AnimatorListenerAdapter() { override fun onAnimationStart(animator: Animator) { dispatchRemoveStarting(viewHolder) } override fun onAnimationCancel(animator: Animator) { clear(viewHolder.itemView) } override fun onAnimationEnd(animator: Animator) { clear(viewHolder.itemView) dispatchRemoveFinished(viewHolder) removeAnimations.remove(viewHolder) dispatchFinishedWhenDone() } } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FadeInAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FadeInAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FadeInDownAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FadeInDownAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(-holder.itemView.height * .25f) alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationY = -holder.itemView.height * .25f holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(0f) alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FadeInLeftAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FadeInLeftAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(-holder.itemView.rootView.width * .25f) alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationX = -holder.itemView.rootView.width * .25f holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(0f) alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FadeInRightAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FadeInRightAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(holder.itemView.rootView.width * .25f) alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationX = holder.itemView.rootView.width * .25f holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(0f) alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FadeInUpAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FadeInUpAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(holder.itemView.height * .25f) alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationY = holder.itemView.height * .25f holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(0f) alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FlipInBottomXAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FlipInBottomXAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationX(-90f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.rotationX = -90f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationX(0f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FlipInLeftYAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FlipInLeftYAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationY(90f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.rotationY = 90f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationY(0f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FlipInRightYAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FlipInRightYAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationY(-90f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.rotationY = -90f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationY(0f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/FlipInTopXAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class FlipInTopXAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationX(90f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.rotationX = 90f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { rotationX(0f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/LandingAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class LandingAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { alpha(0f) .scaleX(1.5f) .scaleY(1.5f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.alpha = 0f holder.itemView.scaleX = 1.5f holder.itemView.scaleY = 1.5f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { alpha(1f) scaleX(1f) scaleY(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/OvershootInLeftAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.OvershootInterpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class OvershootInLeftAnimator : BaseItemAnimator { private val tension: Float constructor() { tension = 2.0f } constructor(tension: Float) { this.tension = tension } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(-holder.itemView.rootView.width.toFloat()) duration = removeDuration setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationX = -holder.itemView.rootView.width.toFloat() } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(0f) duration = addDuration setListener(DefaultAddAnimatorListener(holder)) interpolator = OvershootInterpolator(tension) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/OvershootInRightAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.OvershootInterpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class OvershootInRightAnimator : BaseItemAnimator { private val tension: Float constructor() { tension = 2.0f } constructor(tension: Float) { this.tension = tension } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(holder.itemView.rootView.width.toFloat()) duration = removeDuration setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationX = holder.itemView.rootView.width.toFloat() } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(0f) duration = addDuration interpolator = OvershootInterpolator(tension) setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/ScaleInAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class ScaleInAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(0f) scaleY(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.scaleX = 0f holder.itemView.scaleY = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(1f) scaleY(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/ScaleInBottomAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class ScaleInBottomAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotY = holder.itemView.height.toFloat() } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(0f) scaleY(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotY = holder.itemView.height.toFloat() holder.itemView.scaleX = 0f holder.itemView.scaleY = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(1f) scaleY(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/ScaleInLeftAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class ScaleInLeftAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotX = 0f } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(0f) scaleY(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotX = 0f holder.itemView.scaleX = 0f holder.itemView.scaleY = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(1f) scaleY(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/ScaleInRightAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class ScaleInRightAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotX = holder.itemView.width.toFloat() } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(0f) scaleY(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotX = holder.itemView.width.toFloat() holder.itemView.scaleX = 0f holder.itemView.scaleY = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(1f) scaleY(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/ScaleInTopAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class ScaleInTopAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotY = 0f } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(0f) scaleY(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.pivotY = 0f holder.itemView.scaleX = 0f holder.itemView.scaleY = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { scaleX(1f) scaleY(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/SlideInDownAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInDownAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(-holder.itemView.height.toFloat()) alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationY = -holder.itemView.height.toFloat() holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(0f) alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/SlideInLeftAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInLeftAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(-holder.itemView.rootView.width.toFloat()) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationX = -holder.itemView.rootView.width.toFloat() } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(0f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/SlideInRightAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInRightAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(holder.itemView.rootView.width.toFloat()) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationX = holder.itemView.rootView.width.toFloat() } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationX(0f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/SlideInUpAnimator.kt ================================================ package jp.wasabeef.recyclerview.animators import android.view.animation.Interpolator import androidx.recyclerview.widget.RecyclerView /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ open class SlideInUpAnimator : BaseItemAnimator { constructor() constructor(interpolator: Interpolator) { this.interpolator = interpolator } override fun animateRemoveImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(holder.itemView.height.toFloat()) alpha(0f) duration = removeDuration interpolator = interpolator setListener(DefaultRemoveAnimatorListener(holder)) startDelay = getRemoveDelay(holder) }.start() } override fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.translationY = holder.itemView.height.toFloat() holder.itemView.alpha = 0f } override fun animateAddImpl(holder: RecyclerView.ViewHolder) { holder.itemView.animate().apply { translationY(0f) alpha(1f) duration = addDuration interpolator = interpolator setListener(DefaultAddAnimatorListener(holder)) startDelay = getAddDelay(holder) }.start() } } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/animators/holder/AnimateViewHolder.kt ================================================ package jp.wasabeef.recyclerview.animators.holder import android.animation.Animator import androidx.recyclerview.widget.RecyclerView interface AnimateViewHolder { fun preAnimateAddImpl(holder: RecyclerView.ViewHolder) fun preAnimateRemoveImpl(holder: RecyclerView.ViewHolder) fun animateAddImpl(holder: RecyclerView.ViewHolder, listener: Animator.AnimatorListener) fun animateRemoveImpl( holder: RecyclerView.ViewHolder, listener: Animator.AnimatorListener ) } ================================================ FILE: animators/src/main/java/jp/wasabeef/recyclerview/internal/ViewHelper.kt ================================================ package jp.wasabeef.recyclerview.internal import android.view.View /** * Copyright (C) 2021 Daichi Furiya / Wasabeef * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ object ViewHelper { @JvmStatic fun clear(v: View) { v.apply { alpha = 1f scaleY = 1f scaleX = 1f translationY = 0f translationX = 0f rotation = 0f rotationY = 0f rotationX = 0f pivotY = v.measuredHeight / 2f pivotX = v.measuredWidth / 2f animate().setInterpolator(null).startDelay = 0 } } } ================================================ FILE: build.gradle ================================================ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { ext.kotlin_version = '1.3.72' repositories { google() jcenter() } dependencies { classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.5' classpath 'com.android.tools.build:gradle:4.2.0-beta04' classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" } } allprojects { repositories { google() mavenCentral() jcenter() } tasks.withType(Javadoc) { enabled = false } } ================================================ FILE: example/build.gradle ================================================ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion COMPILE_SDK_VERSION as int defaultConfig { minSdkVersion MIN_SDK_VERSION as int targetSdkVersion TARGET_SDK_VERSION as int versionCode VERSION_CODE as int versionName VERSION_NAME } // SigningConfigs apply from: '../signingConfigs/debug.gradle', to: android buildTypes { debug { debuggable true signingConfig signingConfigs.debug } release { debuggable false zipAlignEnabled true } } } repositories { // maven { url = "https://oss.sonatype.org/content/repositories/snapshots"} } dependencies { implementation project(':animators') implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" implementation "androidx.appcompat:appcompat:1.2.0" implementation "androidx.recyclerview:recyclerview:1.1.0" implementation 'com.squareup.picasso:picasso:2.8' } ================================================ FILE: example/src/main/AndroidManifest.xml ================================================ ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/AdapterSampleActivity.kt ================================================ package jp.wasabeef.example.recyclerview import android.content.Context import android.os.Bundle import android.view.View import android.view.animation.OvershootInterpolator import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Spinner import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import jp.wasabeef.recyclerview.adapters.AlphaInAnimationAdapter import jp.wasabeef.recyclerview.adapters.AnimationAdapter import jp.wasabeef.recyclerview.adapters.ScaleInAnimationAdapter import jp.wasabeef.recyclerview.adapters.SlideInBottomAnimationAdapter import jp.wasabeef.recyclerview.adapters.SlideInLeftAnimationAdapter import jp.wasabeef.recyclerview.adapters.SlideInRightAnimationAdapter import jp.wasabeef.recyclerview.animators.FadeInAnimator /** * Created by Daichi Furiya / Wasabeef on 2020/08/26. */ class AdapterSampleActivity : AppCompatActivity() { internal enum class Type { AlphaIn { override operator fun get(context: Context): AnimationAdapter { return AlphaInAnimationAdapter(MainAdapter(context, SampleData.LIST.toMutableList())) } }, ScaleIn { override operator fun get(context: Context): AnimationAdapter { return ScaleInAnimationAdapter(MainAdapter(context, SampleData.LIST.toMutableList())) } }, SlideInBottom { override operator fun get(context: Context): AnimationAdapter { return SlideInBottomAnimationAdapter(MainAdapter(context, SampleData.LIST.toMutableList())) } }, SlideInLeft { override operator fun get(context: Context): AnimationAdapter { return SlideInLeftAnimationAdapter(MainAdapter(context, SampleData.LIST.toMutableList())) } }, SlideInRight { override operator fun get(context: Context): AnimationAdapter { return SlideInRightAnimationAdapter(MainAdapter(context, SampleData.LIST.toMutableList())) } }; abstract operator fun get(context: Context): AnimationAdapter } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_adapter_sample) setSupportActionBar(findViewById(R.id.tool_bar)) supportActionBar?.setDisplayShowTitleEnabled(false) val recyclerView = findViewById(R.id.list) recyclerView.layoutManager = if (intent.getBooleanExtra(MainActivity.KEY_GRID, true)) { GridLayoutManager(this, 2) } else { LinearLayoutManager(this) } val spinner = findViewById(R.id.spinner) spinner.adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1).apply { for (type in Type.values()) add(type.name) } spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { recyclerView.adapter = Type.values()[position][view.context].apply { setFirstOnly(true) setDuration(500) setInterpolator(OvershootInterpolator(.5f)) } } override fun onNothingSelected(parent: AdapterView<*>) { // no-op } } recyclerView.itemAnimator = FadeInAnimator() val adapter = MainAdapter(this, SampleData.LIST.toMutableList()) recyclerView.adapter = AlphaInAnimationAdapter(adapter).apply { setFirstOnly(true) setDuration(500) setInterpolator(OvershootInterpolator(.5f)) } } } ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/AnimatorSampleActivity.kt ================================================ package jp.wasabeef.example.recyclerview import android.os.Bundle import android.view.View import android.widget.AdapterView import android.widget.ArrayAdapter import android.widget.Spinner import androidx.appcompat.app.AppCompatActivity import androidx.recyclerview.widget.GridLayoutManager import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import jp.wasabeef.recyclerview.animators.BaseItemAnimator import jp.wasabeef.recyclerview.animators.FadeInAnimator import jp.wasabeef.recyclerview.animators.FadeInDownAnimator import jp.wasabeef.recyclerview.animators.FadeInLeftAnimator import jp.wasabeef.recyclerview.animators.FadeInRightAnimator import jp.wasabeef.recyclerview.animators.FadeInUpAnimator import jp.wasabeef.recyclerview.animators.FlipInBottomXAnimator import jp.wasabeef.recyclerview.animators.FlipInLeftYAnimator import jp.wasabeef.recyclerview.animators.FlipInRightYAnimator import jp.wasabeef.recyclerview.animators.FlipInTopXAnimator import jp.wasabeef.recyclerview.animators.LandingAnimator import jp.wasabeef.recyclerview.animators.OvershootInLeftAnimator import jp.wasabeef.recyclerview.animators.OvershootInRightAnimator import jp.wasabeef.recyclerview.animators.ScaleInAnimator import jp.wasabeef.recyclerview.animators.ScaleInBottomAnimator import jp.wasabeef.recyclerview.animators.ScaleInLeftAnimator import jp.wasabeef.recyclerview.animators.ScaleInRightAnimator import jp.wasabeef.recyclerview.animators.ScaleInTopAnimator import jp.wasabeef.recyclerview.animators.SlideInDownAnimator import jp.wasabeef.recyclerview.animators.SlideInLeftAnimator import jp.wasabeef.recyclerview.animators.SlideInRightAnimator import jp.wasabeef.recyclerview.animators.SlideInUpAnimator /** * Created by Daichi Furiya / Wasabeef on 2020/08/26. */ class AnimatorSampleActivity : AppCompatActivity() { internal enum class Type(val animator: BaseItemAnimator) { FadeIn(FadeInAnimator()), FadeInDown(FadeInDownAnimator()), FadeInUp(FadeInUpAnimator()), FadeInLeft(FadeInLeftAnimator()), FadeInRight(FadeInRightAnimator()), Landing(LandingAnimator()), ScaleIn(ScaleInAnimator()), ScaleInTop(ScaleInTopAnimator()), ScaleInBottom(ScaleInBottomAnimator()), ScaleInLeft(ScaleInLeftAnimator()), ScaleInRight(ScaleInRightAnimator()), FlipInTopX(FlipInTopXAnimator()), FlipInBottomX(FlipInBottomXAnimator()), FlipInLeftY(FlipInLeftYAnimator()), FlipInRightY(FlipInRightYAnimator()), SlideInLeft(SlideInLeftAnimator()), SlideInRight(SlideInRightAnimator()), SlideInDown(SlideInDownAnimator()), SlideInUp(SlideInUpAnimator()), OvershootInRight(OvershootInRightAnimator(1.0f)), OvershootInLeft(OvershootInLeftAnimator(1.0f)) } private val adapter = MainAdapter(this, SampleData.LIST.toMutableList()) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_animator_sample) setSupportActionBar(findViewById(R.id.tool_bar)) supportActionBar?.setDisplayShowTitleEnabled(false) val recyclerView = findViewById(R.id.list) recyclerView.apply { itemAnimator = SlideInLeftAnimator() adapter = this@AnimatorSampleActivity.adapter layoutManager = if (intent.getBooleanExtra(MainActivity.KEY_GRID, true)) { GridLayoutManager(context, 2) } else { LinearLayoutManager(context) } } val spinner = findViewById(R.id.spinner) val spinnerAdapter = ArrayAdapter(this, android.R.layout.simple_list_item_1) for (type in Type.values()) { spinnerAdapter.add(type.name) } spinner.adapter = spinnerAdapter spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) { recyclerView.itemAnimator = Type.values()[position].animator recyclerView.itemAnimator?.addDuration = 500 recyclerView.itemAnimator?.removeDuration = 500 } override fun onNothingSelected(parent: AdapterView<*>) { // no-op } } findViewById(R.id.add).setOnClickListener { adapter.add("newly added item", 1) } findViewById(R.id.del).setOnClickListener { adapter.remove(1) } } } ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/MainActivity.kt ================================================ package jp.wasabeef.example.recyclerview import android.content.Intent import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.widget.SwitchCompat /** * Created by Daichi Furiya / Wasabeef on 2020/08/26. */ class MainActivity : AppCompatActivity() { companion object { const val KEY_GRID = "GRID" } private var enabledGrid = false override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) findViewById(R.id.btn_animator_sample).setOnClickListener { startActivity(Intent(this, AnimatorSampleActivity::class.java).apply { putExtra(KEY_GRID, enabledGrid) }) } findViewById(R.id.btn_adapter_sample).setOnClickListener { startActivity(Intent(this, AdapterSampleActivity::class.java).apply { putExtra(KEY_GRID, enabledGrid) }) } findViewById(R.id.grid).setOnCheckedChangeListener { _, isChecked -> enabledGrid = isChecked } } } ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/MainAdapter.kt ================================================ package jp.wasabeef.example.recyclerview import android.content.Context import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.ImageView import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.squareup.picasso.Picasso /** * Created by Daichi Furiya / Wasabeef on 2020/08/26. */ class MainAdapter(private val context: Context, private val dataSet: MutableList) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val v = LayoutInflater.from(context).inflate(R.layout.layout_list_item, parent, false) return ViewHolder(v) } override fun onBindViewHolder(holder: ViewHolder, position: Int) { Picasso.get().load(R.drawable.chip).into(holder.image) holder.text.text = dataSet[position] } override fun getItemCount(): Int { return dataSet.size } fun remove(position: Int) { dataSet.removeAt(position) notifyItemRemoved(position) } fun add(text: String, position: Int) { dataSet.add(position, text) notifyItemInserted(position) } class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { var image: ImageView = itemView.findViewById(R.id.image) as ImageView var text: TextView = itemView.findViewById(R.id.text) as TextView } } ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/MyAnimationAdapter.kt ================================================ package jp.wasabeef.example.recyclerview import androidx.recyclerview.widget.RecyclerView import jp.wasabeef.recyclerview.adapters.AlphaInAnimationAdapter class MyAnimatorAdapter constructor( adapter: RecyclerView.Adapter, from: Float = 0.5f ) : AlphaInAnimationAdapter(adapter, from) { } ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/MyAnimator.kt ================================================ package jp.wasabeef.example.recyclerview import android.view.animation.Interpolator import androidx.interpolator.view.animation.LinearOutSlowInInterpolator import jp.wasabeef.recyclerview.animators.ScaleInRightAnimator class MyAnimator( interpolator: Interpolator = LinearOutSlowInInterpolator() ) : ScaleInRightAnimator(interpolator) { } ================================================ FILE: example/src/main/java/jp/wasabeef/example/recyclerview/SampleData.kt ================================================ package jp.wasabeef.example.recyclerview /** * Created by Daichi Furiya / Wasabeef on 2020/08/26. */ interface SampleData { companion object { val LIST = arrayOf( "Apple", "Ball", "Camera", "Day", "Egg", "Foo", "Google", "Hello", "Iron", "Japan", "Coke", "Dog", "Cat", "Yahoo", "Sony", "Canon", "Fujitsu", "USA", "Nexus", "LINE", "Haskell", "C++", "Java", "Go", "Swift", "Objective-c", "Ruby", "PHP", "Bash", "ksh", "C", "Groovy", "Kotlin", "Chip", "Japan", "U.S.A", "San Francisco", "Paris", "Tokyo", "Silicon Valley", "London", "Spain", "China", "Taiwan", "Asia", "New York", "France", "Kyoto", "Android", "Google", "iPhone", "iPad", "iPod", "Wasabeef" ) } } ================================================ FILE: example/src/main/res/layout/activity_adapter_sample.xml ================================================ ================================================ FILE: example/src/main/res/layout/activity_animator_sample.xml ================================================ ================================================ FILE: example/src/main/res/layout/activity_main.xml ================================================