Skip to content

Instantly share code, notes, and snippets.

View WendyYanto's full-sized avatar

Wenn WendyYanto

  • Singapore
View GitHub Profile
@WendyYanto
WendyYanto / ViewStub.kt
Last active December 13, 2020 12:23
Lazyload
private fun isViewShown(): Boolean {
return (parentView.scrollY + screenHeight) >= viewStub.top
}
class LazyLoadComponent @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : LinearLayout(context, attrs) {
private val viewStub by lazy {
ViewStub(context, attrs)
}
init {
with(viewStub) {
<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 RxJavaTest {
companion object {
private const val USER_ID = "USER_ID"
private const val NAME = "John Doe"
private const val AGE = 20
}
@Test
fun getUser() {
User(id=USER_ID, name=John Doe, age=20)
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
get user
UserID is invalid