Coder Social home page Coder Social logo

devahamed / multiviewadapter Goto Github PK

View Code? Open in Web Editor NEW
820.0 40.0 151.0 25.43 MB

Easily create complex recyclerview adapters in android

Home Page: https://devahamed.github.io/MultiViewAdapter

License: Apache License 2.0

Java 100.00%
android android-library recyclerview recyclerview-adapter java-library recyclerview-multi-type diffutils recycleradapter

multiviewadapter's Introduction

😔 Due to the nature of my job and growing popularity of Jetpack Compose, I lack the motivation to keep this project alive.



Alt text

GitHub license Code coverage Build Status

Recyclerview is one of the powerful widgets inside android framework. But creating adapters with multiple view types is always exhausting. Not anymore. MultiViewAdapter makes it easy for you to create adapter with multiple view types easily. Using the library you will be able to build composable view holders, which can be re-used across your app. Apart from this, MultiViewAdapter adds many other useful features into the library as add-ons.

🎉🎉 MultiViewAdapter v3.0 supports AndroidX. v3.0 is identical to v2.0 except for package name changes and androidx support.

Contents

  1. Why this library
  2. Feature Showcase
  3. Gradle Dependency
  4. Core Concepts
  5. Basic Usage
  6. Advanced Usage
  7. Learn More
  8. Changelog
  9. Contribution
  10. Credits
  11. Hall of fame
  12. License

Why this library?

Have you ever displayed multiple view types inside a single adapter? Have you ever added selection mode to an adapter? Have you ever set different span size to different items inside a single adapter? Have you ever added swipe-to-dismiss / drag & drop / infinite scrolling features to your adapter?

If you answered yes, then you must know how hard it is to do any one of these. What if you had to add all of these inside a single adapter. Phew.

Problems with default adapter

  1. In default adapter approach, code is not re-usable as it is.
  2. If you have to add multiple viewtypes the code grows painfully.
  3. If the data needs to be updated, its hard to write the updation logic and call the correct notify method.

Problems with similar libraries

To solve the above problems, you can also use a different library or libraries. But such libraries have a common restrictions - Your data model will be polluted with the view logic.

  1. Your data objects should extend/implement from library's model, which can interfere with your object hierarchy.
  2. View holder creation and binding has to be written inside the data model. You are forced to keep layout and view references inside the model class itself.
  3. For complex lists, generic notifyDataSetChanged method will be called during updation. Also these libraries don’t take advantage of DiffUtil.
  4. You have to write switch cases, if you want to have different item-decorations/span-size/selection-modes/expansion-modes for different view types.
  5. You lose the 'type' information when accessing objects ie., you need to cast the object every time you need it.

MultiViewAdapter solves all of these requirements. The library was specifically designed in a way to not interfere with your object modeling and hierarchy.


Feature Showcase

Here are the few features which are possible with this library.

Multiple Viewtypes Multiple Spans Other Features
Multiple Viewtypes Multiple Span Other
Selection Item Expansion Section Expansion
Selection Item Expansion Section Expansion

Gradle Dependency

The library is available via JCenter. JCenter is the default maven repository used by Android Studio. The minimum API level supported by this library is API 14.

Adding Library

Core

dependencies {
    implementation 'dev.ahamed.mva2:adapter:2.0.0'
}

Adding Extension

Extensions

dependencies {
    implementation 'dev.ahamed.mva2:ext-databinding:2.0.0'  // DataBinding
    implementation 'dev.ahamed.mva2:ext-decorator:2.0.0'    // Decorators
    implementation 'dev.ahamed.mva2:ext-diffutil-rx:2.0.0'  // RxDiffUtil
}

Using Snapshot Version

Just add '-SNAPSHOT' to the version name

dependencies {
    implementation 'dev.ahamed.mva2:adapter:2.0.0-SNAPSHOT' // Library
}

To use the above snapshot version add the following to your project's gradle file

allprojects {
    repositories {
        maven {
            url 'https://oss.jfrog.org/artifactory/oss-snapshot-local'
        }
    }
}

Core Concepts

Core mantra of MultiViewAdapter - Separation of view logic from data management logic. You get two different components which are :

  1. Section - Component to hold your data. All data related updates will run here and proper notify method will be called on the adapter.
  2. ItemBinder - Component which creates and binds your view holder. All view related logic should go here.

Section

Section is the building block for MultiViewAdapter. Section will hold your data which needs to be displayed inside the recyclerview - data can be a single item or list of items. When the underlying data is changed the section will calculate the diff and call the correct notify method inside the adapter. You can add as many as Section to an adapter.

How Section Works GIF

There are different types of sections.

Name Description
ItemSection Section to display single item
ListSection Section to display list of items
HeaderSection Section to display list of items along with a header
NestedSection Section which can host other section
TreeSection Section which can display items in tree fashion. Ex: Comment list

ItemBinder

ItemBinder is the class where all view related code should be written. ItemBinder is responsible for creating and binding view holders. The method signatures are kept close to the default RecyclerView.Adapter method signatures. For each viewtype inside the recyclerview, you need to create an ItemBinder.

ItemBinder allows you to have different decoration for different view types. Apart from this, with ItemBinder you will be able to add Swipe-to-dismiss, drag and drop features.


Basic Usage

Lets create an adapter which displays a list of cars. Follow these steps.

  1. You need to create an ItemBinder for your model. ItemBinder is responsible for creating and binding your view holders. Following is the code snippet of ItemBinder for CarModel class.

CarBinder

public class CarBinder extends ItemBinder<CarModel, CarBinder.CarViewHolder> {

  @Override public CarViewHolder createViewHolder(ViewGroup parent) {
      return new CarViewHolder(inflate(R.layout.item_car, parent));
  }

  @Override public boolean canBindData(Object item) {
      return item instanceof CarModel;
  }

  @Override public void bindViewHolder(CarViewHolder holder, CarModel item) {
      holder.tvCarName.setText(item.getName());
  }

  static class CarViewHolder extends ItemViewHolder<CarModel> {

    TextView tvCarName;

    public CarViewHolder(View itemView) {
        super(itemView);
        tvCarName = findViewById(R.id.tv_car_name);
    }
  }
}
  1. Now create an adapter and use the ItemBinder created above. Since we are displaying a list of items we need to create an ListSection object and add the data items to it. Now add this section to adapter. Done.

Inside Activity/Fragment

class CarListActivity extends Activity {
  private RecyclerView recyclerView;
  private List<CarModel> cars;

  public void initViews() {

      // Create Adapter
      MultiViewAdapter adapter = new MultiViewAdapter();
      recyclerView.setAdapter(adapter);

      // Register Binder
      adapter.registerBinders(new CarItemBinder());

      // Create Section and add items
      ListSection<YourModel> listSection = new ListSection<>();
      listSection.addAll(cars);

      // Add Section to the adapter
      adapter.addSection(listSection);
  }
}

Yay!! We are done.


Advanced Usage

Multiple viewtypes

The USP of MultiViewAdapter is adding multiple viewtypes to a single adapter easily. For each view type you need to create an ItemBinder and register it with the adapter. You don't need to manage the viewtypes yourself or write crazy if-else-if conditions.

    adapter.registerBinders(new Binder1(), new Binder2(), ...);

Multiple Sections

Sections are building blocks of MultiViewAdapter. You can add as many as sections to the adapter and you can nest the sections within another section as well. Each section represents a data set. If you want to display multiple data set inside a single adapter you can do so by adding any number of sections.

    adapter.addSection(new ItemSection());
    adapter.addSection(new ListSection());
    adapter.addSection(new NestedSection());
    // And so on...

Selection

Full Documentation

MultiViewAdapter provides easy way to add selection/choice mode for the recyclerview. There are four types of mode available

  1. SINGLE - Only one item can be selected.
  2. MULTIPLE - Multiple items can be selected.
  3. INHERIT - Inherits the property from the parent. This the default value for sections.
  4. NONE - Disables the selection mode.

Set selection mode to your adapter or section.

    adapter.setSelectionMode(Mode.SINGLE);

    // You can set selection mode for section as well
    section1.setSelectionMode(Mode.MULTIPLE); // Different mode than adapter
    section2.setSelectionMode(Mode.NONE); // Disables selection for this section

To select an item, inside the viewholder call ItemViewHolder.toggleItemSelection() method. For example,

  static class ViewHolder extends BaseViewHolder<SelectableItem> {

    ViewHolder(View itemView) {
      super(itemView);
      itemView.setOnClickListener(new View.OnClickListener() {
        @Override public void onClick(View view) {
          toggleItemSelection();
        }
      });
    }
  }

Expansion

Full Documentation

MultiViewAdapter allows you to expand/collapse a single item or an entire section. There are four types of expansion mode available.

  1. SINGLE - Only one item/section can be expanded.
  2. MULTIPLE - Multiple items/sections can be expanded.
  3. INHERIT - Inherits the property from the parent. This the default value for sections.
  4. NONE - Disables the expansion mode.

Set expansion mode to the adapter.

    // Expanding single item
    adapter.setExpansionMode(Mode.SINGLE);
    section1.setExpansionMode(Mode.MULTIPLE); // Different mode than adapter
    section2.setExpansionMode(Mode.NONE); // Disables expansion for this section

    // Expanding Sections
    adapter.setSectionExpansionMode(Mode.SINGLE);

To expand/collapse an item, inside the viewholder call ItemViewHolder.toggleItemExpansion() method. Similarly to expand/collapse a section, call ItemViewHolder.toggleSectionExpansion() method. For example,

  static class ViewHolder extends BaseViewHolder<SelectableItem> {

    ViewHolder(View itemView) {
      super(itemView);
      itemView.setOnClickListener(new View.OnClickListener() {
        @Override public void onClick(View view) {
          toggleItemExpansion();
          // or
          toggleSectionExpansion();
        }
      });
    }
  }

Different SpanCount

Full Documentation

You can display items inside the adapter with different span count. You can customise the span count either by ItemBinder or Section.

Different span count by viewtype

Each ItemBinder can customise the span count by overriding a method like this. maxSpanCount is the span count of parent.

    public class SampleBinder extends ItemBinder<SampleModel, SampleViewHolder> {

      @Override public int getSpanSize(int maxSpanCount) {
        return YOUR_SPAN_COUNT;
      }

    }

Different span count for sections

You can also set span count for individual sections. Call section.setSpanCount(int) to set the span count for sections.

Swipe to dismiss

Full Documentation

Swipe to dismiss gesture can be added in two simple steps.

Attach your RecyclerView to the adapter's ItemTouchHelper.

  adapter.getItemTouchHelper().attachToRecyclerView(recyclerView);

Override getSwipeDirections() inside your viewholder class.

    @Override public int getSwipeDirections() {
      return ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
    }

Drag and drop

Full Documentation

You can drag and drop the items inside or across sections. An item can be moved to any place of another item - only constraint is view type should be same for both items. Drag and drop gesture can be added by two simple steps,

Attach your RecyclerView to the adapter's ItemTouchHelper.

  adapter.getItemTouchHelper().attachToRecyclerView(recyclerView);

Override getDragDirections() inside your viewholder class.

    @Override public int getDragDirections() {
      return ItemTouchHelper.LEFT
          | ItemTouchHelper.UP
          | ItemTouchHelper.RIGHT
          | ItemTouchHelper.DOWN;
    }

Infinite scrolling

Full Documentation

Infinite loading is a add-on feature available in MultiViewAdapter ie., you don't need to create a separate adapter. You can use it with existing MultiViewAdapter, by creating an InfiniteLoadingHelper object and setting it to adapter.

  protected void setUpAdapter() {
    // Only 10 pages will be loaded
    infiniteLoadingHelper = new InfiniteLoadingHelper(recyclerView, R.layout.item_loading_footer, 10) {
      @Override public void onLoadNextPage(int page) {
        // Load next page
      }
    };
    adapter.setInfiniteLoadingHelper(infiniteLoadingHelper);
  }

Custom decoration

Full Documentation

The library allows you to draw decoration for individual items or sections. You can create a decoration by extending Decorator which can be added to any ItemBinder or Section.

  MultiViewAdapter adapter = new MultiViewAdapter();
  recyclerView.addItemDecoration(adapter.getItemDecoration());

  // Add to itembinder
  itemBinder.addDecorator(new SampleDecoration());
  // or you can add it to a Section
  section.addDecorator(new SampleDecoration());

Decoration and its api's are powerful feature of this library. Kindly read the full documentation to understand the complete feature. Decoration Documentation


Learn More

  1. Documentation Website - If you would like to learn more about various other features, kindly read the documentation. All features are documented with sample code which should help you set-up complex recyclerview adapters.
  2. Sample App - Sample app showcases all the features of the library. Also it is an excellent reference for creating most complex use cases.
  3. JavaDocs

Changelog

v2.0.0

Type Stability Date
Major Stable 29-October-2019

After being in development for more than a year and being in beta for more than three months, the library is moved to stable release.

Changes

  • NestedSection visibility flags are passed down to its children. This fixes incorrect selection/expansion toggles on child views.

v2.0.0-beta01

Type Stability Date
Major Beta 3-July-2019

All public API's are finalized for v2.0.0 release, only bug fixes will be added in further beta's.

Features added

  • Added OnItemClickListener method inside the ItemSection class.

Bug fixes

  • Fixed NPE thrown by ItemSection when the item is null and expansion/selection is toggled.

Behavior Changes

  • HeaderSection is has been changed to host ItemSection and NestedSection. Previously it was hosting ItemSection and ListSection.

v2.0.0-alpha02

Type Stability Date
Major Alpha 31-May-2019

Features added

  • Implemented onDrawOver method inside the decoration api

Bug fixes

  • Fixed incorrect adapter position being sent to notify while calling clearAllSelections() method - Issue
  • Fixed incorrect 'selection' and 'expansion' behaviour - Issue

Behavior Changes

  • Pre-defined payload is sent when item's selection/expansion is toggled
  • TreeSection decoration behavior is changed
  • TreeSection when created, will be either expanded or collapsed by user flag

Misc

  • Sample app updated is with new showcases for decoration and TreeSection api's
  • Automation for app releases is enabled. Now app is pushed to playstore with a git-tag push
  • Project contribution guidelines and templates are added

v2.0.0-alpha01

Type Stability Date
Major Alpha 20-April-2019
  • Initial release for v2.x refactor

Alternatively, you can visit the project's releases page for complete changelog. (View Releases) Also if you watch this repository, GitHub will send you a notification every time there is an update.


Contribution

We welcome any contribution to the library. This project has a good infrastructure which should make you comfortable to push any changes. When you make a pull request CI builds the project, runs the test cases and reports the test coverage changes, so you will know whether your pull request is breaking build.

You can contribute to any of the following modules:

  1. Core Library
  2. Library Extensions
  3. Sample App
  4. Documentation
  5. Design assets

We are looking for project maintainers, who have made prior contributions to this project can get in touch if interested. You can contact the project owner here.


Credits

This project stands on the shoulders of open source community. It is a must to credit where it is due.

  1. AOSP - Android Open Source Project
  2. Artifactory OSS - Repository manager to host snapshot builds
  3. Bintray - Distribution platform
  4. Bitrise - CI & CD service
  5. Codecov - Code coverage hosting service
  6. Docsify - Documentation generator
  7. Github - Version control & issue management platform

Also this library uses following open source gradle plugins

  1. Bintray Release - Plugin to release the library artifacts to bintray
  2. Artifactory Publish - Plugin to release snapshots to artifactory oss

If this library does not suit your needs create an issue/feature request. Meanwhile check these awesome alternatives as well.

  1. MultipleViewTypesAdapter - Original inspiration for this library
  2. AdapterDelegates
  3. Groupie
  4. Epoxy

Hall of fame

If you are using MultiViewAdapter in your app and you are happy with it, you can create a pull request to include your app information here. We will display it here.


License

Copyright 2017 Riyaz Ahamed

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.

multiviewadapter's People

Contributors

devahamed avatar electricmagic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

multiviewadapter's Issues

Item click and long click

Hello, first of all, congratulations for this great library. I have a question. Does this library support item click and long click detection? Thanks in advance!

Expanding non-child groups

Is it possible to expand groups that are not children?
For example, I have a header that says "expand all", when clicking this header I want to expand three different groups bellow this header.
As far as I can see I can only expand from the ViewHolder itself and that's not enough for this requirement I think.

NullPointerException in the sample app

In 'Simple grid' and 'Complex' page, long press the grid item will caused NullPointerException:

FATAL EXCEPTION: main
    Process: com.ahamed.sample, PID: 25712
    java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v7.widget.helper.ItemTouchHelper.startDrag(android.support.v7.widget.RecyclerView$ViewHolder)' on a null object reference
    at com.ahamed.multiviewadapter.CoreRecyclerAdapter$2.onStartDrag(CoreRecyclerAdapter.java:79)
    at com.ahamed.multiviewadapter.BaseViewHolder.startDrag(BaseViewHolder.java:162)
    at com.ahamed.sample.common.binder.GridItemBinder$ItemViewHolder$2.onItemLongClick(GridItemBinder.java:73)
    at com.ahamed.sample.common.binder.GridItemBinder$ItemViewHolder$2.onItemLongClick(GridItemBinder.java:71)
    at com.ahamed.multiviewadapter.BaseViewHolder.onLongClick(BaseViewHolder.java:44)

Kotlin IllegalAccessError Problem

I got IllegalAccessError when my RecyclerAdapter is Kotlin.
It says "Illegal class access", "declaration of 'My Adapter Class' appears in ...base.apk:classes2.dex"

But when I change my class to java, It works fine.

java.lang.IllegalAccessError: Illegal class access: 'cupid.android.ui.adapter.HomeFragmentAdapter' attempting to access 'com.ahamed.multiviewadapter.BaseDataManager' (declaration of 'cupid.android.ui.adapter.HomeFragmentAdapter' appears in /data/app/cupid.android-1/base.apk:classes2.dex)
                                                                 at cupid.android.ui.adapter.HomeFragmentAdapter.<init>(HomeFragmentAdapter.kt:20)
                                                                 at cupid.android.ui.screen.activity.main.fragment.home.HomeFragmentLayout.createView(HomeFragmentLayout.kt:20)
                                                                 at cupid.android.ui.screen.activity.main.fragment.home.HomeFragmentLayout.createView(HomeFragmentLayout.kt:13)
                                                                 at cupid.android.ui.base.BaseFragmentLayout.view(BaseFragmentLayout.kt:12)
                                                                 at cupid.android.ui.screen.activity.main.fragment.home.HomeFragment.onCreateView(HomeFragment.kt:37)
                                                                 at android.support.v4.app.Fragment.performCreateView(Fragment.java:2337)
                                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1418)
                                                                 at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1739)
                                                                 at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1808)
                                                                 at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:799)
                                                                 at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2579)
                                                                 at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2366)
                                                                 at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2321)
                                                                 at android.support.v4.app.FragmentManagerImpl.execSingleAction(FragmentManager.java:2198)
                                                                 at android.support.v4.app.BackStackRecord.commitNowAllowingStateLoss(BackStackRecord.java:651)
                                                                 at android.support.v4.app.FragmentStatePagerAdapter.finishUpdate(FragmentStatePagerAdapter.java:167)
                                                                 at android.support.v4.view.ViewPager.populate(ViewPager.java:1236)
                                                                 at android.support.v4.view.ViewPager.populate(ViewPager.java:1084)
                                                                 at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1614)
                                                                 at android.view.View.measure(View.java:19857)
                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                 at android.support.design.widget.CoordinatorLayout.onMeasureChild(CoordinatorLayout.java:714)
                                                                 at android.support.design.widget.HeaderScrollingViewBehavior.onMeasureChild(HeaderScrollingViewBehavior.java:91)
                                                                 at android.support.design.widget.AppBarLayout$ScrollingViewBehavior.onMeasureChild(AppBarLayout.java:1362)
                                                                 at android.support.design.widget.CoordinatorLayout.onMeasure(CoordinatorLayout.java:784)
                                                                 at android.view.View.measure(View.java:19857)
                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                 at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                                 at android.view.View.measure(View.java:19857)
                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
                                                                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
                                                                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
                                                                 at android.view.View.measure(View.java:19857)
                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                 at android.view.View.measure(View.java:19857)
                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                 at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1464)
                                                                 at android.widget.LinearLayout.measureVertical(LinearLayout.java:758)
                                                                 at android.widget.LinearLayout.onMeasure(LinearLayout.java:640)
                                                                 at android.view.View.measure(View.java:19857)
                                                                 at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:6083)
                                                                 at android.widget.FrameLayout.onMeasure(FrameLayout.java:185)
                                                                 at com.android.internal.policy.DecorView.onMeasure(DecorView.java:689)
                                                                 at android.view.View.measure(View.java:19857)
07-06 04:36:31.822 8493-8493/cupid.android E/AndroidRuntime:     at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2275)
                                                                 at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1366)
                                                                 at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1619)
                                                                 at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1254)
                                                                 at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6337)
                                                                 at android.view.Choreographer$CallbackRecord.run(Choreographer.java:874)
                                                                 at android.view.Choreographer.doCallbacks(Choreographer.java:686)
                                                                 at android.view.Choreographer.doFrame(Choreographer.java:621)
                                                                 at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:860)
                                                                 at android.os.Handler.handleCallback(Handler.java:751)
                                                                 at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                 at android.os.Looper.loop(Looper.java:154)
                                                                 at android.app.ActivityThread.main(ActivityThread.java:6119)
                                                                 at java.lang.reflect.Method.invoke(Native Method)
                                                                 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:886)
                                                                 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)

Removing DataItemBinders from Adapter

This library was very useful to me. Thank a lot!
Just wanted to know is there any way to remove a registered binder from recyclerAdapter dynamically?

Update to support library to 28.0.0 stable

Since android support libraries are moving into jetpack, and package names are being changed, it is good to have one last minor version release(v1.3.0) before migration.

Repeating menu groups in a single list

Hello. Been using your library since yesterday, and it has been wonderful. Thanks for the effort.

Having a question here.. how do I build such a list:


header a
item a1
item a2

header b
item b1
item b2

where basically header a and b are the same object type, and items a1, a2, b1 and b2 are also the same type.

If in the adapter I have two list managers (say, headers and items), then headers will grouped at the top, and all of the items will be grouped below.

Maybe this is just a stupid question, but really appreciate any help. Thanks beforehand.

I would like to make a suggestion

1.

/**

  • Denotes that the item is lies in the middle of the grid
    */
    int POSITION_RIGHT = 4;

/**

  • Denotes that the item is lies in the right edge of the grid
    */
    int POSITION_BOTTOM = 8;

/**

  • Denotes that the item is lies in the bottom edge of the grid
    */
    int POSITION_MIDDLE = 0;

why the POSITION_RIGHT ‘s note is rigth ?
this is a accident mistake or this have other meaning?

2.

Can you provide a demo about in a RecyclerView with Grid hava different item and different SpanCount ?
I have read ComplexListActivity ,but This is not what I want。
https://github.com/DevAhamed/MultiViewAdapter/wiki/Grid-Adapter about specific demo!

Best blessing!
thank you very much!

Add ui tests

The entire library is not tested. Adding test cases will help the library to iterate quickly and ensures the new feature doesn't break.

RFE Support for cursors and the Loader Pattern

It would be really nice to be able to use the Loader pattern with cursors.

I have a CursorRecyclerViewAdapter implementation that i might be able to adapt but I don't want to bother if there is already something in the works.

.setSelectedItem not working

BaseDataManager.setSelectedItem can only be called from within the same library (com.github.devahamed:multi-view-adapter) less... (Ctrl+F1)
This API has been flagged with a restriction that has not been met. Examples of API restrictions: * Method can only be invoked by a subclass * Method can only be accessed from within the same library (defined by the Gradle library group id) * Method can only be accessed from tests. You can add your own API restrictions with the @RestrictTo annotation. Issue id: RestrictedApi

here is my code

if(taxListDataSet.contains(row1)) {
rowDataListManager.setSelectedItem(taxListDataSet.get(taxListDataSet.indexOf(row1)));
selectableAdapter.notifyDataSetChanged();
}

Change item's decoration color

Instead of the decoration takes the background color of parent view containing the recyclerview, could we change the color of decoration? Many thanks.

about getPositionInAdapter method

Corerecycleradapter ——>getpositioninadapter (BaseDataManager dataManager, int binderPosition)
What is the effect of this method?
I did not read, ask for answers.
Thank you

Effect of expanding and collapsing an item on the holder's itemView

When an item in the expandable list is expanded or collapsed, most of the contents of the holder's
itemView are not affected (except the expand/contract indicator).
I have a holder which has many complex views (including a TextureView) that do not need to be refreshed every time I expand or collapse that item.
So I was thinking that shouldn't there be an alternative abstract method in the ItemBinder class which should get invoked instead of invoking the bind() method when expanding or collapsgin an item, where we put the views that get changed only on expanding/collapsing? I think the impact on performance could be reduced by this.

Incorrect behaviour of "selection_mode"

Information Needed:

  • Android API level: 21
  • Library Version: 2.0.0-alpha01
  • Recyclerview Version: 28.0.0

What:
When adapter has selection mode as 'Multiple' and sections has selection mode as 'Single', adapter behaves as if the selection mode was 'Single'

Steps to reproduce:

  1. Install sample app, goto 'selection' demo screen
  2. Set adapter selection mode as 'Multiple' and set selection mode as 'Single' for all the sections.
  3. Select an item in section 1 and select an item in section 2.
  4. Notice how the section 1 item is unselected. This is a behaviour of 'Single' mode, but it should not be the case since adapter has 'Multiple'

Issue to bind

java.lang.IllegalStateException: Binder not found for position. Position = 0 using wiki simple usage

Multipleviews

Hi @DevAhamed,

I was reading the Multiple Data Sets section on the wiki and I wonder if it is possible to add a header view for each data set?

Also in this example I see that there are two separate list. How can we do if we have one list with different kind of views? (Ex.: a newsfeed where one item is a photo item, one a simple text item and they have different layouts)

Thank you.

Move DiffUtil calculation to background thread

DiffUtil calculation is done at the main thread. For lists smaller count, the calculation on main thread is fine. But for larger lists it might block the main thread for few frames.

Grid Layoutmanger spacing.

I have to increase gap of grid view items nearly 23dp. But I'm not getting that much spacing in between. Could you please suggest me on this?
My span count is 2:
Actual Result:
Grid1 Grid2
Grid3 Grid4

Excepted Result:
Grid1 Grid2
Grid3 Grid4

IndexOutOfBoundsException when expanding group item

In the sample app, when expanding items in 'Expanding group' page, IndexOutOfBoundsException thrown:

IndexOutOfBoundsException
FATAL EXCEPTION: main
  Process: com.ahamed.sample, PID: 24672
  java.lang.IndexOutOfBoundsException: Index: 10, Size: 10
  at java.util.ArrayList.get(ArrayList.java:411)
  at com.ahamed.multiviewadapter.BaseDataManager.getItem(BaseDataManager.java:316)
  at com.ahamed.multiviewadapter.BaseDataManager.get(BaseDataManager.java:210)
  at com.ahamed.multiviewadapter.CoreRecyclerAdapter.onBindViewHolder(CoreRecyclerAdapter.java:116)
  at com.ahamed.multiviewadapter.CoreRecyclerAdapter.onBindViewHolder(CoreRecyclerAdapter.java:35)
  ...

sticky group headers

are there any plans to implement a "sticky headers feature" to expandable group headers?

Expandable groups

Hi! first of all, awesome library!!

I found an issue with the expand collapse feature. While items expand and collapse correctly, groups can't collapse again, except if I click on another group(in EXPANDABLE_MODE_SINGLE). When i call the method isItemExpanded() after toggleGroupExpansion() it returns allways false.

This is a clone of your proyect:

multiviewadapter

Remove file templates

File templates is not a widely used feature since it requires set-up from the user side. Also whenever the AndroidStudio is updated users have to move the file templates manually.

Apart from this file templates is additional burden to keep them updated with each release. So we can remove the file templates from the library.

Automate snapshots deployment

Build snapshots of library from the default branch and deploy them to artifactory. We have already integrated with CI pipeline, where builds are checked nightly on default branch. We can leverage this and deploy snapshots either,

  1. Nightly
  2. Weekly
  3. On every push to the default branch

We have to choose any one of the options above and automate the deployment process.

Refactoring Library to v2

I have been developing the library under the wraps for a few months. Open source development should not happen that way, but i regret doing the same. I am currently in the process of migrating to AndroidX. Once done v2 source code will be dropped with a better documentation and test cases.

  • Drop new source code into the repo
  • Add test cases for v2 codebase
  • Add new sample app
  • Release sample app into playstore
  • Create new website for library
  • Better javadoc comments - will be improved continuously
  • Improve wiki documentation - Choose wiki hosting like MkDocs or GitBook
  • Make v2 branch as primary
  • Add issue and pull request templates
  • Create kanban style project management inside the github repo
  • Add new ReadMe.md
  • Add Milestones.md
  • Add Contributions.md
  • Add a readme, which explains the internals of the library

Sorting

Hi Ahamed,

Your library is awesome and saved me lots of times and headache, thank you.

I was wondering if there is a way to add SortedList or any kind of sorting to items in the DataListManager as my data is coming through RxJava and I have no clue about the order of them so I have to sort it before passing it to Adapter.

I was doing it before by adding my item to SortedList and adding Comprable to my model.

AndroidX Support

Since AndroidX packages are now out of beta, its time to add support for new packages. Since this requires a major refactor, my current plan is to release it with v2 refactor.

Improve test cases - Migrate to unit test cases

At the time of v1.2.6 release, the combined test coverage stands at 55%. These include some false positive test cases as well. Since we have android unit test which needs emulator to boot up, our CI build times are high and fail most of the times. So its time to improve the test cases for the library.

  • Convert all test cases into jUnit tests
  • Remove the false positive test cases
  • Increase the coverage at least to 80%

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.