Merge pull request #58 from TouchInstinct/feature/add-void-single-live-event-support
Feature/add NewSingleLiveEvent that supports Void event
This commit is contained in:
commit
6d180f6b06
|
|
@ -0,0 +1,28 @@
|
|||
package ru.touchin.lifecycle.livedata
|
||||
|
||||
import androidx.annotation.MainThread
|
||||
|
||||
/**
|
||||
* A lifecycle-aware observable that sends only new updates after subscription, used for events like
|
||||
* navigation and Snackbar messages.
|
||||
*
|
||||
*
|
||||
* This avoids a common problem with events: on configuration change (like rotation) an update
|
||||
* can be emitted if the observer is active. This LiveData only calls the observable if there's an
|
||||
* explicit call to setValue() or call().
|
||||
*
|
||||
*
|
||||
* Note that only one observer is going to be notified of changes.
|
||||
*
|
||||
* This version of SingleLiveEvent supports empty events
|
||||
*/
|
||||
class EmptySingleLiveEvent : SingleLiveEvent<Void?>() {
|
||||
@MainThread
|
||||
fun call() {
|
||||
value = null
|
||||
}
|
||||
|
||||
fun postCall() {
|
||||
super.postValue(null)
|
||||
}
|
||||
}
|
||||
|
|
@ -5,7 +5,7 @@ import androidx.lifecycle.MutableLiveData
|
|||
import androidx.lifecycle.Observer
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
|
||||
class SingleLiveEvent<T> : MutableLiveData<T>() {
|
||||
open class SingleLiveEvent<T> : MutableLiveData<T>() {
|
||||
|
||||
private val pending = AtomicBoolean(false)
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ project(':lifecycle-rx').projectDir = new File(rootDir, 'lifecycle-rx')
|
|||
project(':views').projectDir = new File(rootDir, 'views')
|
||||
project(':recyclerview-adapters').projectDir = new File(rootDir, 'recyclerview-adapters')
|
||||
project(':kotlin-extensions').projectDir = new File(rootDir, 'kotlin-extensions')
|
||||
project(':recyclerview-calendar').projectDir = new File(gradle.ext.componentsRoot, 'recyclerview-calendar')
|
||||
project(':recyclerview-calendar').projectDir = new File(rootDir, 'recyclerview-calendar')
|
||||
project(':tabbar-navigation').projectDir = new File(rootDir, 'tabbar-navigation')
|
||||
project(':base-map').projectDir = new File(rootDir, 'base-map')
|
||||
project(':yandex-map').projectDir = new File(rootDir, 'yandex-map')
|
||||
|
|
|
|||
Loading…
Reference in New Issue