GithubHelp home page GithubHelp logo

soxjke / celladapter Goto Github PK

View Code? Open in Web Editor NEW

This project forked from erva/celladapter

0.0 2.0 0.0 230 KB

CellAdapter simplifies working with RecyclerView. It provides an opportunity to easily support multiple view types, to separate ViewHolders from Adapter class, map data to a view in a convenient way, register and handle UI callbacks for each ViewHolder.

License: MIT License

Kotlin 53.29% Java 46.71%

celladapter's Introduction

CellAdapter

License: MIT

GitHub Logo

This library simplifies RecyclerView with multiple view types. Main points:

  • Single adapter class for all project
  • Easy to use - just register Cell, Model and ClickListener (optional) in adapter
  • Listen clicks on any View of any type
  • Build-in single / multi select
  • Supports Java / Kotlin and androidx.recyclerview/support:recyclerview-v7

No more code like this:

@Override
public int getItemViewType(int position) {
	// Just as an example, return 0 or 2 depending on position
	return position % 2 * 2;
}

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
	switch (viewType) {
		case 0: return new ViewHolder0(...);
		case 2: return new ViewHolder2(...);
		...
	}
}

Usage

Java

CellAdapter adapter = new CellAdapter(context);
// feel free to register multiple models and cells 
// model per cell, so your RecyclerView would represent multiple view types
adapter.registerCell(SampleModel.class, SampleCell.class, new SampleCell.Listener(){}); 

Kotlin

var adapter: CellAdapter = CellAdapter().let {
        it.cell(SampleCell1::class) {
            item(SampleModel1::class)
            listener(object : SampleCell1.Listener {})
        }
        it.cell(SampleCell2::class) {
            item(SampleModel2::class)
            listener(object : SampleCell2.Listener {})
        }
    }

where SampleModel.class is POJO and SampleCell.class is

@Layout(R.layout.cell_sample)
public class SampleCell extends Cell<SampleModel, SampleCell.Listener> {

    @Override
    protected void bindView() {
        getItem(); // is your Model object
    }
    
    protected void clearResources() {
        //optional
    }

    public interface Listener extends Cell.Listener<Model> {
        void callbackSample(Model model);
    }
}

Kotlin is almost the same. Check samples for details.

Samples and hints

Versions

3.0.0

For androidx - import io.erva.celladapter.x...

For support:recyclerview-v7 - import io.erva.celladapter.v7...

2.0.4

You have only import io.erva.celladapter

support:recyclerview-v7 by default

Download

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

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

Add the dependency:

dependencies {
    
    // one of two
    implementation "com.android.support:recyclerview-v7:27.1.1" // any version
    implementation "androidx.recyclerview:recyclerview:1.0.0-alpha3" // any version

    
    // for java projects
    implementation ('com.github.erva.CellAdapter:celladapter:3.0.0') {
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'androidx.recyclerview', module: 'recyclerview'
    }
    
    // for kotlin projects
    implementation ('com.github.erva.CellAdapter:celladapter-kotlin:3.0.0') {
        exclude group: 'com.android.support', module: 'recyclerview-v7'
        exclude group: 'androidx.recyclerview', module: 'recyclerview'
    } 
}

Proguard

3.0.0

Java

#CellAdapter
-dontwarn io.erva.celladapter.**
-keepclasseswithmembers public class * extends io.erva.celladapter.** { *; }

Kotlin

#CellAdapter
-dontwarn io.erva.celladapter.**
-keep public class kotlin.reflect.jvm.internal.impl.builtins.* { public *; }
-keepclassmembers class * extends io.erva.celladapter.** {
    <init>(android.view.View);
}

2.0.4

#CellAdapter
-dontwarn io.erva.celladapter.**
-keepclasseswithmembers public class * extends io.erva.celladapter.** { *; }

License

CellAdapter is licensed under the MIT License.


Icons made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

celladapter's People

Contributors

erva avatar

Watchers

 avatar  avatar

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.