Skip to content

Instantly share code, notes, and snippets.

View LDRAlighieri's full-sized avatar
💭
I need 48 hours a day...

Vladimir Raupov LDRAlighieri

💭
I need 48 hours a day...
View GitHub Profile
@LDRAlighieri
LDRAlighieri / corbind-texview-textchanges-flow.kt
Last active August 16, 2019 13:34
Example of handling TextView events as Flow<CharSequence>
/* add dependency in gradle file */
implementation 'ru.ldralighieri.corbind:corbind:{latest_version}'
findViewById<EditText>(R.id.et_name)
.textChanges() // Flow<CharSequence>
.onEach { /* handle text change events */ }
.launchIn(scope)
@LDRAlighieri
LDRAlighieri / corbind-viewpager-pageselections-channel.kt
Last active August 16, 2019 13:34
Example of handling ViewPager events as ReceiveChannel<Int>
/* add dependency in gradle file */
implementation 'ru.ldralighieri.corbind:corbind-viewpager:{latest_version}'
launch {
findViewById<ViewPager>(R.id.vp_slides)
.pageSelections(scope) // ReceiveChannel<Int>
.consumeEach {
/* handle ViewPager events */
}
}
@LDRAlighieri
LDRAlighieri / corbind-view-clicks-action.kt
Last active August 16, 2019 13:26
Example of handling Button events as action
/* add dependency in gradle file */
implementation 'ru.ldralighieri.corbind:corbind:{latest_version}'
launch {
findViewById<AppCompatButton>(R.id.bt_confirm)
.clicks {
/* perform an action on View click events */
}
}
@LDRAlighieri
LDRAlighieri / corbind-loggin-button-enabled.kt
Created August 16, 2019 13:56
Example of login button enabling/disabling by email and password field validation
combine(
et_email.textChanges()
.map { Patterns.EMAIL_ADDRESS.matcher(it).matches() },
et_password.textChanges()
.map { it.length > 7 },
transform = { email, password -> email && password }
)
.onEach { bt_login.isEnabled = it }
@LDRAlighieri
LDRAlighieri / composites-fiberglass-items-example.kt
Last active January 28, 2023 19:44
Example of Fiberglass screen items that can be drawn
data class SpacerItem(val height: Int) : FiberglassItem {
override val id: String = UUID.randomUUID().toString()
}
data class TitleItem(val title: String) : FiberglassItem {
override val id: String = title
}
data class LoremIpsumItem(private val words: Int) : FiberglassItem {
val text = LOREM_IPSUM_SOURCE.take(words).joinToString(separator = " ")
@LDRAlighieri
LDRAlighieri / composites-fiberglass-slots-example.kt
Last active February 3, 2024 07:04
Example of Fiberglass screen slots for items
fun spacerItemSlot(): FiberglassLazyItemSlot = { _, item ->
Spacer(modifier = Modifier.height((item as SpacerItem).height.dp))
}
fun titleItemSlot(): FiberglassLazyItemSlot = { _, item ->
Text(
text = (item as TitleItem).title,
modifier = Modifier.padding(horizontal = AppTheme.dimensions.horizontalGuideline),
color = AppTheme.colors.onBackground,
style = AppTheme.typography.headlineMedium
@LDRAlighieri
LDRAlighieri / composites-fiberglass-lazy-column-example.kt
Last active February 3, 2024 07:05
Example of Fiberglass lazy column
@Composable
private fun FiberglassColumnContent() {
val items: List<FiberglassItem> = remember {
buildList {
val count = 4
repeat(count) {
val number = it + 1
add(TitleItem("Block №$number"))
add(LoremIpsumItem(20 * number))
if (number < count) add(SpacerItem(16))
@LDRAlighieri
LDRAlighieri / corbind-activity-backPresses-example.kt
Created February 17, 2023 17:47
Example of corbind-activity OnBackPressedDispatcher.backPresses extension
onBackPressedDispatcher.backPresses(lifecycleOwner = this)
.onEach { currentFlowFragment?.onBackPressed() }
.launchIn(lifecycleScope)
@LDRAlighieri
LDRAlighieri / corbind-fragment-resultEvents-example.kt
Last active February 17, 2023 19:31
Example of corbind-fragment FragmentManager.resultEvents extension
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
parentFragmentManager.resultEvents(
requestKey = RESULT_DATA_KEY,
lifecycleOwner = this@ResultFragment
)
.mapNotNull { it.bundle.toResultData() }
.onEach(::renderResultData)
.launchIn(this)
}
@LDRAlighieri
LDRAlighieri / corbind-viewpager2-pageScrollEvents-example.kt
Last active February 17, 2023 19:28
Example of corbind-viewpager2 ViewPager2.pageScrollEvents extension
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
detailsViewPager.pageScrollEvents()
.filter { it.positionOffset == 0f }
.map { it.position }
.distinctUntilChanged()
.onEach(::onPositionChanged)
.launchIn(this)
}
}