david.bilik
02/16/2018, 8:04 AMinterface AutoRefreshViewModel : LifecycleObserver {
@OnLifecycleEvent(value = Lifecycle.Event.ON_START)
fun startAutoRefresh()
@OnLifecycleEvent(value = Lifecycle.Event.ON_STOP)
fun stopAutoRefresh()
}
and then I have implementation of this interface
class AutoRefreshImplementation(val period: Long, val action: () -> Unit) : AutoRefreshViewModel {
private var refreshDisposable: Disposable? = null
override fun startAutoRefresh() {
refreshDisposable?.safeDispose()
refreshDisposable = Observable.interval(period, period, TimeUnit.MILLISECONDS)
.subscribe {
action()
}
}
override fun stopAutoRefresh() {
refreshDisposable?.safeDispose()
}
}
usage of it in class is simple,
class ControlViewModel @Inject constructor() : ViewModel(), AutoRefreshViewModel by AutoRefreshImplementation(period, {
// action
}) {...}
everything works fine until I change something in this file ControlViewModel
, then annotation processor throws an error ControlViewModel.java:52: error: annotation @OnLifecycleEvent is missing a default value for the element 'value'
@android.arch.lifecycle.OnLifecycleEvent()
and in the generated stub I can see both methods as
@java.lang.Override()
@android.arch.lifecycle.OnLifecycleEvent()
public void startAutoRefresh() {
}
@java.lang.Override()
@android.arch.lifecycle.OnLifecycleEvent()
public void stopAutoRefresh() {
}
… if I rebuild my project, stub looks ok
@java.lang.Override()
@android.arch.lifecycle.OnLifecycleEvent(value = android.arch.lifecycle.Lifecycle.Event.ON_START)
public void startAutoRefresh() {
}
@java.lang.Override()
@android.arch.lifecycle.OnLifecycleEvent(value = android.arch.lifecycle.Lifecycle.Event.ON_STOP)
public void stopAutoRefresh() {
}
workaround is to not use delegated implementation but use it myself, but its a real bummer