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-material-checkedChanges-example.kt
Created February 17, 2023 18:01
Example of corbind-material ChipGroup.checkedChanges extension
binding.choiceChipGroup.checkedChanges()
.dropInitialValue()
.map { checkedIds -> state.change(checkedIds) }
.shareIn(scope = scope, started = SharingStarted.Eagerly, replay = 1)
@LDRAlighieri
LDRAlighieri / corbind-material-valueChanges-example.kt
Created February 17, 2023 17:59
Example of corbind-material Slider.valueChanges extension
minVisibleItemsSlider.valueChanges()
.onEach { count -> expandableCell.minVisibleItems = count.roundToInt() }
.launchIn(scope)
@LDRAlighieri
LDRAlighieri / corbind-receivesBroadcast-example.kt
Last active February 17, 2023 17:56
Example of corbind Context.receivesBroadcast extension
context
.receivesBroadcast(IntentFilter(nfcAction))
.map { it.getNfcState() }
.distinctUntilChanged()
.onEach { _nfcState.value = it }
.launchIn(scope)
@LDRAlighieri
LDRAlighieri / corbind-viewpager2-pageSelections-example.kt
Last active February 17, 2023 19:31
Example of corbind-viewpager2 ViewPager2.pageSelections extension
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
productsViewPager.pageSelections()
.onEach(::onPageSelected)
.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)
}
}
@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-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 / 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 / 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-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 = " ")