Skip to content

Instantly share code, notes, and snippets.

View WendyYanto's full-sized avatar

Wenn WendyYanto

  • Singapore
View GitHub Profile
<resources>
<declare-styleable name="LazyLoadComponent">
<attr name="layout_res" format="reference" />
<attr name="parent_layout_id" format="reference" />
</declare-styleable>
</resources>
init {
val typeArray = context.theme.obtainStyledAttributes(attrs, R.styleable.LazyLoadComponent, 0, 0)
val parentResId = typeArray.getResourceId(R.styleable.LazyLoadComponent_parent_layout_id, -1)
val layoutRes = typeArray.getResourceId(R.styleable.LazyLoadComponent_layout_res, -1)
with(viewStub) {
layoutResource = layoutRes
addView(this)
}
class LazyLoadComponent @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {
private val viewStub by lazy {
ViewStub(context, attrs)
}
init {
with(viewStub) {
@WendyYanto
WendyYanto / ViewStub.kt
Last active December 13, 2020 12:23
Lazyload
private fun isViewShown(): Boolean {
return (parentView.scrollY + screenHeight) >= viewStub.top
}
User(id=USER_ID, name=John Doe, age=20)
class RxJavaTest {
companion object {
private const val USER_ID = "USER_ID"
private const val NAME = "John Doe"
private const val AGE = 20
}
@Test
fun getUser() {
get user
UserID is invalid
class RxJavaUnitTest {
companion object {
private const val NAME = "John Doe"
private const val AGE = 20
private const val EMPTY = ""
}
@Test
fun getUserWithError() {
class RxJavaUnitTest {
companion object {
private const val USER_ID = "USER_ID"
private const val NAME = "John Doe"
private const val AGE = 20
private const val EMPTY = ""
}
@Test