Guest User

Untitled

a guest
Apr 20th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.22 KB | None | 0 0
  1. package com.blitterhead.ampwifi.util;
  2.  
  3. import android.app.Application;
  4. import android.arch.lifecycle.AndroidViewModel;
  5. import android.databinding.Observable;
  6. import android.databinding.PropertyChangeRegistry;
  7. import android.support.annotation.NonNull;
  8.  
  9. /**
  10. * Created by Mike on 15-Jan-18.
  11. */
  12.  
  13. public class BaseObservableAndroidViewModel extends AndroidViewModel implements Observable {
  14. protected BaseObservableAndroidViewModel(@NonNull Application application) {
  15. super(application);
  16. }
  17.  
  18. private transient PropertyChangeRegistry mCallbacks;
  19.  
  20. public synchronized void addOnPropertyChangedCallback(Observable.OnPropertyChangedCallback listener) {
  21. if (this.mCallbacks == null) {
  22. this.mCallbacks = new PropertyChangeRegistry();
  23. }
  24.  
  25. this.mCallbacks.add(listener);
  26. }
  27.  
  28. public synchronized void removeOnPropertyChangedCallback(Observable.OnPropertyChangedCallback listener) {
  29. if (this.mCallbacks != null) {
  30. this.mCallbacks.remove(listener);
  31. }
  32. }
  33.  
  34. public synchronized void notifyChange() {
  35. if (this.mCallbacks != null) {
  36. this.mCallbacks.notifyCallbacks(this, 0, null);
  37. }
  38. }
  39.  
  40. protected void notifyPropertyChanged(int fieldId) {
  41. if (this.mCallbacks != null) {
  42. this.mCallbacks.notifyCallbacks(this, fieldId, null);
  43. }
  44. }
  45. }
Add Comment
Please, Sign In to add comment