android.databinding.ObservableList Java Examples

The following examples show how to use android.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: BindingRecyclerViewAdapter.java    From android-data-binding-recyclerview with Apache License 2.0 8 votes vote down vote up
@Override
public void onItemRangeMoved(ObservableList sender, int fromPosition, int toPosition, int itemCount)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyItemMoved(fromPosition, toPosition);
    }
}
 
Example #2
Source File: ListBindingAdapters.java    From views-widgets-samples with Apache License 2.0 7 votes vote down vote up
@Override
public void onItemRangeInserted(ObservableList observableList,
        int start, int count) {
    if (mLayoutId == 0) {
        return;
    }
    startTransition(mTarget);
    final int end = start + count;
    LayoutInflater inflater = (LayoutInflater) mTarget.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (int i = end - 1; i >= start; i--) {
        Object entry = observableList.get(i);
        ViewDataBinding binding =
                bindLayout(inflater, mTarget, mLayoutId, entry);
        mTarget.addView(binding.getRoot(), start);
    }
}
 
Example #3
Source File: LayerListAdapter.java    From spline with Apache License 2.0 7 votes vote down vote up
public ObservableList<Layer> getTwirledDownLayersForGroup(LayerGroup root) {
    ObservableList<Layer> twirledDownLayers = new ObservableArrayList<>();

    for (Layer l : root.getLayers()) {
        twirledDownLayers.add(l);
        if (l instanceof LayerGroup) {
            LayerGroup group = (LayerGroup) l;
            if (group.isTwirledDown()) {
                int i = twirledDownLayers.indexOf(l);
                List<Layer> childLayers = getTwirledDownLayersForGroup(group);
                twirledDownLayers.addAll(i + 1, childLayers);
            }
        }
    }

    return twirledDownLayers;
}
 
Example #4
Source File: ListBindingAdapters.java    From android-ui-toolkit-demos with Apache License 2.0 7 votes vote down vote up
@Override
public void onItemRangeInserted(ObservableList observableList,
        int start, int count) {
    if (mLayoutId == 0) {
        return;
    }
    startTransition(mTarget);
    final int end = start + count;
    LayoutInflater inflater = (LayoutInflater) mTarget.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    for (int i = end - 1; i >= start; i--) {
        Object entry = observableList.get(i);
        ViewDataBinding binding =
                bindLayout(inflater, mTarget, mLayoutId, entry);
        mTarget.addView(binding.getRoot(), start);
    }
}
 
Example #5
Source File: RecyclerViewDatabindingAdapter.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 7 votes vote down vote up
@Override
public void onItemRangeChanged(final ObservableList<ItemTypeT> items,
        final int start, final int count) {
    mainHandler.post(() -> {
        for (int i = start; i < start + count; ++i) {
            adapterItems.set(i, items.get(i));
        }

        notifyItemRangeChanged(getItemLayoutPosition(start), count);
    });
}
 
Example #6
Source File: ListBindingAdapters.java    From android-ui-toolkit-demos with Apache License 2.0 7 votes vote down vote up
@Override
public void onItemRangeChanged(ObservableList observableList,
        int start, int count) {
    if (mLayoutId == 0) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) mTarget.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    startTransition(mTarget);
    final int end = start + count;
    for (int i = start; i < end; i++) {
        Object data = observableList.get(i);
        ViewDataBinding binding = bindLayout(inflater,
                mTarget, mLayoutId, data);
        binding.setVariable(BR.data, observableList.get(i));
        mTarget.removeViewAt(i);
        mTarget.addView(binding.getRoot(), i);
    }
}
 
Example #7
Source File: ListBindingAdapters.java    From views-widgets-samples with Apache License 2.0 6 votes vote down vote up
@Override
public void onItemRangeChanged(ObservableList observableList,
        int start, int count) {
    if (mLayoutId == 0) {
        return;
    }
    LayoutInflater inflater = (LayoutInflater) mTarget.getContext()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    startTransition(mTarget);
    final int end = start + count;
    for (int i = start; i < end; i++) {
        Object data = observableList.get(i);
        ViewDataBinding binding = bindLayout(inflater,
                mTarget, mLayoutId, data);
        binding.setVariable(BR.data, observableList.get(i));
        mTarget.removeViewAt(i);
        mTarget.addView(binding.getRoot(), i);
    }
}
 
Example #8
Source File: BindingRecyclerViewAdapter.java    From SimpleFTP with MIT License 5 votes vote down vote up
/**
 * Sets the list of items to display.
 * @param items The list of items.
 */
public void setItems(@Nullable Collection<T> items)
{
    if (this.items == items)
    {
        return;
    }

    if (this.items != null)
    {
        this.items.removeOnListChangedCallback(onListChangedCallback);
        notifyItemRangeRemoved(0, this.items.size());
    }

    if (items instanceof ObservableList)
    {
        this.items = (ObservableList<T>) items;
        notifyItemRangeInserted(0, this.items.size());
        this.items.addOnListChangedCallback(onListChangedCallback);
    }
    else if (items != null)
    {
        this.items = new ObservableArrayList<>();
        this.items.addOnListChangedCallback(onListChangedCallback);
        this.items.addAll(items);
    }
    else
    {
        this.items = null;
    }
}
 
Example #9
Source File: BindingRecyclerViewAdapter.java    From android-data-binding-recyclerview with Apache License 2.0 5 votes vote down vote up
@Override
public void onChanged(ObservableList sender)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyDataSetChanged();
    }
}
 
Example #10
Source File: BindingRecyclerViewAdapter.java    From SimpleFTP with MIT License 5 votes vote down vote up
/**
 * Called when the list changed
 * @param sender The current list.
 */
@Override
public void onChanged(ObservableList sender)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyDataSetChanged();
    }
}
 
Example #11
Source File: BindingRecyclerViewAdapter.java    From SimpleFTP with MIT License 5 votes vote down vote up
/**
 * Called when an item range is inserted in the list.
 * @param sender The current list.
 * @param positionStart The position of the first item inserted.
 * @param itemCount The number of items inserted.
 */
@Override
public void onItemRangeInserted(ObservableList sender, int positionStart, int itemCount)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyItemRangeInserted(positionStart, itemCount);
    }
}
 
Example #12
Source File: ListBindingAdapters.java    From views-widgets-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeMoved(ObservableList observableList,
        int from, int to, int count) {
    if (mLayoutId == 0) {
        return;
    }
    startTransition(mTarget);
    for (int i = 0; i < count; i++) {
        View view = mTarget.getChildAt(from);
        mTarget.removeViewAt(from);
        int destination = (from > to) ? to + i : to;
        mTarget.addView(view, destination);
    }
}
 
Example #13
Source File: ListBindingAdapters.java    From views-widgets-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeRemoved(ObservableList observableList,
        int start, int count) {
    if (mLayoutId == 0) {
        return;
    }
    startTransition(mTarget);
    for (int i = 0; i < count; i++) {
        mTarget.removeViewAt(start);
    }
}
 
Example #14
Source File: ListBindingAdapters.java    From android-ui-toolkit-demos with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeRemoved(ObservableList observableList,
        int start, int count) {
    if (mLayoutId == 0) {
        return;
    }
    startTransition(mTarget);
    for (int i = 0; i < count; i++) {
        mTarget.removeViewAt(start);
    }
}
 
Example #15
Source File: BindingRecyclerViewAdapter.java    From SimpleFTP with MIT License 5 votes vote down vote up
/**
 * Called when an item range is removed from the list.
 * @param sender The current list.
 * @param positionStart The position of the first item removed.
 * @param itemCount The number of items removed.
 */
@Override
public void onItemRangeRemoved(ObservableList sender, int positionStart, int itemCount)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyItemRangeRemoved(positionStart, itemCount);
    }
}
 
Example #16
Source File: ListBindingAdapters.java    From android-ui-toolkit-demos with Apache License 2.0 5 votes vote down vote up
/**
 * Assign a list of items to a ViewGroup. This is used with the {@code entries} and
 * {@code layout} attributes in the application namespace. Example Usage:
 * <pre><code>&lt;LinearLayout
 *     android:layout_width="match_parent"
 *     android:layout_height="wrap_content"
 *     android:orientation="vertical"
 *     app:entries="@{items}"
 *     app:layout="@{@layout/item}"/&gt;
 * </code></pre>
 * <p>
 * In the above, {@code items} is a List or ObservableList. {@code layout} does not
 * need to be hard-coded, but most commonly will be. This BindingAdapter will work
 * with any ViewGroup that only needs addView() and removeView() to manage its Views.
 * <p>
 * The layout, &commat;layout/item for example, must have a single variable named
 * {@code data}.
 */
@BindingAdapter({"entries", "layout"})
public static <T> void setEntries(ViewGroup viewGroup,
        List<T> oldEntries, int oldLayoutId,
        List<T> newEntries, int newLayoutId) {
    if (oldEntries == newEntries && oldLayoutId == newLayoutId) {
        return; // nothing has changed
    }

    EntryChangeListener listener =
            ListenerUtil.getListener(viewGroup, R.id.entryListener);
    if (oldEntries != newEntries && listener != null && oldEntries instanceof ObservableList) {
        ((ObservableList)oldEntries).removeOnListChangedCallback(listener);
    }

    if (newEntries == null) {
        viewGroup.removeAllViews();
    } else {
        if (newEntries instanceof ObservableList) {
            if (listener == null) {
                listener =
                        new EntryChangeListener(viewGroup, newLayoutId);
                ListenerUtil.trackListener(viewGroup, listener,
                        R.id.entryListener);
            } else {
                listener.setLayoutId(newLayoutId);
            }
            if (newEntries != oldEntries) {
                ((ObservableList)newEntries).addOnListChangedCallback(listener);
            }
        }
        resetViews(viewGroup, newLayoutId, newEntries);
    }
}
 
Example #17
Source File: RecyclerViewDatabindingAdapter.java    From Android-App-Architecture-MVVM-Databinding with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeInserted(final ObservableList<ItemTypeT> items,
        final int start, final int count) {
    mainHandler.post(() -> {
        for (int i = start + count - 1; i >= start; --i) {
            adapterItems.add(start, items.get(i));
        }

        notifyItemRangeInserted(getItemLayoutPosition(start), count);
    });
}
 
Example #18
Source File: BindingRecyclerView.java    From Studio with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeMoved(ObservableList<T> sender,
                             int fromPosition, int toPosition, int itemCount) {
    for (int i = 0; i < itemCount; i++) {
        notifyItemMoved(fromPosition + i, toPosition + i);
    }
}
 
Example #19
Source File: ListBindingAdapters.java    From views-widgets-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Assign a list of items to a ViewGroup. This is used with the {@code entries} and
 * {@code layout} attributes in the application namespace. Example Usage:
 * <pre><code>&lt;LinearLayout
 *     android:layout_width="match_parent"
 *     android:layout_height="wrap_content"
 *     android:orientation="vertical"
 *     app:entries="@{items}"
 *     app:layout="@{@layout/item}"/&gt;
 * </code></pre>
 * <p>
 * In the above, {@code items} is a List or ObservableList. {@code layout} does not
 * need to be hard-coded, but most commonly will be. This BindingAdapter will work
 * with any ViewGroup that only needs addView() and removeView() to manage its Views.
 * <p>
 * The layout, &commat;layout/item for example, must have a single variable named
 * {@code data}.
 */
@BindingAdapter({"entries", "layout"})
public static <T> void setEntries(ViewGroup viewGroup,
        List<T> oldEntries, int oldLayoutId,
        List<T> newEntries, int newLayoutId) {
    if (oldEntries == newEntries && oldLayoutId == newLayoutId) {
        return; // nothing has changed
    }

    EntryChangeListener listener =
            ListenerUtil.getListener(viewGroup, R.id.entryListener);
    if (oldEntries != newEntries && listener != null && oldEntries instanceof ObservableList) {
        ((ObservableList)oldEntries).removeOnListChangedCallback(listener);
    }

    if (newEntries == null) {
        viewGroup.removeAllViews();
    } else {
        if (newEntries instanceof ObservableList) {
            if (listener == null) {
                listener =
                        new EntryChangeListener(viewGroup, newLayoutId);
                ListenerUtil.trackListener(viewGroup, listener,
                        R.id.entryListener);
            } else {
                listener.setLayoutId(newLayoutId);
            }
            if (newEntries != oldEntries) {
                ((ObservableList)newEntries).addOnListChangedCallback(listener);
            }
        }
        resetViews(viewGroup, newLayoutId, newEntries);
    }
}
 
Example #20
Source File: DocumentView.java    From spline with Apache License 2.0 5 votes vote down vote up
private void addPropertyChangedCallbacks(List<Layer> layers, int start, int end) {
    for (int i = start; i < end; i++) {
        Layer l = layers.get(i);
        l.addOnPropertyChangedCallback(mOnPropertyChangedCallback);
        if (l instanceof LayerGroup) {
            LayerGroup lg = (LayerGroup) l;
            ObservableList<Layer> childLayers = lg.getLayers();
            // Add list listener for future changes to the layer group's list of children
            childLayers.addOnListChangedCallback(mOnListChangedCallback);

            // Recursive call to add property listeners to each child layer
            addPropertyChangedCallbacks(childLayers);
        }
    }
}
 
Example #21
Source File: BindingRecyclerViewAdapter.java    From android-data-binding-recyclerview with Apache License 2.0 5 votes vote down vote up
@Override
public void onItemRangeChanged(ObservableList sender, int positionStart, int itemCount)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyItemRangeChanged(positionStart, itemCount);
    }
}
 
Example #22
Source File: ListFragment.java    From spline with Apache License 2.0 5 votes vote down vote up
private void updateList() {
    PickerViewModel viewModel = PickerViewModel.getInstance();
    ObservableList<File> files = viewModel.getFiles();

    if (mAdapter == null) {
        mAdapter = new FileAdapter();
        mList.setAdapter(mAdapter);
    }

    mAdapter.setFiles(files);
    mBinding.setViewModel(viewModel);
}
 
Example #23
Source File: ListFragment.java    From spline with Apache License 2.0 5 votes vote down vote up
public FileAdapter() {
    mOnListChangedCallback = new ObservableList
            .OnListChangedCallback<ObservableList<Layer>>() {
        @Override
        public void onChanged(ObservableList<Layer> layers) {

        }

        @Override
        public void onItemRangeChanged(ObservableList<Layer> layers, int i, int i1) {

        }

        @Override
        public void onItemRangeInserted(ObservableList<Layer> layers, int start, int
                count) {
            notifyItemRangeInserted(start, count);
        }

        @Override
        public void onItemRangeMoved(ObservableList<Layer> sender, int fromPosition, int
                toPosition, int itemCount) {

        }

        @Override
        public void onItemRangeRemoved(ObservableList<Layer> sender, int positionStart,
                                       int itemCount) {

        }
    };
}
 
Example #24
Source File: BindingRecyclerViewAdapter.java    From android-data-binding-recyclerview with Apache License 2.0 5 votes vote down vote up
public void setItems(@Nullable Collection<T> items)
{
    if (this.items == items)
    {
        return;
    }

    if (this.items != null)
    {
        this.items.removeOnListChangedCallback(onListChangedCallback);
        notifyItemRangeRemoved(0, this.items.size());
    }

    if (items instanceof ObservableList)
    {
        this.items = (ObservableList<T>) items;
        notifyItemRangeInserted(0, this.items.size());
        this.items.addOnListChangedCallback(onListChangedCallback);
    }
    else if (items != null)
    {
        this.items = new ObservableArrayList<>();
        this.items.addOnListChangedCallback(onListChangedCallback);
        this.items.addAll(items);
    }
    else
    {
        this.items = null;
    }
}
 
Example #25
Source File: LayerListAdapter.java    From spline with Apache License 2.0 5 votes vote down vote up
private void addListChangedCallbacks(List<Layer> layers, int start, int end) {
    for (int i = start; i < end; i++) {
        Layer l = layers.get(i);
        if (l instanceof LayerGroup) {
            LayerGroup lg = (LayerGroup) l;
            ObservableList<Layer> childLayers = lg.getLayers();
            // Add list listener for future changes to the layer group's list of children
            childLayers.addOnListChangedCallback(mOnListChangedCallback);
            // Recursive call to add property listeners to each child layer
            addListChangedCallbacks(childLayers);
        }
    }
}
 
Example #26
Source File: BindingRecyclerViewAdapter.java    From SimpleFTP with MIT License 5 votes vote down vote up
/**
 * Called when an item range changed in the list.
 * @param sender The current list.
 * @param positionStart The position of the first item modified.
 * @param itemCount The number of items modified.
 */
@Override
public void onItemRangeChanged(ObservableList sender, int positionStart, int itemCount)
{
    RecyclerView.Adapter adapter = adapterReference.get();
    if (adapter != null)
    {
        adapter.notifyItemRangeChanged(positionStart, itemCount);
    }
}
 
Example #27
Source File: RecyclerViewAdapterChangedCallback.java    From demo4Fish with MIT License 4 votes vote down vote up
@Override
public void onItemRangeRemoved(ObservableList sender, int positionStart, int itemCount) {
    mAdapter.notifyItemRangeRemoved(positionStart, itemCount);
}
 
Example #28
Source File: ListFragment.java    From spline with Apache License 2.0 4 votes vote down vote up
public void setFiles(ObservableList<File> files) {
    mFiles = files;
    mFiles.addOnListChangedCallback(mOnListChangedCallback);
    notifyDataSetChanged();
}
 
Example #29
Source File: ObservableBindingUtil.java    From demo4Fish with MIT License 4 votes vote down vote up
public static IBinding bind(ObservableList observableList, ObservableList.OnListChangedCallback callback) {
    IBinding binding = new ListBinding(observableList, callback);
    binding.bind();

    return binding;
}
 
Example #30
Source File: MeiziAdapter.java    From NewsMe with Apache License 2.0 4 votes vote down vote up
public MeiziAdapter(Context context, ObservableList<Image> data, RequestManager manager) {
    super(context, data);
    this.mRequestManager = manager;
    setHasStableIds(true);
}