package chat.rocket.android.realm_helper;

import io.realm.Realm;
import io.realm.RealmChangeListener;
import io.realm.RealmObject;
import io.realm.RealmResults;
import java.util.List;

public class RealmListObserver<T extends RealmObject> extends AbstractRealmResultsObserver<T> {
  public interface Query<T extends RealmObject> {
    RealmResults<T> queryItems(Realm realm);
  }
  public interface OnUpdateListener<T extends RealmObject> {
    void onUpdateResults(List<T> results);
  }

  private final Query<T> query;
  private OnUpdateListener<T> onUpdateListener;

  /*package*/ RealmListObserver(RealmHelper helper, Query<T> query) {
    super(helper);
    this.query = query;
  }

  public RealmListObserver<T> setOnUpdateListener(OnUpdateListener<T> onUpdateListener) {
    this.onUpdateListener = onUpdateListener;
    return this;
  }

  @Override protected final RealmResults<T> queryItems(Realm realm) {
    return query.queryItems(realm);
  }

  @Override public final RealmChangeListener<RealmResults<T>> getListener() {
    return element -> {
      if (onUpdateListener != null) {
        onUpdateListener.onUpdateResults(element);
      }
    };
  }
}
@@ -947,24 +947,65 @@
 ealm);%0A  %7D%0A%0A
+  private String previousResultsString;%0A%0A
   @Override 
@@ -1085,20 +1085,271 @@
 urn 
-element -%3E %7B
+results -%3E %7B%0A      String currentResultString = results != null ? results.toString() : null;%0A      if (previousResultsString != null && previousResultsString.equals(currentResultString)) %7B%0A        return;%0A      %7D%0A      previousResultsString = currentResultString;
 %0A   
@@ -1428,15 +1428,15 @@
 lts(
-element
+results
 );%0A 

modify RealmListObserver notification.