Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.blitterhead.ampwifi.util;
- import android.app.Application;
- import android.arch.lifecycle.AndroidViewModel;
- import android.databinding.Observable;
- import android.databinding.PropertyChangeRegistry;
- import android.support.annotation.NonNull;
- /**
- * Created by Mike on 15-Jan-18.
- */
- public class BaseObservableAndroidViewModel extends AndroidViewModel implements Observable {
- protected BaseObservableAndroidViewModel(@NonNull Application application) {
- super(application);
- }
- private transient PropertyChangeRegistry mCallbacks;
- public synchronized void addOnPropertyChangedCallback(Observable.OnPropertyChangedCallback listener) {
- if (this.mCallbacks == null) {
- this.mCallbacks = new PropertyChangeRegistry();
- }
- this.mCallbacks.add(listener);
- }
- public synchronized void removeOnPropertyChangedCallback(Observable.OnPropertyChangedCallback listener) {
- if (this.mCallbacks != null) {
- this.mCallbacks.remove(listener);
- }
- }
- public synchronized void notifyChange() {
- if (this.mCallbacks != null) {
- this.mCallbacks.notifyCallbacks(this, 0, null);
- }
- }
- protected void notifyPropertyChanged(int fieldId) {
- if (this.mCallbacks != null) {
- this.mCallbacks.notifyCallbacks(this, fieldId, null);
- }
- }
- }
Add Comment
Please, Sign In to add comment