RvTools


Source link: https://github.com/olmur/rvtools

RvTools

Add lib to your project

compile ('com.olmur.rvtools:rvtools:0.0.5') {

exclude group: 'com.android.support' 
}

Extend RvtRecyclerAdapter class

public class MyAdapter extends RvtListAdapter<MyEntity, MyViewHolder> {

... 
}

Create ViewHolder that extends RvtViewHolder

public class MyViewHolder extends RvtRecyclerAdapter.RvtViewHolder<MyEntity> {

 private TextView titleTv;

 ViewHolder(@NonNull View view) {

 super(view);

 titleTv = (TextView) view.findViewById(R.id.title_tv);

}

 @Override

public void bindViewHolder(MyEntity element) {

 titleTv.setText(element.getTitle());

}
 
}

Create Gestures Listeners

public class MainActivity extends AppCompatActivity implements OnSwipeLeftAction, OnSwipeRightAction, OnOrderChangedListener {

@Override
  public void onSwipeLeftAction(int position) {

adapter.deletItem(position);

  
}

 @Override
  public void onSwipeRightAction(int position) {

adapter.changeItem(position);

  
}

 @Override
  public void onOrderChanged() {

Snackbar.make(root, "Order has been changed", Snackbar.LENGTH_SHORT).show();

  
}
 
}

Create Swipe Context Menu Drawer:

You can use RvtSwipeContextMenu

RvtSwipeContextMenu rvtSwipeContextMenu = new RvtSwipeContextMenu.Builder(context)

 .withIconsRes(R.drawable.ic_edit, R.drawable.ic_delete)

 .withIconsSizeDp(32)

 .withIconsMarginFromListEdgesDp(16)

 .withIconsColorInt(Color.WHITE)

 .withBackgroundsColorsInt(Color.MAGENTA, Color.RED)

 .build();

Or create your own swipe context menu by implementing SwipeContextMenuDrawer interface

To add different behaviour on item select/release override these methods in your ViewHolder

 public class MyViewHolder extends RvtViewHolder<MyEntity> {

 ...

 @Override

public void onSelected() {

 super.onSelected();

 itemView.setBackgroundColor(Color.GRAY);

 titleTv.setTextColor(Color.WHITE);

}

 @Override

public void onReleased() {

 super.onReleased();

 itemView.setBackgroundColor(Color.WHITE);

 titleTv.setTextColor(Color.GRAY);

}

// Provide selected vh height for elevation increase/decrease when vh is being selected/released.

// Works only API 21 and above only.

@Override

public int selectedVhHeightDp() {

 return RvtUtils.Resources.dpToPixels(itemView.getContext(), 8);

}
  
}

Create RvtRecyclerView and provide it with empty view

RvtRecyclerView recyclerView = (RvtRecyclerView) findViewById(R.id.rvt_recycler_view);
 recyclerView.setEmptyView(emptyView);

Create RvTools for your RecyclerView

  RvTools rvtools = new RvTools

  .Builder(recyclerView)

  .withSwipeRightAction(this)

  .withSwipeLeftAction(this)

  .withMoveAction(this, RvTools.DOWN, RvTools.UP)

  .withSwipeContextMenuDrawer(rvtSwipeContextMenu)

  .build();

Than you can bind and unbind rvtools from your recycler view

rvtools.bind(recyclerView);

  rvtools.unbind();

Check out for more examples in sample app.

Resources

Theo is a Gradle plugin that provides annotations for each "dangerous android permission".

Customized toggle button.

Cicerone is a lightweight library that makes the navigation in an Android app easy.

Custom view to pick up a value from a given range using click button or swiping.

ImageMap is a small android library for displaying multiple image on a view using an adapter, you can then retrieve tap event on defined image.

SpannableBar is a Grid-style spannable bar, that is useful when you need a way to span a bar over columns. The view allows you to set the starting column, the span, the number of columns, and more.

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