Giter Site home page Giter Site logo

rongi / klaster Goto Github PK

View Code? Open in Web Editor NEW
363.0 5.0 9.0 375 KB

Declare RecyclerView adapters in a functional way, without boilerplate and subclassing. No compromises on flexibility. If it's possible to do something by subclassing, it's possible to do it with this library.

License: MIT License

Kotlin 100.00%
android recyclerview recyclerview-adapter

klaster's People

Contributors

rongi 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

klaster's Issues

Consider using separate builders for view type

val itemType1 = ViewTypeBuilder().itemType(1).view(R.layout.one).bind { view -> // bind to the view} 
 
val itemType2 = ViewTypeBuilder().itemType(2).view(R.layout.two).bind { view -> // bind to the view
 
Then the main builder can maybe take a list of this viewtypes e.g.
Klaster.get()
  .itemCount { articles.size }
  .viewTypes(listOf(itemType1, itemType2, etc, etc))

Missing androidx support?

I am using klaster for the first time and it really is charming to use ๐Ÿฅ‡

However I could not fully test it yet, since in my project I am using androidx. The RecyclerView import therefore differs to the one from klaster, which leads to the following issue:

Type argument is not within its bounds: should be subtype of 'androidx.recyclerview.widget.RecyclerView.ViewHolder'

and

Cannot access class 'androidx.recyclerview.widget.RecyclerView.Adapter'. Check your module classpath for missing or conflicting dependencies

My code looks like this:

private fun createAdapter(movies: MutableList<Movie>) = Klaster.withViewHolder<MovieViewHolder>()
        .itemCount { movies.size }
        .viewHolder { _, parent ->
            val view = layoutInflater.inflate(R.layout.vh_movies, parent, false)
            MovieViewHolder(view)
        }
        .bind { position ->
            val movie = movies[position]
            tvTitle.text = movie.title
        }
        .build()

How can i resolve those issues?

Check that bind works with different view types

.view { viewType, parent ->
    when (viewType) {
      ITEM_TYPE_1 -> layoutInflater.inflate(R.layout.list_item1, parent, false)
      ITEM_TYPE_2 -> layoutInflater.inflate(R.layout.list_item2, parent, false)
      else -> throw IllegalStateException("Unknown type: $viewType")
    }
  }
  .bind { position ->
    // What will happen if the view layout is different ??
  }

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.