Android Open Source - YOW2014-Android-MVVM View Model Pcl Base






From Project

Back to project page YOW2014-Android-MVVM.

License

The source code is released under:

MIT License

If you think the Android project YOW2014-Android-MVVM listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.adilmughal.demo.yow.mvvm.searchd.viewmodel;
//from ww  w. j a va  2  s  .  c o  m
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;

import android.os.Handler;
import android.os.Looper;

/**
 * View Model Base to support Java Beans Property Change Listeners
 * 
 * @author adil
 * 
 */
public class ViewModelPclBase {

  private PropertyChangeSupport propertyChangeSupport;
  
  public ViewModelPclBase() {
    propertyChangeSupport = new PropertyChangeSupport(this);
  }

  public void addPropertyChangeListener(String propertyName,
      PropertyChangeListener listener) {
    propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
  }

  public void removePropertyChangeListener(String propertyName,
      PropertyChangeListener listener) {
    propertyChangeSupport.removePropertyChangeListener(propertyName,
        listener);
  }

  protected void notifyPropertyChanged(final String propertyName) {
    notifyPropertyChanged(propertyName, null, null);
  }

  protected void notifyPropertyChanged(final String propertyName,
      final Object previousValue, final Object newValue) {
    if (Looper.myLooper() == Looper.getMainLooper()) {
      propertyChangeSupport.firePropertyChange(propertyName,
          previousValue, newValue);
    } else {
      // Dispatch/post to UI thread
      new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
          propertyChangeSupport.firePropertyChange(propertyName,
              previousValue, newValue);
        }
      });
    }
  }
}




Java Source Code List

com.adilmughal.demo.yow.mvvm.searchd.activity.SearchActivity.java
com.adilmughal.demo.yow.mvvm.searchd.activity.SearchPclActivity.java
com.adilmughal.demo.yow.mvvm.searchd.contract.SearchRepository.java
com.adilmughal.demo.yow.mvvm.searchd.repository.DummySearchRepository.java
com.adilmughal.demo.yow.mvvm.searchd.viewmodel.SearchPclViewModel.java
com.adilmughal.demo.yow.mvvm.searchd.viewmodel.SearchViewModel.java
com.adilmughal.demo.yow.mvvm.searchd.viewmodel.StringItemPresentationModel.java
com.adilmughal.demo.yow.mvvm.searchd.viewmodel.ViewModelBase.java
com.adilmughal.demo.yow.mvvm.searchd.viewmodel.ViewModelPclBase.java
com.adilmughal.demo.yow.searchd.traditional.activity.SearchActivity.java
com.adilmughal.demo.yow.searchd.traditional.contract.SearchRepository.java
com.adilmughal.demo.yow.searchd.traditional.repository.DummySearchRepository.java