Created
January 20, 2020 15:28
-
-
Save fluxtah/fc451dafd850e11178a9c25871bab9f7 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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