Code Monkey home page Code Monkey logo

diff-adapter's Introduction

diff-adapter Build Status Maven Central

Gradle:

implementation 'ru.starksoft:diff-adapter:1.x.x'

Usage:

DiffAdapter
    .create(adapterDataSource)
    // Reflection-based factory
    .withViewHolders(SampleViewHolder::class.java, HeaderViewHolder::class.java, DataInfoViewHolder::class.java)
    //	Second variant to attach ViewHolders, without reflection
    .withFactory(ViewHolderFactory { parent, viewType, onClickListener ->
        return@ViewHolderFactory when (viewType) {
            DifferViewModel.getItemViewType(SampleViewModel::class.java) -> SampleViewHolder(parent, onClickListener)
            DifferViewModel.getItemViewType(HeaderViewModel::class.java) -> HeaderViewHolder(parent, onClickListener)
            DifferViewModel.getItemViewType(DataInfoViewModel::class.java) -> DataInfoViewHolder(parent, onClickListener)

            else -> throw IllegalStateException("Unknown viewType=$viewType at ${javaClass.simpleName}")
        }
    })
    .withClickListener(OnClickListener { _, viewModel, action, _ ->
        return@OnClickListener when (action) {
            SampleClickAction.DELETE.ordinal -> {
                adapterDataSource.remove((viewModel as SampleViewModel).id)
                true
            }
            SampleClickAction.DELETE_MULTI.ordinal -> {
                (activity as AppCompatActivity?)?.startSupportActionMode(actionModeCallback)
                true
            }
            else -> false
        }
    })
    .initAdapter()
    .attachTo(sampleRecyclerView, createDifferAdapterEventListener(), refreshAdapterOnAttach = true)

If you are using reflection-based factory .withViewHolders add this in proguard file:

-keep public class * extends ru.starksoft.differ.adapter.viewholder.DifferViewHolder {
    *;
}

License:

            GNU LESSER GENERAL PUBLIC LICENSE
		       Version 2.1, February 1999

 Copyright (C) 1991, 1999 Free Software Foundation, Inc.
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 Everyone is permitted to copy and distribute verbatim copies
 of this license document, but changing it is not allowed.

[This is the first released version of the Lesser GPL.  It also counts
 as the successor of the GNU Library Public License, version 2, hence
 the version number 2.1.]

diff-adapter's People

Contributors

pazaryan avatar starksoft avatar

Stargazers

 avatar  avatar

Watchers

 avatar  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.