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
val timer: TimerTask = object : TimerTask() { | |
override fun run() { | |
Handler().post { | |
//change current page | |
} | |
} | |
} | |
Timer().schedule(timer, DEFAULT_DELAY, DEFAULT_PERIOD) |
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
GlobalScope.launch { | |
increase(DEFAULT_DELAY).collect { currentValue-> | |
print("Current value: $currentValue") | |
} | |
} |
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
suspend fun increase(delay: Long):Flow<Int> = flow { | |
var start = 0 | |
do { | |
emit(start) | |
delay(delay) | |
start++ | |
} while (coroutineContext.isActive) | |
} |
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
fun flipModuleFlow(startPosition: Int, count: Int, delayMillis: Long = 2_000) = flow { | |
var s = startPosition % count | |
do { | |
emit(s) | |
delay(delayMillis) | |
s = (s + 1) % count | |
} while (coroutineContext.isActive) | |
} |
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 startSlide() { | |
slideJob?.cancel() | |
slideJob = lifecycleScope.launchWhenCreated { | |
flipModuleFlow(pager.currentItem, movieImagesAdapter.getAdapterSize()) | |
.collect { currentPosition-> | |
pager.setCurrentItem(currentPosition, true) | |
} | |
} | |
} |
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
inner class SlideTrailersCallback : ViewPager2.OnPageChangeCallback() { | |
override fun onPageSelected(position: Int) { | |
super.onPageSelected(position) | |
startSlide() | |
} | |
} | |
pager.registerOnPageChangeCallback(SlideTrailersCallback()) |
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
GlobalScope.launch { | |
increase(DEFAULT_DELAY).map { | |
it / 2 % 0 | |
}.collect { | |
print("Current value: $it") | |
} | |
} |
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
GlobalScope.launch { | |
increase(DEFAULT_DELAY).take(10).collect { | |
print("Current value: $it") | |
} | |
} |
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
val hotChannelExemple = Channel<String>() | |
launch { | |
hotChannelExemple.send("um") | |
hotChannelExemple.send("dois") | |
hotChannelExemple.send("três") | |
hotChannelExemple.send("quatro") | |
} | |
repeat(2) { println("Collector 1 ${hotChannelExemple.receive()}") } |
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
val coldFlowExemple = (1..3).asFlow() | |
coldFlowExemple.onEach { | |
println("delay") | |
delay(300) | |
}.collect { value -> | |
println("Collector 1 - ${value}") | |
} | |
println("--") |
OlderNewer