A slim & clean & typeable Adapter without# VIEWHOLDER

Overview

PLEASE NOTE, THIS PROJECT IS NO LONGER BEING MAINTAINED

Download GitHub license Platform

First At A Glance :)

SlimAdapter

Intro

logo

A slim & clean & typeable Adapter without# VIEWHOLDER

Features

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

Ex Features

  • Add Header & Footer Unlimitly
  • Auto emptyState with emptyView

Setup

compile 'net.idik:slimadapter:2.1.2'

Usages

Java

Step 0: Create SlimAdapter

SlimAdapter.create()
SlimAdapter.create(SlimAdapterEx.class) //For ex features if need

Step 1: register data types & 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...
                                    }
                                })
        ...;

Step 3: Use SlimAdapter as normal adapter

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

    {
        data.add(new SectionHeader("My Friends"));
        data.add(new User("Jack", 21, R.drawable.icon1, "123456789XX"));
        data.add(new User("Marry", 17, R.drawable.icon2, "123456789XX"));
        data.add(new SectionHeader("My Images"));
        data.add(new Image(R.drawable.cover1));
        data.add(new Image(R.drawable.cover2));
        data.add(new Image(R.drawable.cover3));
        data.add(new Image(R.drawable.cover4));
        data.add(new Image(R.drawable.cover5));
        data.add(new Image(R.drawable.cover6));
        data.add(new Image(R.drawable.cover7));
        data.add(new Image(R.drawable.cover8));
        data.add(new Image(R.drawable.cover9));
        data.add(new Image(R.drawable.cover10));
        data.add(new Image(R.drawable.cover11));
        data.add(new SectionHeader("My Musics"));
        data.add(new Music("Love story", R.drawable.icon3));
        data.add(new Music("Nothing's gonna change my love for u", R.drawable.icon4));
        data.add(new Music("Just one last dance", R.drawable.icon5));
    }
    
    slimAdapter.updateData(data);
    

About SlimAdapterEx

SlimAdapter aims to be "Slim", not "Super", so the SlimAdapter core lib is focus on wrapping the RecycleAdapter to provide a more friendly api.

Anyway, Someone needs a more power Adpter, and this is the reason why SlimAdapterEx exsit.

In a word, SlimAdapterEx is focus on providing some power feature in a slim way.

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)

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.
Comments
  • Can't have fastscroll

    Can't have fastscroll

    I didn't find any way to have a fastscroll with your API. I like to use https://github.com/FutureMind/recycler-fast-scroll but I can't mix the two libraries due to the fact that SlimAdapter is hidden (and so I can't override it and make it implements SectionTitleProvider.

    Having a public constructor instead of a SlimAdapter.create() method would certainly solve that issue.

    enhancement 
    opened by FredJul 5
  • checkbox position issue

    checkbox position issue

    i have add checkbox in user_item checkbox position is change on scroll how to solve it please help.

    and also how to get position on item is click or select

    opened by haris15 4
  • Feature: Loading ViewType

    Feature: Loading ViewType

    I use adapters alongside the recyclerView to load more data and display a progress bar while waiting for the response. Do you guys have suggestions on how to do that using the SlimAdapter? If it's possible to accomplish it I'm changing all my recycler views 😀

    opened by llleodeleon 2
  • SlimInjector IllegalArgumentException (lambda)

    SlimInjector IllegalArgumentException (lambda)

    Using lambda instead of anonymous class make it crash.

    (Episode episode, IViewInjector view) -> {                    
      // code
    })
    

    instead of

    new SlimInjector<Episode>() {
        @Override
        public void onInject(Episode episode, IViewInjector view) {
            // code
        }
    })
    
    opened by fcannizzaro 2
  • IViewInjector new methods

    IViewInjector new methods

    Can you add some methods ?

    like

    injector.alpha(int id, float alpha);
    
    injector.visible(int id, boolean condition);
    
    injector.invisible(int id, boolean condition);
    
    injector.gone(int id, boolean condition);
    

    Great library 👍

    opened by fcannizzaro 2
  • SlimMoreLoader ArrayIndexOutOfBoundsException: length=0; index=-1

    SlimMoreLoader ArrayIndexOutOfBoundsException: length=0; index=-1

    In SlimMoreLoader::onScrollStateChanged() method. In some case, it cased ArrayIndexOutOfBoundsException: length=0; index=-1.

    Well, it comes from findLastCompletelyVisibleItemPosition return -1 ---> getItem(-1).

    The adapter position of the last fully visible view or NO_POSITION if there aren't any visible items. int NO_POSITION Constant Value: -1 (0xffffffff)

    This case happens when the item is height enough to no one completely visible on the screen.

    opened by jkyeo 1
  • Fatal Exception: java.lang.NullPointerException

    Fatal Exception: java.lang.NullPointerException

    Hi. Some of my users are experiencing the following exception:

    Fatal Exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Class java.lang.Object.getClass()' on a null object reference
           at net.idik.lib.slimadapter.SlimAdapter.getItemViewType(SlimAdapter.java:242)
           at net.idik.lib.slimadapter.SlimAdapterEx.getItemViewType(SlimAdapterEx.java:99)
           at android.support.v7.widget.RecyclerView$Recycler.tryGetViewHolderForPositionByDeadline(RecyclerView.java:5507)
           at android.support.v7.widget.GapWorker.prefetchPositionWithDeadline(GapWorker.java:282)
           at android.support.v7.widget.GapWorker.flushTaskWithDeadline(GapWorker.java:336)
           at android.support.v7.widget.GapWorker.flushTasksWithDeadline(GapWorker.java:349)
           at android.support.v7.widget.GapWorker.prefetch(GapWorker.java:356)
           at android.support.v7.widget.GapWorker.run(GapWorker.java:387)
           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:6688)
           at java.lang.reflect.Method.invoke(Method.java)
           at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
           at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358)
    

    It seems to be related to this line in particular. data.get(position); is returning null, hence dataTypes.indexOf(item.getClass()); fails with an NPE (item is null by that time).

    Any idea what might be causing this?

    opened by mradzinski 1
  • List keep getting duplicated

    List keep getting duplicated

    Hi, First of all thanks for the the SlimAdapter. I am facing an issue which I am sure is not a big deal. But I am a newbie so couldn't find the wayout.

    The Issue-

    1. My RecyclerView list gets an addon of a whole set of items everytime I call my activity. That is where I got stuck.
    2. I couldn't import integer value so for the time being I converted it into string but is there a better option for it.

    Thanks

    opened by deamoniz3r 1
  • QUESTION: how can i update just a single section data.

    QUESTION: how can i update just a single section data.

    hi, thanks your lib looks nice, but i looking for a example for how i can update just the data for a single section , for example i have 3 sections and 2 of them are loaded from database but one is loaded from internet , so i need to know how update the last one section when i get the data form internet without reload the others 2 sections.

    is this posible ?

    opened by yesidlazaro 1
  • ParametersAreNonnullByDefault

    ParametersAreNonnullByDefault

    Hello, SlimAdapter is awesome, but when using it from Kotlin, I have to specify each time wether the type is nullable or not. Could the square's solution be implemented?

    https://medium.com/square-corner-blog/non-null-is-the-default-58ffc0bb9111

    This PR is just a starting point, I did not an extensive research of all the functions that should be marked as @Nullable

    opened by jmfayard 1
  • Register with view factory instead of layout id

    Register with view factory instead of layout id

    Hi,

    First of all thank you for this nice lib, I really like the API!

    However, in some cases you really just need a single view into your adapter. In that particular case, being forced to create an layout file with this single view and have to inflate it is not really performant, it would be much more efficient to be able to provide a view factory or any similar concept to the register method.

    opened by FredJul 1
  • How we can programmatically (automatically) click on specific item?

    How we can programmatically (automatically) click on specific item?

    In normal Adapter we can perform Click like this

    recyclerView.findViewHolderForAdapterPosition(pos).itemView.performClick();

    How this functionality achieve in SlimAdapter?

    opened by Talhasahi 0
  • Recyclerview Changing Items During Scroll

    Recyclerview Changing Items During Scroll

    My list contain videos and on scroll back the video is playing in diffrent position if item1 was playing video1 but when scroll back item 1 is playing video 4

    opened by midhilajm 0
  • Can you add item animation?

    Can you add item animation?

    I like to use SlimAdapter, but now I want to use item animation when I delete or add item, but I can do it in SlimAdapter. Can you add this feature, or you have a suggestion for me?

    nb: I just want to use simple fade animation when add item and item shift when I delete.

    opened by jrizani 1
The bullet proof, fast and easy to use adapter library, which minimizes developing time to a fraction...

FastAdapter The FastAdapter is here to simplify creating adapters for RecyclerViews. Don't worry about the adapter anymore. Just write the logic for h

Mike Penz 3.7k Jan 8, 2023
An Adapter that allows a RecyclerView to be split into Sections with headers and/or footers. Each Section can have its state controlled individually.

⚠️ Archived: this repository is no longer going to be maintained. SectionedRecyclerViewAdapter An Adapter that allows a RecyclerView to be split into

Gustavo Pagani 1.7k Dec 21, 2022
Android - A ListView adapter with support for multiple choice modal selection

MultiChoiceAdapter MultiChoiceAdapter is an implementation of ListAdapter which adds support for modal multiple choice selection as in the native Gmai

Manuel Peinado Gallego 855 Nov 11, 2022
Create a new adapter for a RecyclerView or ViewPager is now much easier.

Efficient Adapter for Android Create a new adapter for a RecyclerView or ViewPager is now much easier. Overview Create a list of elements into a Recyc

Stan Kocken 423 Sep 16, 2022
Adapter Kit is a set of useful adapters for Android.

Adapter Kit Adapter Kit is a set of useful adapters for Android. The kit currently includes, Instant Adapter Instant Cursor Adapter Simple Section Ada

Ragunath Jawahar 368 Nov 25, 2022
Simplify Adapter creation for your Android ListViews.

FunDapter takes the pain and hassle out of creating a new Adapter class for each ListView you have in your Android app. It is a new approach to custom

Ami Goldenberg 287 Dec 22, 2022
Rx based RecyclerView Adapter

RxRecyclerAdapter Rx based generic RecyclerView Adapter Library. How to use it? Example! Enable Databinding by adding these lines to your build.gradle

Ahmed Rizwan 193 Jun 18, 2022
This Repository simplifies working with RecyclerView Adapter

AutoAdapter This Repository simplifies working with RecyclerView Adapter Gradle: Add it in your root build.gradle at the end of repositories: allproj

George Dzotsenidze 151 Aug 15, 2021
Generic RecyclerView adapter

Generic RecyclerView Adapter. Lightweight library which simplifies creating RecyclerView adapters and illuminates writing boilerplate code. Creating a

Leonid Ustenko 77 Dec 24, 2022
Android library for the adapter view (RecyclerView, ViewPager, ViewPager2)

Antonio Android library for the adapter view (RecyclerView, ViewPager, ViewPager2) Free from implementation of the adapter's boilerplate code ! Reuse

NAVER Z 106 Dec 23, 2022
Small, smart and generic adapter for recycler view with easy and advanced data to ViewHolder binding.

smart-recycler-adapter Never code any boilerplate RecyclerAdapter again! This library will make it easy and painless to map your data item with a targ

Manne Öhlund 405 Dec 30, 2022
Don't write a RecyclerView adapter again. Not even a ViewHolder!

LastAdapter Don't write a RecyclerView adapter again. Not even a ViewHolder! Based on Android Data Binding Written in Kotlin No need to write the adap

Miguel Ángel Moreno 781 Dec 19, 2022
Don't write a RecyclerView adapter again. Not even a ViewHolder!

LastAdapter Don't write a RecyclerView adapter again. Not even a ViewHolder! Based on Android Data Binding Written in Kotlin No need to write the adap

Miguel Ángel Moreno 781 Dec 19, 2022
Add RecyclerView, use Adapter class and ViewHolder to display data.

فكرة المشروع في هذا المشروع سنقوم بعرض قائمة من البيانات للطلاب على واجهة تطبيق Android بإستخدام: مفهوم RecyclerView مفهوم Adapter مفهوم ViewModel محت

Shaima Alghamdi 3 Nov 18, 2021
A beautiful, slim Android ProgressBar.

Android NumberProgressBar The NumberProgressBar is a bar, slim and sexy (every man wants! ). I decided to do this because I was really tired of androi

代码家 6k Jan 7, 2023
🎶🎼 Very slim music player 👨‍🎤 100% made in Italy 🍕🌳🌞🍝🌄

Source code for the Android music player Music Player GO

Enrico D'Ortenzio 1.2k Jan 2, 2023
Open Source Library for Holdable ViewHolder in RecyclerView

HoldableSwipeHandler Open Source Library for Holdable ViewHolder in RecyclerView

null 10 May 11, 2022
Android Clean Architecture💎 Base Project Android with Kotlin and MVVM applying clean architecture

Android Clean Architecture?? Base Project Android with Kotlin and MVVM applying clean architecture

Mina Mikhail 103 Dec 2, 2022
Chat App MVVM + Clean ArchitectureChat App MVVM + Clean Architecture

Chat App MVVM + Clean Architecture This Android application built using MVVM + Clean Architecture architecture approach and is written 100% in Kotlin.

null 4 Nov 29, 2022