Gesture Recycler


Source link: https://github.com/thesurix/gesture-recycler

Gesture Recycler

This library provides swipe & drag and drop support for RecyclerView. Based on great example from Android-ItemTouchHelper-Demo.

Demo

Features

  • item click/long press/double tap listener
  • empty view
  • undo
  • swipe
  • long press drag
  • manual mode drag
  • support for different layout managers
  • predefined drag & swipe flags for RecyclerView's layout managers
  • DiffUtil feature

Dependency

To use this library in your android project, just simply add the following dependency into your build.gradle

dependencies {

  compile 'com.thesurix.gesturerecycler:gesture-recycler:1.4.1' 
}

How to use?

// Define your RecyclerView and adapter as usually final LinearLayoutManager manager = new LinearLayoutManager(getContext());
 recyclerView.setHasFixedSize(true);
 recyclerView.setLayoutManager(manager);
  // Extend GestureAdapter and write your own // ViewHolder items must extend GestureViewHolder final MonthsAdapter adapter = new MonthsAdapter(getContext(), R.layout.linear_item);
 adapter.setData(getMonths());
 recyclerView.setAdapter(adapter);

Swipe and drag & drop support:

GestureManager gestureManager = new GestureManager.Builder(mRecyclerView)

// Enable swipe

  .setSwipeEnabled(true)

// Enable long press drag and drop 

  .setLongPressDragEnabled(true)

// Enable manual drag from the beginning, you need to provide View inside your GestureViewHolder

  .setManualDragEnabled(true)

// Use custom gesture flags

// Do not use this method if you want predefined flags for RecyclerView layout manager 

  .setSwipeFlags(ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT)

  .setDragFlags(ItemTouchHelper.UP | ItemTouchHelper.DOWN)

  .build();

Data callbacks:

adapter.setDataChangeListener(new GestureAdapter.OnDataChangeListener<MonthItem>() {

 @Override

 public void onItemRemoved(final MonthItem item, final int position) {

 
}

  @Override

 public void onItemReorder(final MonthItem item, final int fromPos, final int toPos) {

 
}

}
);

Data animations:

// Support for data animations adapter.add(month);
 adapter.insert(month, 5);
 adapter.remove(5);
  // or adapter.setData(months, diffUtilCallback)  // This will interrupt pending animations adapter.setData(months) 

Item click events:

// Attach DefaultItemClickListener or implement RecyclerItemTouchListener.ItemClickListener recyclerView.addOnItemTouchListener(new RecyclerItemTouchListener<>(new DefaultItemClickListener<CustomItem>() {

 @Override

 public boolean onItemClick(final CustomItem item, final int position) {

  // return true if the event is consumed

  return false;

 
}

  @Override

 public void onItemLongPress(final CustomItem item, final int position) {

 
}

  @Override

 public boolean onDoubleTap(final CustomItem item, final int position) {

  // return true if the event is consumed

  return false;

 
}

}
));

Empty view:

<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView

android:id="@+id/recycler_view"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

 <!-- Define your empty view in layout -->
  <TextView

android:id="@+id/empty_view"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:textAppearance="@android:style/TextAppearance.Large"

android:text="No data"/> </FrameLayout>
// Pass null to disable empty view final View emptyView = view.findViewById(R.id.empty_view);
 adapter.setEmptyView(emptyView);

Undo:

// Undo last data transaction (add, insert, remove, swipe, reorder) adapter.undoLast();
  // Set undo stack size adapter.setUndoSize(2);

Help

See examples.

To do

  • background view for swipeable items
  • tests?

Licence

Copyright 2016 thesurix  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. 

Resources

A simple and easy to use API to integrate EarthView with Google into your android application.

An easy open source Android game engine.

Generates fake data for testing or populating a development database. Run your tests with realistic data like names, emails, dates, countries.

WeekCalendar is a library which provides a weekly calendar.

A simple multi-state toggle button for Android.

A library to work with Spannable.

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