This file contains 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
<resources> | |
<declare-styleable name="LazyLoadComponent"> | |
<attr name="layout_res" format="reference" /> | |
<attr name="parent_layout_id" format="reference" /> | |
</declare-styleable> | |
</resources> |
This file contains 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
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) | |
} |
This file contains 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 LazyLoadComponent @JvmOverloads constructor( | |
context: Context, attrs: AttributeSet? = null | |
) : LinearLayout(context, attrs) { | |
private val viewStub by lazy { | |
ViewStub(context, attrs) | |
} | |
init { | |
with(viewStub) { |
This file contains 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
private fun isViewShown(): Boolean { | |
return (parentView.scrollY + screenHeight) >= viewStub.top | |
} |
This file contains 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
User(id=USER_ID, name=John Doe, age=20) |
This file contains 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 RxJavaTest { | |
companion object { | |
private const val USER_ID = "USER_ID" | |
private const val NAME = "John Doe" | |
private const val AGE = 20 | |
} | |
@Test | |
fun getUser() { |
This file contains 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
user ID is invalid |
This file contains 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
get user | |
UserID is invalid |
This file contains 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 RxJavaUnitTest { | |
companion object { | |
private const val NAME = "John Doe" | |
private const val AGE = 20 | |
private const val EMPTY = "" | |
} | |
@Test | |
fun getUserWithError() { |
This file contains 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 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 |
OlderNewer