kubatatami/SlimAdapter


A slim & clean & typeable Adapter without# VIEWHOLDER

Download


Step 1. Add the JitPack repository to your build file

Add it in your root settings.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}

Add it in your settings.gradle.kts at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url = uri("https://jitpack.io") }
		}
	}

Add to pom.xml

	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.kubatatami:SlimAdapter:0.9.1'
	}
	dependencies {
		implementation("com.github.kubatatami:SlimAdapter:0.9.1")
	}
	<dependency>
	    <groupId>com.github.kubatatami</groupId>
	    <artifactId>SlimAdapter</artifactId>
	    <version>0.9.1</version>
	</dependency>

                            
    libraryDependencies += "com.github.kubatatami" % "SlimAdapter" % "0.9.1"
        
        

                            
    :dependencies [[com.github.kubatatami/SlimAdapter "0.9.1"]]
        
        

Readme


logo

Download GitHub license Platform

SlimAdapter

A slim & clean & typeable Adapter without# VIEWHOLDER

Features

  • No ViewHolder any more
  • No Reflection
  • Fluent & simple API
  • Multi-typeable adapter
  • Support kotlin

Setup

compile 'net.idik:slimadapter:1.2.1'

Usages

Java

Step 1: Create SlimAdapter & attachTo target RecyclerView

  • register(layoutRes, SlimInjector<DataType>)

    Register a DataType to be associated with a layoutRes through a SlimInjector

  • registerDefault(layoutRes, SlimInjector)

    Register a default layoutRes to all the DataType which has not registered by alone.


 SlimAdapter.create()
                .register(R.layout.item_user, new SlimInjector<User>() {
                    @Override
                    protected void onInject(User data, IViewInjector injector) {
                        ...// inject data into views,step 2
                    }
                })
                .register(R.layout.item_interger, new SlimInjector<Integer>() {
                    @Override
                    protected void onInject(Integer data, IViewInjector injector) {
                        ...// inject data into views,step 2
                    }
                })
                .register(R.layout.item_string, new SlimInjector<String>() {
                    @Override
                    protected void onInject(String data, IViewInjector injector) {
                        ...// inject data into views,step 2
                    }
                })
                .registerDefault(R.layout.item_string, new SlimInjector() {
                    @Override
                    protected void onInject(Object data, IViewInjector injector) {
                        ...// inject data into views,step 2
                    }
                })
                .attachTo(recyclerView);
    }
    

Step 2: Inject data into views with fluent apis

injector.text(R.id.name, data.getName())
        .text(R.id.age, String.valueOf(data.getAge()))
        .textColor(R.id.age, Color.RED)
        .textSize(R.id.age, 8)
        .longClicked(R.id.name, new View.OnLongClickListener() {
                                    @Override
                                    public boolean onLongClick(View v) {
                                        //do stuff...
                                        return false;
                                    }
                                })
        .clicked(R.id.text, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        //do stuff...
                                    }
                                })
        .with(R.id.name, new IViewInjector.Action<TextView>() {
                                    @Override
                                    public void action(TextView view) {
                                        //do stuff...
                                    }
                                })
        ...;

Custom ViewInjecor?

there are lots of methods about views as you know, i could not consider every single one to included it in the default view injector imp, you can extend the CustomViewInjector to match you needs, the docs & example is comming soon...

Step 3: Use SlimAdapter as normal adapter

    List<Object> data = new ArrayList<>();

    {
        data.add("hello");
        data.add(",");
        data.add(new User("iDIK", 27));
        data.add("world");
        data.add("!");
        data.add(666666);
        data.add(34234);
        data.add(666669L);
    }
    
    slimAdapter.setData(data).notifyDataSetChanged();
    

SlimAdapter 💗 Kotlin

SlimAdapter.create()
                .register<String>(R.layout.item_string) { data, injector ->
                    ...// inject data into views
                }
                .register<User>(R.layout.item_user) { data, injector ->
                    ...// inject data into views
                }
                .register<Int>(R.layout.item_interger) { data, injector ->
                    ...// inject data into views
                }
                .registerDefault(R.layout.item_string) { data, injector ->
                    ...// inject data into views
                }
                .attachTo(recyclerView)

<a href='https://bintray.com/idik-net/SlimAdapter/SlimAdapter?source=watch' alt='Get automatic notifications about new "SlimAdapter" versions'><img src='https://www.bintray.com/docs/images/bintray_badge_color.png'></a>

License

MIT License

Copyright (c) 2017 认真的帅斌

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.