RecyclerView Presenter
Convenience library to handle different view types with different presenters in a single RecyclerView.
How to install
repositories {
maven {
url "https://jitpack.io"
}
}
dependencies {
compile 'com.github.kibotu:RecyclerViewPresenter:-SNAPSHOT'
// optional
compile 'jp.wasabeef:recyclerview-animators:2.2.3'
}
How to use
-
Add the PresenterAdapter to your RecyclerView
PresenterAdapter<String> adapter = new PresenterAdapter<>(); list.setAdapter(adapter);
-
[Add a model with a Presenter as representation] ( https://github.com/kibotu/RecyclerViewPresenter/blob/master/app/src/main/java/net/kibotu/android/recyclerviewpresenter/app/MainActivity.java#L42-L47) to the adapter, e.g.:
adapter.add(myModelObject, PhotoPresenter.class); adapter.add(myModelObject, LabelPresenter.class);
-
Create a presenter, e.g. PhotoPresenter or LabelPresenter
public class MyModelPresenter extends Presenter<MyModel, PhotoPresenter.ViewHolder>
-
Add click listener to adapter and to presenter
// adapter adapter.setOnItemClickListener((item, rowView, position) -> toast(format("{ 0 } . { 1 } ", position, item))); // in bind method of presenter if (presenterAdapter.getOnItemClickListener() != null) presenterAdapter.getOnItemClickListener().onItemClick(item, v, position);
Updating item
adapter.update(0, myModelObject);
Sorting
PresenterAdapter.sort(adapter);
Sort if model doesn't implement Comparable
adapter.sortBy((o1, o2) -> o1.compareTo(o2));
###License
Copyright 2016 Jan Rabe 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.