Kotlin Extensions Function and Properties

December 28, 2018

Extensions Function

fun Location.toLatLng() = LatLng(latitude, longitude)

fun <T> LiveData<T>.observeOnce(lifecycleOwner: LifecycleOwner, observer: Observer<T>) {
    observe(lifecycleOwner, object : Observer<T> {
        override fun onChanged(t: T?) {
            observer.onChanged(t)
            removeObserver(this)
        }
    })
}

Extensions Property

val Location.secondsElapsed: Long
    get() = LocalDateTime.now(ZoneOffset.UTC).toEpochSecond(ZoneOffset.UTC) - (time/1000)

References:

This work is licensed under a
Creative Commons Attribution-NonCommercial 4.0 International License.