Click-Drag-Swipe (CDS) RecyclerView


Source link: https://github.com/GauravChaddha1996/CDSRecyclerView

Click-Drag-Swipe (CDS) RecyclerView

Recycler View Library with built-in Item click listeners,drag and swipe functionality.

Description

CDS Recycler View is a recycler view with item click, item long press, drag, swipe and load more listener functionality.

It provides setter functions for item clicks, item long press, drag complete listeners( listener called when drag of an item completes),swipe complete listeners( listeners called when an item is swiped off) and setter and removal functions for load more listener. It also provide add and remove built-in functions for the recycler view adapter.

Min Sdk = 16

Gradle Usage

Add it in your root build.gradle at the end of repositories:

allprojects {

repositories {

  ...
  maven {
 url "https://jitpack.io" 
}

 
}
 
}
 

Step 2. Add the dependency

dependencies {

compile 'com.github.GauravChaddha1996:CDSRecyclerView:1.5' 
}
 

Usage

Drag and swipe functionality is disabled by defualt.Use the enable functions to add them after recycler view initialization

Without extending CdsRecyclerViewAdapter the drag and swipe functionality won't be present

Include the CdsRecyclerView in your layout:

<com.gaurav.cdsrecyclerview.CdsRecyclerView
  android:id="@+id/recyclerView"
  android:layout_width="match_parent"
  android:layout_height="match_parent">  </com.gaurav.cdsrecyclerview.CdsRecyclerView> 

Create a recycler view adapter extending CdsRecyclerViewAdapter to get add, remove, drag and swipe functionality.

(Note: Without extending CdsRecyclerViewAdapter the drag and swipe functionality won't be present)

  public class RecyclerViewAdapter extends CdsRecyclerViewAdapter<String, RecyclerViewAdapter.MyViewHolder> {

private Context mContext;

public RecyclerViewAdapter(Context context, List<String> list) {

 super(context, list);

 mContext = context;

}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

 return new MyViewHolder(LayoutInflater.from(mContext).inflate(R.layout.your_item_layout, parent, false));

}

// note that we override the bindHolder custom function to get back the
// custom view holder instead of the usual onBindViewHolder()
@Override
public void bindHolder(MyViewHolder holder, int position) {

 holder.mTextView.setText(getList().get(position));

}

 public class MyViewHolder extends RecyclerView.ViewHolder {

 TextView mTextView;

  public MyViewHolder(View itemView) {

  super(itemView);

  mTextView = (TextView) itemView.findViewById(R.id.item_recycler_view_text);

 
}

}
 
}
 

Initialize the Cdsrecycler view as you would for a normal recycler view

mRecyclerView = new CdsRecyclerView(this);
 mRecyclerView = (CdsRecyclerView) findViewById(R.id.recyclerView);
 mRecyclerView.setHasFixedSize(true);
 mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
 //or any other layout manager 

Set the Adapter

mRecyclerViewAdapter = new RecyclerViewAdapter(this, getData());
 mRecyclerView.setAdapter(mRecyclerViewAdapter);
 

Setting on item click,long press, drag, swipe and load more listener functionality

mRecyclerView.setItemClickListener(new CdsRecyclerView.ItemClickListener() {

@Override

public void onItemClick(int position) {

 Toast.makeText(MainActivity.this, "Item Clicked:" +

mRecyclerViewAdapter.getItem(position), Toast.LENGTH_SHORT).show();

}

  
}
);

mRecyclerView.setItemLongPressListener(new CdsRecyclerView.ItemLongPressListener() {

@Override

public void onItemLongClick(int position) {

Toast.makeText(MainActivity.this, "Item Long Clicked:" +

mRecyclerViewAdapter.getItem(position), Toast.LENGTH_SHORT).show();

  
}

  
}
);

mRecyclerView.enableItemSwipe();
 mRecyclerView.enableItemDrag();
 mRecyclerView.setOnLoadMoreListener(new CdsRecyclerView.LoadMoreListener() {

  @Override

  public void onLoadMore() {

// do your loading here, maybe show a progress bar before loading after loading is done,
  // remove the progress bar and remember to do the following- Set the loading in recycler
  // view as false
  mRecyclerView.setLoading(false);

  //You can remove the load more listener like this
  mRecyclerView.removeOnLoadMoreListener();

  
}

 
}
, 5);
 

Features and functions

1.Set and disable item click listeners

  • Function to set:
mRecyclerView.setItemClickListener(new CdsRecyclerView.ItemClickListener() {

@Override

public void onItemClick(int position) {

 Toast.makeText(MainActivity.this, "Item Clicked:" +

mRecyclerViewAdapter.getItem(position), Toast.LENGTH_SHORT).show();

}

  
}
);
 
  • Function to disable :
mRecyclerView.disableItemClick();
 

2.Set and disable item long press

  • Function to set:
mRecyclerView.setItemLongPressListener(new CdsRecyclerView.ItemLongPressListener() {

@Override

public void onItemLongClick(int position) {

Toast.makeText(MainActivity.this, "Item Long Clicked:" +

mRecyclerViewAdapter.getItem(position), Toast.LENGTH_SHORT).show();

  
}

  
}
);
 
  • Function to disable :
mRecyclerView.disableItemLongPress();
 

3.Enable and disable drag

  • Enable drag:

      mRecyclerView.enableItemDrag();
     
  • Disable drag:

    mRecyclerView.disableItemDrag();
    
    

4.Enable and disable swipe

  • Enable swipe:

    mRecyclerView.enableItemSwipe();
     
  • Disable swipe:

    mRecyclerView.disableItemSwipe() 

5.Set and remove drag complete listener

  • Set drag complete listener:

     mRecyclerView.setItemDragCompleteListener( new CdsItemTouchCallback.ItemDragCompleteListener() {
    
     @Override
    
     public void onItemDragComplete(int fromPosition, int toPosition) {
    
      Toast.makeText(MainActivity.this, "Item dragged from " + fromPosition +
    
     " to " + toPosition, Toast.LENGTH_SHORT).show();
    
     
    }
    
    }
    );
     
  • Remove drag complete listener:

     mRecyclerView.removeItemDragCompleteListener();
     

6.Enable and disable swipe complete listener

  • Set swipe complete listener:

      mRecyclerView.setItemSwipeCompleteListener(new CdsItemTouchCallback.ItemSwipeCompleteListener() {
    
     @Override
    
     public void onItemSwipeComplete(int position) {
    
      Toast.makeText(MainActivity.this, "Item was swiped:" + position,
    
     Toast.LENGTH_SHORT).show();
    
     
    }
    
    }
    );
     
  • Remove swipe complete listener:

    mRecyclerView.removeItemSwipeCompleteListener();
     

7.Set or remove on load more listener

  • Set load more listener:

      mRecyclerView.setOnLoadMoreListener(new CdsRecyclerView.LoadMoreListener() {
    
    @Override
    
    public void onLoadMore() {
    
     // do your loading here, maybe show a progress bar before loading
    // after loading is done, remove the progress bar and remember to do the
    // following-
    // Set the loading in recycler view as false
    mRecyclerView.setLoading(false);
    
    }
    
      
    }
    , 5);
     
  • Remove load more listener:

    mRecyclerView.removeOnLoadMoreListener();
     

License

Copyright 2016-present Gaurav Chaddha  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

The recommended pattern for Android's equivalent to cron jobs and Windows scheduled tasks is to use AlarmManager. This works well when coupled with an IntentService, as the service will do its work on a background thread and shut down when there is no more work to do.

There's one small problem: IntentService does nothing to keep the device awake. If the alarm was a WAKEUP variant, the phone will only stay awake on its own while the BroadcastReceiver handling the alarm is in its onReceive() method. Otherwise, the phone may fall back asleep.

WakefulIntentService attempts to combat this by combining the ease of IntentService with a partial WakeLock.

ViewPager with custom aspect ratio.

Design template library for LG QCircle SDK.

Tooleap is an Android SDK which brings your app to the forefront of a user's device screen with a floating (always-on-top) UI, thus creating a unique multitasking experience and increasing your app's availability and usability.

Sample Of All Samples

With your help we can build a sample app that touches most components of the Android framework, helpful for beginners and experienced.

The CurtainView is much like a layer on the top level of your layout. It's also a container which can wrap other Views.

It will not block the actions of the child view unless you make a standard pull event.

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