Skip to content

Commit

Permalink
Resolved #217 - Optimizing data binding of adapter's data set
Browse files Browse the repository at this point in the history
  • Loading branch information
davideas committed Apr 25, 2017
1 parent 43800cc commit d7d6eec
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import android.databinding.BindingAdapter;
import android.support.v7.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import eu.davidea.flexibleadapter.FlexibleAdapter;
Expand All @@ -16,7 +15,7 @@ public class BindingAdapters {
public static <T extends IFlexible> void setAdapter(RecyclerView recyclerView, List<T> items) {
RecyclerView.Adapter adapter = recyclerView.getAdapter();
if (adapter != null && adapter instanceof FlexibleAdapter) {
((FlexibleAdapter<T>) adapter).updateDataSet(new ArrayList<>(items));
((FlexibleAdapter<T>) adapter).updateDataSet(items);
} else {
throw new IllegalStateException("Binding works only with FlexibleAdapter");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ public BindingFlexibleAdapter(@Nullable Object listeners, boolean stableIds) {

@Override
public void updateDataSet(List<T> items, boolean animate) {
//if (mItems instanceof ObservableList) {
//TODO: mItems are wrapped into ArrayList in FlexibleAdapter and thus we don't remove the callback on changes.
//((ObservableList<T>) this.mItems).removeOnListChangedCallback(callback);
//}
if (items instanceof ObservableList) {
((ObservableList<T>) items).addOnListChangedCallback(callback);
}
Expand Down Expand Up @@ -99,7 +95,7 @@ public void onItemRangeRemoved(ObservableList sender, final int positionStart, f

private static void ensureChangeOnMainThread() {
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
throw new IllegalStateException("You must only modify the ObservableList on the main thread.");
throw new IllegalStateException("You can only modify the ObservableList on the main thread.");
}
}
}
Expand Down

0 comments on commit d7d6eec

Please sign in to comment.