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

A lightweight dependency injection framework for Android.

Inspired by MiniGuice and RoboGuice.

Dedicated iOS & Android simulators in the browser.

Thin wrapper for managing periodic sync with ContentResolver.

Just another logging framework. Multiple combinable logging classes. Combine local logging with rolling file logging with Crashlytics with NewRelic...

Android UI Automator to JUnit Format Converter.

Reads Android UI automator file outout and write a JUNIT Xml file. For example for usage in CI server as Jenkins.

Write less code! Don't inflate views, menus, preferences manually anymore!

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