androidx.databinding.ObservableList Java Examples

The following examples show how to use androidx.databinding.ObservableList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BindingItemAdapter.java    From recyclerview-adapters with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
    super.onAttachedToRecyclerView(recyclerView);
    callback = new ObservableList.OnListChangedCallback<ObservableList<I>>() {
        @Override
        public void onChanged(ObservableList<I> sender) {
            notifyDataSetChanged();
        }

        @Override
        public void onItemRangeChanged(ObservableList<I> sender, int positionStart, int itemCount) {
            notifyItemRangeChanged(positionStart, itemCount);
        }

        @Override
        public void onItemRangeInserted(ObservableList<I> sender, int positionStart, int itemCount) {
            notifyItemRangeInserted(positionStart, itemCount);
        }

        @Override
        public void onItemRangeMoved(ObservableList<I> sender, int fromPosition, int toPosition, int itemCount) {
            notifyItemMoved(fromPosition, toPosition);
        }

        @Override
        public void onItemRangeRemoved(ObservableList<I> sender, int positionStart, int itemCount) {
            notifyItemRangeRemoved(positionStart, itemCount);
        }
    };
    observableList.addOnListChangedCallback(callback);
}
 
Example #2
Source File: BindingFlexibleAdapter.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void updateDataSet(List<T> items, boolean animate) {
    if (items instanceof ObservableList) {
        ((ObservableList<T>) items).addOnListChangedCallback(callback);
    }
    super.updateDataSet(items, animate);
}
 
Example #3
Source File: BindingFlexibleAdapter.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onChanged(ObservableList sender) {
    BindingFlexibleAdapter<T> adapter = adapterRef.get();
    if (adapter == null) {
        return;
    }
    ensureChangeOnMainThread();
    adapter.notifyDataSetChanged();
}
 
Example #4
Source File: BindingFlexibleAdapter.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeChanged(ObservableList sender, final int positionStart, final int itemCount) {
    BindingFlexibleAdapter<T> adapter = adapterRef.get();
    if (adapter == null) {
        return;
    }
    ensureChangeOnMainThread();
    adapter.notifyItemRangeChanged(positionStart, itemCount);
}
 
Example #5
Source File: BindingFlexibleAdapter.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeInserted(ObservableList sender, final int positionStart, final int itemCount) {
    BindingFlexibleAdapter<T> adapter = adapterRef.get();
    if (adapter == null) {
        return;
    }
    ensureChangeOnMainThread();
    adapter.notifyItemRangeInserted(positionStart, itemCount);
}
 
Example #6
Source File: BindingFlexibleAdapter.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeMoved(ObservableList sender, final int fromPosition, final int toPosition, final int itemCount) {
    BindingFlexibleAdapter<T> adapter = adapterRef.get();
    if (adapter == null) {
        return;
    }
    ensureChangeOnMainThread();
    for (int i = 0; i < itemCount; i++) {
        adapter.notifyItemMoved(fromPosition + i, toPosition + i);
    }
}
 
Example #7
Source File: BindingFlexibleAdapter.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeRemoved(ObservableList sender, final int positionStart, final int itemCount) {
    BindingFlexibleAdapter<T> adapter = adapterRef.get();
    if (adapter == null) {
        return;
    }
    ensureChangeOnMainThread();
    adapter.notifyItemRangeRemoved(positionStart, itemCount);
}
 
Example #8
Source File: BindingAdapters.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@BindingAdapter("items")
public static void bindAdapterWithDefaultBinder(@NonNull RecyclerView recyclerView, @Nullable ObservableList<Download> items) {
    DownloadsAdapter adapter = (DownloadsAdapter)recyclerView.getAdapter();
    if (adapter != null) {
        adapter.setDownloadsList(items);
    }
}
 
Example #9
Source File: BindingRecyclerViewAdapter.java    From deagle with Apache License 2.0 5 votes vote down vote up
BindingRecyclerViewAdapter(final ObservableList<T> items, final ItemBinder<T> binder, final LayoutSelector<T> layout_selector) {
	mItems = items;
	mItemBinder = binder;
	mLayoutSelector = layout_selector;
	items.addOnListChangedCallback(new OnListChangedCallback<ObservableList<T>>(this));
	notifyDataSetChanged();
}
 
Example #10
Source File: RecyclerViewBindingAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@BindingAdapter({"items", "item_binder", "item_layout_selector"})
public static <T> void setItemsAndBinder(final RecyclerView recycler_view, final ObservableList<T> items, final ItemBinder<T> binder, final LayoutSelector<T> layout_selector) {
	recycler_view.setAdapter(new BindingRecyclerViewAdapter<>(items, binder, layout_selector));
}
 
Example #11
Source File: ObservableSortedList.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void removeOnListChangedCallback(final OnListChangedCallback<? extends ObservableList<T>> callback) {
	if (mListeners == null) return;
	mListeners.remove(callback);
}
 
Example #12
Source File: ObservableSortedList.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void addOnListChangedCallback(final OnListChangedCallback<? extends ObservableList<T>> callback) {
	if (mListeners == null) this.mListeners = new ListChangeRegistry();
	mListeners.add(callback);
}
 
Example #13
Source File: BindingRecyclerViewAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void onItemRangeRemoved(final ObservableList sender, final int positionStart, final int itemCount) {
	mAdapter.notifyItemRangeRemoved(positionStart, itemCount);
}
 
Example #14
Source File: BindingRecyclerViewAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void onItemRangeMoved(final ObservableList sender, final int fromPosition, final int toPosition, final int itemCount) {
	mAdapter.notifyItemMoved(fromPosition, toPosition);
}
 
Example #15
Source File: BindingRecyclerViewAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void onItemRangeInserted(final ObservableList sender, final int positionStart, final int itemCount) {
	mAdapter.notifyItemRangeInserted(positionStart, itemCount);
}
 
Example #16
Source File: BindingRecyclerViewAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void onItemRangeChanged(final ObservableList sender, final int positionStart, final int itemCount) {
	mAdapter.notifyItemRangeChanged(positionStart, itemCount);
}
 
Example #17
Source File: BindingRecyclerViewAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@Override public void onChanged(final ObservableList sender) {
	mAdapter.notifyDataSetChanged();
}
 
Example #18
Source File: RecyclerViewBindingAdapter.java    From deagle with Apache License 2.0 4 votes vote down vote up
@BindingAdapter({"items", "item_binder", "item_layout"})
public static <T> void setItemsAndBinder(final RecyclerView recycler_view, final ObservableList<T> items, final ItemBinder<T> binder, final @LayoutRes int item_layout) {
	recycler_view.setAdapter(new BindingRecyclerViewAdapter<>(items, binder, new LayoutSelector<T>() {
		@Override public int getLayoutRes(final T model) { return item_layout; }
	}));
}
 
Example #19
Source File: BindingItemAdapter.java    From recyclerview-adapters with Apache License 2.0 4 votes vote down vote up
public BindingItemAdapter(@NonNull Context context, @NonNull ObservableList<I> observableList) {
    super(context);
    this.observableList = observableList;
}
 
Example #20
Source File: MainViewModel.java    From android-mvvm-architecture with Apache License 2.0 4 votes vote down vote up
public ObservableList<QuestionCardData> getQuestionDataList() {
    return questionDataList;
}