recycler-pager-adaper


Source link: https://github.com/henrytao-me/recycler-pager-adapter

recycler-pager-adaper

Recycling mechanism for pager adapter

Installation

compile "me.henrytao:recycler-pager-adapter:<latest-version>"

recycler-pager-adapter is deployed to jCenter. Make sure you have jcenter() in your project gradle.

Idea

  • Apply RecyclerView mechanism for PagerAdapter.
  • Use View instead of Fragment for improving performance.
  • Fix onDataSetChanged issue with PagerAdapter.

Usage

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
 <android.support.v7.widget.Toolbar
  android:id="@+id/toolbar"
  style="@style/AppStyle.MdToolbar" />
 <android.support.v4.view.ViewPager
  android:id="@+id/view_pager"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:layout_below="@+id/toolbar" /> </RelativeLayout>
mPagerAdapter = new PagerAdapter();
 vViewPager.setAdapter(mPagerAdapter);
public class PagerAdapter extends RecyclerPagerAdapter<RecyclerPagerAdapter.ViewHolder> {

 private List<Type> mData;
 public PagerAdapter() {

  mData = new ArrayList<>();

  mData.add(Type.LOADING);

  for (int i = 0; i < 50; i++) {

 mData.add(Type.ITEM);

  
}

}

 @Override
public int getItemCount() {

  return mData.size();

}

 @Override
public int getItemViewType(int position) {

  return mData.get(position).getValue();

}

 @Override
public void onBindViewHolder(RecyclerPagerAdapter.ViewHolder holder, int position) {

  if (holder instanceof ItemViewHolder) {

 ((ItemViewHolder) holder).bind(position);

  
}

}

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

  if (Type.valueOf(viewType) == Type.LOADING) {

 return new LoadingViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_loading, parent, false), v -> {

mData.remove(0);

notifyDataSetChanged();

 
}
);

  
}
 else {

 return new ItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_pager, parent, false));

  
}

}

 public enum Type {

  LOADING(0), ITEM(1);

public static Type valueOf(int value) {

 if (value == 0) {

return LOADING;

 
}
 else if (value == 1) {

return ITEM;

 
}

 return null;
  
}

private final int mValue;

Type(int value) {

 mValue = value;
  
}

public int getValue() {

 return mValue;
  
}

}

 public static class ItemViewHolder extends RecyclerPagerAdapter.ViewHolder {

@Bind(R.id.text) TextView vText;

public ItemViewHolder(View itemView) {

 super(itemView);

 ButterKnife.bind(this, itemView);

  
}

public void bind(int position) {

 vText.setText(String.format(Locale.US, "Pager %d", position));

  
}

}

 public static class LoadingViewHolder extends RecyclerPagerAdapter.ViewHolder {

public LoadingViewHolder(View itemView, View.OnClickListener onClickListener) {

 super(itemView);

 itemView.setOnClickListener(onClickListener);

  
}

}
 
}

Contributing

Any contributions are welcome!
Please check the CONTRIBUTING guideline before submitting a new PR.

License

Copyright 2015 "Henry Tao <[email protected]>"  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

ExpandableSelector is an Android library created to show a list of Button/ImageButton widgets inside a animated container which can be collapsed or expanded.

This project is mainly for use with Android applications that do not have access to Java's javax.sound.midi library. However, it is a stand-alone Java library with no Android-specific dependencies or considerations.

Using Digits from source in production applications is not officially supported by Fabric. Please utilize the available binaries.

Android Library for exporting/managing data from the Sensor Manager Library.

Poetry is a persistence library that allows you to persist a JSON object tree (through Jackson) directly into an SQLite database (through OrmLite). Poetry enables you to write less code and persist data much faster.

Open Source framework for building cross-platform truly native iOS, Android and Windows mobile apps using JavaScript.

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