Check this project on dribbble
Read how we did it on our blog
##Requirements
- Android SDK 16+
##Usage
Add to your root build.gradle:
allprojects{repositories{... maven{url "https://jitpack.io" } } }Add the dependency:
dependencies{compile 'com.github.yalantis:todolist:v1.0.1' }Add BatRecyclerView to your xml layout
<?xml version="1.0" encoding="utf-8"?> <LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/apk/res-auto"android:id="@+id/root"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@drawable/gradient"android:orientation="vertical"> <android.support.v7.widget.Toolbar android:id="@+id/toolbar"android:layout_width="match_parent"android:layout_height="?android:attr/actionBarSize"android:background="@android:color/transparent"app:logo="@drawable/ic_menu"> <TextViewandroid:id="@+id/text_title"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center"android:text="14 Feb, 2016"android:textColor="@android:color/white"android:textSize="20sp" /> </android.support.v7.widget.Toolbar> <com.yalantis.beamazingtoday.ui.widget.BatRecyclerView android:id="@+id/bat_recycler_view"android:layout_width="match_parent"android:layout_height="match_parent"android:layout_gravity="center_horizontal"app:add_button_color="@drawable/selector_button_add"app:hint="@string/str_add_goal"app:radio_button_res="@drawable/selector_radio_button" /> </LinearLayout>Create BatListener
privateBatListenermListener = newBatListener(){@Overridepublicvoidadd(Stringstring){mGoals.add(0, newGoal(string)); mAdapter.notify(AnimationType.ADD, 0)} @Overridepublicvoiddelete(intposition){mGoals.remove(position); mAdapter.notify(AnimationType.REMOVE, position)} @Overridepublicvoidmove(intfrom, intto){if (from >= 0 && to >= 0){//if you use 'BatItemAnimator'mAnimator.setPosition(to); BatModelmodel = mGoals.get(from); mGoals.remove(model); mGoals.add(to, model); mAdapter.notify(AnimationType.MOVE, from, to); if (from == 0 || to == 0){mRecyclerView.getView().scrollToPosition(Math.min(from, to))} } } };Create BatAdapter. Pass to its constructor list of models and BatListener. Note that your model should implement BatModel interface
mAdapter = newBatAdapter(mGoals = newArrayList<BatModel>(){{add(newGoal("first")); add(newGoal("second")); add(newGoal("third")); add(newGoal("fourth")); add(newGoal("fifth")); add(newGoal("sixth")); add(newGoal("seventh")); add(newGoal("eighth")); add(newGoal("ninth")); add(newGoal("tenth"))}}, mListener); mAdapter.setOnItemClickListener(newOnItemClickListener(){@OverridepublicvoidonClick(BatModelitem, intposition){Toast.makeText(ExampleActivity.this, item.getText(), Toast.LENGTH_SHORT).show()} });Initialize your recycler view
mRecyclerView.getView().setLayoutManager(newLinearLayoutManager(this)); mRecyclerView.getView().setAdapter(mAdapter); ItemTouchHelperitemTouchHelper = newItemTouchHelper(newBatCallback(this)); itemTouchHelper.attachToRecyclerView(mRecyclerView.getView()); mRecyclerView.setAddItemListener(mListener);You can use BatItemAnimator to animate list items just like in our demo:
mAnimator = newBatItemAnimator(); mAdapter = newBatAdapter(mGoals = newArrayList<BatModel>(){{add(newGoal("first")); add(newGoal("second")); add(newGoal("third")); add(newGoal("fourth")); add(newGoal("fifth")); add(newGoal("sixth")); add(newGoal("seventh")); add(newGoal("eighth")); add(newGoal("ninth")); add(newGoal("tenth"))}}, mListener, mAnimator); mRecyclerView.getView().setItemAnimator(mAnimator);You need to pass the animator instance to BatRecyclerView and to BatAdapter. Also it's necessary to pass the position of the moved item in move() callback:
@Overridepublicvoidmove(intfrom, intto){if (from >= 0 && to >= 0){mAnimator.setPosition(to); BatModelmodel = mGoals.get(from); mGoals.remove(model); mGoals.add(to, model); mAdapter.notify(AnimationType.MOVE, from, to); if (from == 0 || to == 0){mRecyclerView.getView().scrollToPosition(Math.min(from, to))} } }For more usage examples please review sample app
- Cursor fixed.
cursor_drawableattribute andsetCursorDrawable(@DrawableRes int res)method added. Should be used instead ofcursor_colorattribute andsetCursorColor(@ColorInt int color)method respectively
We’d be really happy if you could send us links to your projects where you use our component. Just send an email to [email protected] And do let us know if you have any questions or suggestion regarding the animation.
P.S. We’re going to publish more awesomeness wrapped in code and a tutorial on how to make UI for iOS (Android) better than better. Stay tuned!
The MIT License (MIT) Copyright © 2016 Yalantis, https://yalantis.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 

