diff --git a/app/src/main/java/com/example/sprout/refactor/viewmodel/BaseViewModel.java b/app/src/main/java/com/example/sprout/refactor/viewmodel/BaseViewModel.java index c2b107c..1300820 100644 --- a/app/src/main/java/com/example/sprout/refactor/viewmodel/BaseViewModel.java +++ b/app/src/main/java/com/example/sprout/refactor/viewmodel/BaseViewModel.java @@ -4,6 +4,11 @@ import android.arch.lifecycle.LifecycleObserver; import android.arch.lifecycle.OnLifecycleEvent; +import com.example.sprout.refactor.messengers.NavigationMessage; +import com.example.sprout.refactor.messengers.ToastMessage; +import com.example.sprout.refactor.notification.Observable; +import com.example.sprout.refactor.notification.Observer; + /** * Base ViewModel * @@ -11,6 +16,19 @@ */ public abstract class BaseViewModel implements LifecycleObserver { + protected Observable navigationObservable = new Observable<>(); + protected Observable toastObservable = new Observable<>(); + + public void addObserver(Observer navigationObserver, Observer toastObserver) { + navigationObservable.addObserver(navigationObserver); + toastObservable.addObserver(toastObserver); + } + + public void removeObserver(Observer navigationObserver, Observer toastObserver) { + navigationObservable.removeObserver(navigationObserver); + toastObservable.removeObserver(toastObserver); + } + @OnLifecycleEvent(Lifecycle.Event.ON_CREATE) public void onCreate() { }