Setup #
android{
buildFeatures {
viewBinding true
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach{
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}
dependencies {
implementation 'io.github.shawxingkwok:android-util-view:1.0.8'
}
android{
buildFeatures {
viewBinding = true
}
}
tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach {
kotlinOptions.freeCompilerArgs += "-Xcontext-receivers"
}
dependencies {
implementation("io.github.shawxingkwok:android-util-view:1.0.8")
}
Functions #
Flow.collectOnResumed #
Is used in Fragment.onCreateView
or Fragment.onViewCreated
to
collect flow
with collector
after every Fragment.onResume
.
Switch from
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
flow.collect {
...
}
}
}
}
to
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
flow.collectOnResumed{
...
}
}
Flow.collectOnStarted #
This is similar to Flow.collectOnResumed.
View.onClick #
Sets a View.OnClickListener
with a more precise View
.
KRecyclerViewAdapter #
Common cases #
Take the example of this contact page.
Layout resources are not displayed. The function
binding(FragmentMainBinding::bind)
is
from another library and independent withKRecyclerViewAdapter
.
Partial update with oldContentId
#
This is only used in some special cases like items are massive or source data vary quite frequently like this stopwatch example.
More #
Future functionalities #
KRecyclerViewAdapter
: drag, swipe and set stickHeader likeCompose
.