Created
December 21, 2017 20:12
-
-
Save sagix/457904ab8f41da5d91d343cc915abbd1 to your computer and use it in GitHub Desktop.
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
@file:JvmName("MutableDecoratorUtils") | |
package com.nicolasmouchel.executordecorator.android.arch.lifecycle | |
import android.arch.lifecycle.Lifecycle | |
import android.arch.lifecycle.LifecycleObserver | |
import android.arch.lifecycle.LifecycleOwner | |
import android.arch.lifecycle.OnLifecycleEvent | |
import com.nicolasmouchel.executordecorator.MutableDecorator | |
@Suppress("unused") | |
class MutableDecoratorLifecycle<T>( | |
private val decorated: T, | |
private val decorator: MutableDecorator<T> | |
) : LifecycleObserver { | |
@OnLifecycleEvent(Lifecycle.Event.ON_START) | |
fun onStart() { | |
decorator.mutate(decorated) | |
} | |
@OnLifecycleEvent(Lifecycle.Event.ON_STOP) | |
fun onStop() { | |
decorator.mutate(null) | |
} | |
} | |
@Suppress("unused") | |
fun <T> LifecycleOwner.addDecorator(decorated: T, decorator: MutableDecorator<T>) { | |
lifecycle.addObserver(MutableDecoratorLifecycle(decorated, decorator)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment