DynamicPagerAdapter


Source link: https://github.com/QuarkWorks/DynamicPagerAdapter-Android

DynamicPagerAdapter

The DynamicPagerAdapter extends Android's PagerAdapter to do four important things:

  • Has an accessible HashMap View cache using ViewHolders. The default implementaiton has caching, but it isn't enforced and users of the PagerAdapter don't get access to it.

  • Provides the capability to use multiple view types just like RecyclerView.

  • Handles data set changes in a much more friendly way, allowing items to be removed, added, etc. with less issues and effort on your end.

  • Includes optional discard animations. These are exposed for you to call when you want or to override and create your own.

MyPagerAdapter.java

public class MyPagerAdapter extends DynamicPagerAdapter {

private List<Integer> values;

public PagerAdapter(List<Integer> values) {

this.values = values;
  
}

@Override
  public ViewHolder onCreateViewHolder(ViewGroup container, int position, int viewType) {

final PagerCardView pagerCardView = new PagerCardView(container.getContext());

return new ViewHolder(pagerCardView) {

}
;
  
}

@Override
  public void onBindViewHolder(ViewHolder viewHolder, int position) {

PagerCardView pagerCardView = (PagerCardView) viewHolder.view;

pagerCardView.setViewData(values.get(position));

  
}

@Override
  public int getCount() {

return values.size();

  
}

public void updateValues(List<Integer> values) {

this.values = values;

notifyDataSetChanged();

  
}
 
}

SinglePagerActivity.java

 private MyPagerAdapter pagerAdapter;
  private List<Integer> values;

@Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.pager_activity);

 ViewPager viewPager = (ViewPager) findViewById(R.id.pager_activity_view_pager);

 pagerAdapter = new MyPagerAdapter(values);

viewPager.setAdapter(pagerAdapter);

 pagerAdapter.setCallbacks(new Callbacks() {

 @Override

 public void onDiscardFinished(int position, View view) {

  if (position != NO_POSITION) {

values.remove(position);

pagerAdapter.updateData(values);

  
}

 
}

}
);

  
}

SwipeRemovalViewPager

This ViewPager subclass leverages the DynamicPagerAdapter to call fold animations on the View set after the user flings a pager View off the screen (up or down) or performs a drag-and-drop over a certain distance. It also adds helper methods for retrieving the current View from the DynamicPagerAdapter cache, among other things.

Once you have the DynamicPagerAdapter set up, using the DynamicViewPager is as easy as changing the ViewPager reference in XML to SwipeRemovalViewPager.

<com.quarkworks.dynamicviewpager.SwipeRemovalViewPager

 android:layout_width="match_parent"

 android:layout_height="match_parent"

 ...

 />

PagerContainer

This is a layout wrapper for ViewPagers that we have modified over the years. It passes touch events to the child ViewPager, allowing you to make the ViewPager whatever size you want while still accepting touches from larger areas.

Including with Gradle

  1. Add the JitPack repository center to your project build.gradle:
allprojects {

repositories {

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

}

  
}
 
}
 
  1. Add the dependency to your app build.gradle:
dependencies {

  compile 'com.github.QuarkWorks:DynamicPagerAdapter-Android:0.9.6' 
}
 

Resources

Performance metrics library for Android development (including dagger2metrics).

A simple Android color picker library.

LumberJill is a logging Utility library for Android.

CurrencyEditText is an extension of Android's EditText view object. It is a module designed to provide ease-of-use when using an EditText field for gathering currency information from a user.

A simple spinner for Android with Material Design.

This library allows you to listen to SwipeRefreshLayout start, cancel and finish events.

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