Coder Social home page Coder Social logo

linisme / slimadapter Goto Github PK

View Code? Open in Web Editor NEW
933.0 933.0 118.0 4.99 MB

A slim & clean & typeable Adapter without# VIEWHOLDER

Home Page: https://raw.githubusercontent.com/MEiDIK/SlimAdapter/master/SlimAdapter.jpg

License: MIT License

Java 95.39% Kotlin 4.61%
adapter android kotlin recyclerview

slimadapter's Introduction

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.

slimadapter's People

Contributors

fcannizzaro avatar hl3hl3 avatar jkyeo avatar linisme 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

slimadapter's Issues

Fastscroller support

Can we use fast scroller with slimadapter ? if yes can you provide a example please?

Support for PagedList

Google just release the new Paging lib which has the potential to clearly improve performances in some cases.

Google basically recommands to use a PagedListAdapter, but it would be great to be able to give SlimAdapter a PagedList as well.

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 😀

glide不生效

register(R.layout.classification_item, new SlimInjector(){

			@Override
			public void onInject(final Classification classification, IViewInjector injector) {
				injector.with(R.id.classification_item_shopimg, new IViewInjector.Action<ImageView>(){

						@Override
						public void action(ImageView v) {
							if (classification.shopimg.equals("")) {
								Glide.with(MainActivity.this).load(R.mipmap.ic_launcher).into(v);
								v.setImageResource(R.mipmap.ic_launcher);
							} else {
								Glide.with(MainActivity.this).load("http://test.com/" + classification.shopimg).into(v);
							}
						}
					})
					.clicked(R.id.classification_item_cardView, new OnClickListener(){

						@Override
						public void onClick(View v) {
							Intent intent=new Intent(MainActivity.this, ToolActivity.class);
							intent.putExtra("name", classification.name);
							intent.putExtra("cid", classification.cid);
							startActivity(intent);
						}
					})
					.text(R.id.classification_item_name, classification.name);
			}
		})

这个glide根本就不加载图片出来诶。。

Support stableId

Stable id feature makes RecyclerView's view holder cache more efficient and faster when we call notify data set changed.If i use SlimAdapter,to enable stable id feature, i must write a subclass.If SlimAdapter support stable id feature,that would be great.mo mo da.

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?

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

with方法冲突

用kotlin时injector.with(int id, Action action)方法与kotlin扩展类方法with(receiver: T, block: T.() -> R) 方法冲突啊

not The DEFAULT injector found...

slimAdapter = SlimAdapter.create()
.register(R.layout.question_card, new SlimInjector() {
@OverRide
public void onInject(QuestionsModel data, IViewInjector injector) {
injector.text(R.id.question,data.getTitle());
}
})
.register(R.layout.answer_card, new SlimInjector() {
@OverRide
public void onInject(AnswersModel data, IViewInjector injector) {
injector.text(R.id.answer,data.getTitle());
}
});

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 👍

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 ?

Add containerClick

Many times, we need to support click on whole element, so if it's possible, could you add methods
.click and .longClick without additional ID parameter, and pass that to whole injected view?

How to filter search

Hi there, since I have to two layout which is header and list layout. The question is that when user want to find search word in list layout instead of header layout how to do that?

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.

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.

请问一下作者,如何实现下拉刷新,上拉加载更多,以及headerView/footerView的点击事件。

首先感谢作者,给我们开发者带来如此方便的开源项目。
已经使用SlimAdapter很长时间,已经养成了一种习惯,
所以想请问一下作者,如何实现下拉刷新,上拉加载更多?
目前我使用过程中,遇到需要使用headerView/footerView时,
不知道如何添加headerView/footerView的点击事件。
所以只能通过其他view添加到RecycleView上/下,以实现类似headerView/footerView的点击事件。

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

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
    }
})

register layout contain recyclerview

how i can register for a layout contain recyclerview that it want to be filled ?
and how to pass data list ?any method or somethings else?
in other word ReyclerView in RecyclerView.

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.

Nested Adapter

Can we add a nested SlimAdapter for effects like horizontal and vertical list

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.

How to incress speed

How to incress scrolling speed

My recyclerview with videoview jumbing when scrolling

Custom ViewType

It would be awesome if we could provide custom view types when registering a view. Right now they get generated as soon as a view needs to become available, and this makes impossible for example to prevent the recycling of a certain kind of items.

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.