Skip to content

Instantly share code, notes, and snippets.

View luciofm's full-sized avatar

Lucio Maciel luciofm

View GitHub Profile
@luciofm
luciofm / DebounceLiveData.kt
Created May 13, 2019 16:11
A Debouncing LiveData helper
class DebounceLiveData<Source>(
private val source: LiveData<Source>,
private val debounceMs: Long
) : LiveData<Source>(), CoroutineScope {
private val job = SupervisorJob()
override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job
private var debounceJob: Job? = null
private val observer = Observer<Source> { source ->
@luciofm
luciofm / ChatRoomsFragment.kt
Last active June 13, 2020 14:33
How to run LiveData transformations on a coroutine
class ChatRoomsFragment : Fragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel = ViewModelProviders.of(this, factory).get(ChatRoomsViewModel::class.java)
subscribeUi()
}
private fun subscribeUi() {
@luciofm
luciofm / build.gradle
Created December 2, 2015 14:59
Auto increment version number on release builds... You can change the build type on versionCode.gradle, you also will need to commit and push gradle.properties on your CI
apply from: 'versionCode.gradle'
android {
defaultConfig {
versionName VERSION_NAME
versionCode Integer.parseInt(VERSION_CODE)
}
}