Skip to content

Instantly share code, notes, and snippets.

@fluxtah
Created January 20, 2020 15:28
Show Gist options
  • Save fluxtah/fc451dafd850e11178a9c25871bab9f7 to your computer and use it in GitHub Desktop.
Save fluxtah/fc451dafd850e11178a9c25871bab9f7 to your computer and use it in GitHub Desktop.
class InfiniteHelloJubakoActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_jubako_recycler)
recyclerView.withJubako(this).load(HelloAssembler())
}
class HelloAssembler : SimpleJubakoAssembler() {
var counter = 0
//
// Always has more == infinite!
// Normally you should calculate this value, for instance
// start returning false when you get to the end
// of your data source
//
override fun hasMore() = true
override suspend fun onAssemble(list: MutableList<ContentDescriptionProvider<Any>>) {
// pages of ten
for (i in 0 until 10) {
val num = ++counter
list.addView { textView(it, "Hello Jubako! $num") }
}
}
private fun textView(parent: ViewGroup, text: String): TextView {
return TextView(parent.context).apply {
setText(text)
setTextSize(TypedValue.COMPLEX_UNIT_DIP, 48f)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment