SkillAgentSearch skills...

YasuoRecyclerViewAdapter

一个能让你感受到快乐的RecyclerViewAdapter库,A RecyclerViewAdapter library that can make you feel happy

Install / Use

/learn @q876625596/YasuoRecyclerViewAdapter
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

YasuoRecyclerViewAdapter

A RecyclerViewAdapter library that can make you feel happy

[Language] English | 中文文档

Image from:https://www.zcool.com.cn/work/ZNDU0NzA2MTY=.html

Ⅰ、Preface

YasuoRecyclerViewAdapter ! Let you happy realization list in Android ! 掘金 简书

Ⅱ、Main

Here's a brief introduction to this library:YasuoRecyclerViewAdapter ,Why Yasuo, because Yasuo = = happy! This library is for everyone to feel happy when writing code!

1、Functional features

①、Normal layout and multi layout of list, grid and stageredgrid

②、EmptyLayout/Header/Footer

③、LoadMore

**④、 Folding layout (support multi-level fold) **

⑤、Drag, slide delete

⑥、Two ItemDecoration are attached, which can be selected according to different needs

⑦、The ObservableList is used as the data source without manual notify

⑧、Support findViewById, ViewBinding, DataBinding three modes, according to your existing project mode or preferences to change!

⑨、Highly configurable animation (after comprehensive consideration, the itemanimator scheme of recyclerview is adopted. If necessary, please rely on the ItemAnimators Library of mikepenz)

⑩、Stick header (using sticky-layoutmanager Because there are some bugs in the position acquisition of the original library, we integrate them into this project and fix the bugs.)

2、For the latest version, please see jitpack

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
dependencies {
    implementation 'com.github.q876625596:YasuoRecyclerViewAdapter:x.y.z'
}

2、示例展示

If you want to use Ctrl + CV code directly, please move sample directly

sticky.gif loadMore.gif emptyLayout,header,footer.gif fold.gif drag,swipr delete.gif

3、Detailed introduction

1)Data source

You must use YasuoList or its subclass as the data source. Yasuolist inherits from observablearraylist, adds some common methods, and listens inside the adapter. Therefore, you can use this type of data source without manually notifying

2)Simple writing(Single layout/Multi layout/Header/Footer)
    fun findViewByIdMode(){
        //data source
        val list = YasuoList<Any>()
        val headerList = YasuoList<Any>()
        val footerList = YasuoList<Any>()
        binding.myRV.layoutManager = GridLayoutManager(this, 3)
        //findViewById mode
        binding.myRV.adapterBinding(this,list){
            //do something
            //Binding text layout
            //Just configure holderConfig for the corresponding layout to realize multi layout, header and footer
            holderConfig(R.layout.item_layout_text, TextBean::class) {
                onHolderBind { holder, item ->
                    holder.getView<TextView>(R.id.itemText).apply {
                        text = item.text.value
                    }
                }
            }
        }
        //ViewBinding mode
        binding.myRV.adapterViewBinding(this,list){
            //do something
            //Binding text layout
            //Just configure holderConfig for the corresponding layout to realize multi layout, header and footer
            holderConfig(R.layout.item_layout_text, TextBean::class, { ItemLayoutTextBinding.bind(it) }) {
                onHolderBind { holder, item ->
                    itemText.text = item.text.value
                }
            }
        }
        //DataBinding mode
        binding.myRV.adapterDataBinding(this,list){
            //do something
            //Binding text layout
            //Just configure holderConfig for the corresponding layout to realize multi layout, header and footer
            holderConfig(R.layout.item_layout_text_data_binding, TextBean::class, ItemLayoutTextDataBindingBinding::class) {
                onHolderBind { holder ->
                    //The databinding schema has already bound data in XML, so there is no need to set it manually
                }
            }
        }
    }

There is only one difference between the above three modes, and it is quite convenient to switch between them.

Additional ViewPager2Adapter adapterDataBinding can be replaced by adapterViewBinding, adapterBinding When creating a layout, you should pay attention to: br.vpItem is the default value in adapterDataBinding

    binding.viewPager.adapterDataBinding(this, list) {
        holderConfigVP(R.layout.empty_layout_one_data_binding, EmptyBeanOne::class, EmptyLayoutOneDataBindingBinding::class) {

        }
        holderConfigVP(R.layout.empty_layout_two_data_binding, EmptyBeanTwo::class, EmptyLayoutTwoDataBindingBinding::class) {

        }
     }
3)Empty Layout

The use of empty layout is also very simple. First configure the holderConfig of empty layout, and then call adapter.showEmptyLayout That's it.

        binding.myRV.adapterViewBinding(this,list){
            //do something
            holderConfig(R.layout.item_layout_text, TextBean::class, { ItemLayoutTextBinding.bind(it) }) {
                onHolderBind { holder, item ->
                    itemText.text = item.text.value
                    itemText.setOnClickListener {
                        showEmptyLayout(/*Empty layout entity*/EmptyBeanTwo(), /*Clear header*/true, /*Clear footer*/true)
                    }
                }
            }
        }
4)Set span for layout

There are two ways to set the proportion. The first is to set the proportion for one type of layout:

        binding.myRV.adapterViewBinding(this,list){
            //do something
            holderConfig(R.layout.item_layout_text, TextBean::class, { ItemLayoutTextBinding.bind(it) }) {
                //do something
                //Set the layout of an itemViewType uniformly
                //The staggeredGridLayouytManager filled the line
                staggeredGridFullSpan = true
                //gridLayoutManager Span
                gridSpan = 3
            }
        }

Second, set the proportion of an item separately:

        list.add(ImageBean(MutableLiveData(ContextCompat.getDrawable(this@MainActivity, R.drawable.eee))).apply {
                    //To set an item individually
                    //The staggeredGridLayouytManager filled the line
                    staggeredGridFullSpan = true
                    //gridLayoutManager Span
                    gridSpan = 3
        }

Judging priority: single item setting > type setting

5)LoadMore

Loading more layouts is similar to loading empty layouts. After loading the holderConfig configuration of more layouts, call adapter.showLoadMoreLayout Make the empty layout display and add it at last adapter.onLoadMoreListener Just monitor.

        binding.myRV.adapterViewBinding(this,list){
            //Show load more
            showLoadMoreLayout(DefaultLoadMoreItem())
            //Set to load more listeners
            onLoadMoreListener(binding.myRV) {
                //Request data...
            }
            //do something
        }
6)Drag / swipe delete

Just use adapter.enableDragOrSwipeYou can enable drag and drop, set monitor, set gesture direction, and disable certain layouts

        binding.myRV.adapterViewBinding(this,list){
            //Drag / swipe delete
            enableDragOrSwipe(binding.myRV, isLongPressDragEnable = true, isItemViewSwipeEnable = true)
            //do something
        }
7)Sticky header

First, set the layout manager: stickylinear layout manager, stickygridlayout manager, stickystaged GridLayout manager There are two ways of Sticky header. The first is to set Sticky header for a certain type of layout

        binding.myRV.adapterViewBinding(this,list){
            //do something
            holderConfig(R.layout.item_layout_text, TextBean::class, { ItemLayoutTextBinding.bind(it) }) {
                //Set the layout of an itemViewType uniformly
                //Sticky header. Note that sticky header will fill one line by default
                sticky = true
                //do something
            }
        }

Second, set the Sticky header for an item

list.add(ImageBean(MutableLiveData(ContextCompat.getDrawable(this@MainActivity, R.drawable.eee))).apply {
        //To set an item individually
        //Sticky header. Note that sticky header will fill one line by default
        sticky = true
}
View on GitHub
GitHub Stars51
CategoryDevelopment
Updated1y ago
Forks5

Languages

Kotlin

Security Score

80/100

Audited on Apr 23, 2024

No findings