Skip to content

Instantly share code, notes, and snippets.

@fluxtah
Created January 20, 2020 15:26
Show Gist options
  • Save fluxtah/0a897369be5d745e341def6c5079fe91 to your computer and use it in GitHub Desktop.
Save fluxtah/0a897369be5d745e341def6c5079fe91 to your computer and use it in GitHub Desktop.
// Set page size to 1 so we can see it loading (descriptions are delayed by 500ms)
recyclerView.withJubako(this, pageSize(1)).load {
(0 until 100).forEach { i ->
addRecyclerView(
//
// Inflate a view for our carousel
//
view = { inflater, parent ->
inflater.inflate(R.layout.simple_carousel, parent, false)
},
//
// Provide a lambda that will create our carousel item view holder
//
itemViewHolder = { inflater, parent, _ ->
SimpleCarouselItemViewHolder(inflater, parent)
},
//
// Specify the data that will be loaded into the carousel
//
data = when {
i % 2 == 0 -> getNumbersEnglish()
else -> getNumbersJapanese()
},
//
// Provide a lambda that will fetch carousel item data by position
//
itemData = { data, position -> data[position] },
//
// Specify a lambda that will provide the count of item data in our carousel
//
itemCount = { data -> data.size },
//
// Specify a viewBinder that will allow binding between data and item holder
//
itemBinder = { holder, data ->
holder.itemView.findViewById<TextView>(R.id.text).text = data
}
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment