DragSortAdapter


Source link: https://github.com/vinc3m1/DragSortAdapter

DragSortAdapter

Drag and Drop adapter implementation for RecyclerView. Targeted to support any LayoutManager and ItemAnimator.

Note: This is an advanced library meant to be flexible and customizable which leads to more complexity in integration. It is not meant to be a simple drop-in. If you need even more customization I suggest exploring the source and copying relevant code that you need.

Usage

Add Snapshot repository and add to dependencies:

dependencies {

compile 'com.makeramen:dragsortadapter:X.X.X' 
}
 

Override DragSortAdapter<T extends DragSortAdapter.ViewHolder>, see ExampleAdapter.java: required functions:

// this function should be reasonable performant as it gets called a lot on the UI thread public abstract int getPositionForId(long id);

 // this needs to re-order the positions **live** during dragging public abstract boolean move(int fromPosition, int toPosition);
  // not required but you probably want to override this to save the re-ordering after drop event public void onDrop() {
 
}

Set adapter in code:

recyclerView.setAdapter(new ExampleAdapter(recyclerView));

Call startDrag() when you want to start dragging (e.g. onLongClick):

 @Override public boolean onLongClick(@NonNull View v) {

 startDrag();

 return true;
  
}

Works with any LayoutManager

recyclerView.setLayoutManager(new LinearLayoutManager(this));
 recyclerView.setLayoutManager(new GridLayoutManager(this, 3));
 recyclerView.setLayoutManager(new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL));

And any ItemAnimator:

recyclerView.setItemAnimator(new DefaultItemAnimator());

Resources

This is a simple and elegant menu control.

Error handling library for Android and Java.

Confetti is a high-performance, easily-configurable particle system library that can animate any set of objects through space. You can specify your starting conditions and physical conditions (e.g. X and Y acceleration, boundaries, etc.), and let the confetti library take care of the rest.

Library to convert between RxJava 1.x and 2.x reactive types.

An A/B Testing Library for Android that makes writing simple tests simpler by using annotations.

CannyViewAnimator is an enhanced version of ViewAnimator. It allows to use Animators and Transitions to extend Visibility. The logic is taken from ViewAnimator of the Android SDK. ViewAnimator allows only one child to be visible at a time. Setting another child to be visible causes the previous child to become invisible. This switching occurs with animation.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes