Search in sources :

Example 1 with ISectionable

use of eu.davidea.flexibleadapter.items.ISectionable in project FlexibleAdapter by davideas.

the class FlexibleAdapter method addSection.

/**
	 * @since 5.0.0-b6
	 * @deprecated For a correct positioning of a new Section, use {@link #addSection(IHeader, Comparator)}
	 * instead. This method doesn't perform any sort, so if the refHeader is unknown, the Header
	 * is always inserted at the top, which doesn't cover all use cases.
	 * <p>This method will be deleted before the final release.</p>
	 */
@Deprecated
public void addSection(@NonNull IHeader header, @Nullable IHeader refHeader) {
    int position = 0;
    if (refHeader != null) {
        position = getGlobalPositionOf(refHeader) + 1;
        List<ISectionable> refSectionItems = getSectionItems(refHeader);
        if (!refSectionItems.isEmpty()) {
            position += refSectionItems.size();
        }
    }
    addItem(position, (T) header);
}
Also used : ISectionable(eu.davidea.flexibleadapter.items.ISectionable) SuppressLint(android.annotation.SuppressLint)

Example 2 with ISectionable

use of eu.davidea.flexibleadapter.items.ISectionable in project Neuronizer by djuelg.

the class DisplayTodoListPresenterImpl method syncSubItems.

private void syncSubItems(List<ISectionable> subItems) {
    List<ISectionable> reversedItems = Lists.reverse(Optional.fromNullable(subItems).or(new ArrayList<ISectionable>(0)));
    for (ISectionable vm : reversedItems) {
        TodoListItem item = ((TodoListItemViewModel) vm).getItem();
        EditItemInteractor interactor = new EditItemInteractorImpl(mExecutor, mMainThread, this, repository, item.getUuid(), item.getTitle(), reversedItems.indexOf(vm), item.isImportant(), item.getDetails(), item.isDone(), ((TodoListItemViewModel) vm).getHeader().getHeader().getUuid());
        interactor.execute();
    }
}
Also used : EditItemInteractor(de.djuelg.neuronizer.domain.interactors.todolist.EditItemInteractor) TodoListItemViewModel(de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel) ArrayList(java.util.ArrayList) EditItemInteractorImpl(de.djuelg.neuronizer.domain.interactors.todolist.impl.EditItemInteractorImpl) ISectionable(eu.davidea.flexibleadapter.items.ISectionable) TodoListItem(de.djuelg.neuronizer.domain.model.todolist.TodoListItem)

Example 3 with ISectionable

use of eu.davidea.flexibleadapter.items.ISectionable in project FlexibleAdapter by davideas.

the class DatabaseService method updateNewItems.

/**
 * This demonstrates that new content of existing items are really rebound and
 * notified with CHANGE Payload in the Adapter list when refreshed.
 */
public void updateNewItems() {
    IHeader header = null;
    for (IFlexible iFlexible : mItems) {
        if (iFlexible instanceof AbstractItem) {
            AbstractItem item = (AbstractItem) iFlexible;
            item.increaseUpdates();
        }
        if (iFlexible instanceof ISectionable) {
            IHeader newHeader = ((ISectionable) iFlexible).getHeader();
            if (newHeader instanceof HeaderItem && !newHeader.equals(header)) {
                header = newHeader;
                HeaderItem headerItem = (HeaderItem) header;
                headerItem.increaseUpdates();
            }
        }
    }
}
Also used : IHeader(eu.davidea.flexibleadapter.items.IHeader) IFlexible(eu.davidea.flexibleadapter.items.IFlexible) AbstractItem(eu.davidea.samples.flexibleadapter.items.AbstractItem) InstagramHeaderItem(eu.davidea.samples.flexibleadapter.items.InstagramHeaderItem) StaggeredHeaderItem(eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem) ExpandableHeaderItem(eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem) HeaderItem(eu.davidea.samples.flexibleadapter.items.HeaderItem) ISectionable(eu.davidea.flexibleadapter.items.ISectionable)

Example 4 with ISectionable

use of eu.davidea.flexibleadapter.items.ISectionable in project FlexibleAdapter by davideas.

the class FlexibleAdapter method removeRange.

/**
 * Removes a list of consecutive items and notify the change.
 * <p>If the item, resulting from the provided position:</p>
 * - is <u>not expandable</u> with <u>no</u> parent, it is removed as usual.<br>
 * - is <u>not expandable</u> with a parent, it is removed only if the parent is expanded.<br>
 * - is <u>expandable</u> implementing {@link IExpandable}, it is removed as usual, but
 * it will be collapsed if expanded.<br>
 * - has a {@link IHeader} item, the header will be automatically linked to the first item
 * after the range or can remain orphan.
 * <p>Optionally you can pass any payload to notify the <u>parent</u> or the <u>header</u>
 * about the change and optimize the view binding.</p>
 *
 * @param positionStart the start position of the first item
 * @param itemCount     how many items should be removed
 * @param payload       any non-null user object to notify the parent (the payload will be
 *                      therefore passed to the bind method of the parent ViewHolder),
 *                      pass null to <u>not</u> notify the parent
 * @see #clear()
 * @see #clearAllBut(Integer...)
 * @see #removeItem(int, Object)
 * @see #removeItems(List, Object)
 * @see #removeRange(int, int)
 * @see #removeAllSelectedItems(Object)
 * @see #setPermanentDelete(boolean)
 * @see #setRestoreSelectionOnUndo(boolean)
 * @see #getDeletedItems()
 * @see #getDeletedChildren(IExpandable)
 * @see #restoreDeletedItems()
 * @see #emptyBin()
 * @since 5.0.0-b1
 */
public void removeRange(@IntRange(from = 0) int positionStart, @IntRange(from = 0) int itemCount, @Nullable Object payload) {
    int initialCount = getItemCount();
    log.d("removeRange positionStart=%s itemCount=%s", positionStart, itemCount);
    if (positionStart < 0 || (positionStart + itemCount) > initialCount) {
        log.e("Cannot removeRange with positionStart OutOfBounds!");
        return;
    } else if (itemCount == 0 || initialCount == 0) {
        log.w("removeRange Nothing to delete!");
        return;
    }
    T item = null;
    IExpandable parent = null;
    for (int position = positionStart; position < positionStart + itemCount; position++) {
        // We remove always at positionStart!
        item = getItem(positionStart);
        if (item == null) {
            continue;
        }
        if (!permanentDelete) {
            // When removing a range of children, parent is always the same :-)
            if (parent == null) {
                parent = getExpandableOf(item);
            }
            // Differentiate: (Expandable & NonExpandable with No parent) from (NonExpandable with a parent)
            if (parent == null) {
                createRestoreItemInfo(positionStart, item);
            } else {
                createRestoreSubItemInfo(parent, item);
            }
        }
        // Mark hidden the deleted item
        item.setHidden(true);
        // Unlink items that belongs to the removed header
        if (unlinkOnRemoveHeader && isHeader(item)) {
            IHeader header = (IHeader) item;
            // If item is a Header, remove linkage from ALL Sectionable items if exist
            List<ISectionable> sectionableList = getSectionItems(header);
            for (ISectionable sectionable : sectionableList) {
                sectionable.setHeader(null);
                if (payload != null) {
                    notifyItemChanged(getGlobalPositionOf(sectionable), Payload.UNLINK);
                }
            }
        }
        // Remove item from internal list
        mItems.remove(positionStart);
        if (permanentDelete && mOriginalList != null) {
            mOriginalList.remove(item);
        }
        removeSelection(position);
    }
    // Notify range removal
    notifyItemRangeRemoved(positionStart, itemCount);
    // Update content of the header linked to first item of the range
    int headerPosition = getGlobalPositionOf(getHeaderOf(item));
    if (headerPosition >= 0) {
        notifyItemChanged(headerPosition, payload);
    }
    // Notify the Parent about the change if requested if different from header
    int parentPosition = getGlobalPositionOf(parent);
    if (parentPosition >= 0 && parentPosition != headerPosition) {
        notifyItemChanged(parentPosition, payload);
    }
    // Update empty view
    if (mUpdateListener != null && !multiRange && initialCount > 0 && getItemCount() == 0) {
        mUpdateListener.onUpdateEmptyView(getMainItemCount());
    }
}
Also used : IHeader(eu.davidea.flexibleadapter.items.IHeader) IExpandable(eu.davidea.flexibleadapter.items.IExpandable) ISectionable(eu.davidea.flexibleadapter.items.ISectionable) SuppressLint(android.annotation.SuppressLint)

Example 5 with ISectionable

use of eu.davidea.flexibleadapter.items.ISectionable in project FlexibleAdapter by davideas.

the class FlexibleAdapter method restoreDeletedItems.

/**
 * Restore items just removed.
 * <p><b>Tip:</b> If filter is active, only items that match that filter will be shown(restored).</p>
 *
 * @see #setRestoreSelectionOnUndo(boolean)
 * @since 3.0.0
 */
@SuppressWarnings("ResourceType")
public void restoreDeletedItems() {
    multiRange = true;
    int initialCount = getItemCount();
    // Selection coherence: start from a clean situation
    if (getSelectedItemCount() > 0) {
        clearSelection();
    }
    // Start from latest item deleted, since others could rely on it
    for (int i = mRestoreList.size() - 1; i >= 0; i--) {
        adjustSelected = false;
        RestoreInfo restoreInfo = mRestoreList.get(i);
        if (restoreInfo.relativePosition >= 0) {
            // Restore child
            log.d("Restore SubItem %s", restoreInfo);
            addSubItem(restoreInfo.getRestorePosition(true), restoreInfo.relativePosition, restoreInfo.item, false, Payload.UNDO);
        } else {
            // Restore parent or simple item
            log.d("Restore Item %s", restoreInfo);
            addItem(restoreInfo.getRestorePosition(false), restoreInfo.item);
        }
        // Item is again visible
        restoreInfo.item.setHidden(false);
        // Restore header linkage
        if (unlinkOnRemoveHeader && isHeader(restoreInfo.item)) {
            IHeader header = (IHeader) restoreInfo.item;
            List<ISectionable> items = getSectionItems(header);
            for (ISectionable sectionable : items) {
                linkHeaderTo((T) sectionable, header, Payload.LINK);
            }
        }
    }
    // Restore selection if requested, before emptyBin
    if (restoreSelection && !mRestoreList.isEmpty()) {
        if (isExpandable(mRestoreList.get(0).item) || getExpandableOf(mRestoreList.get(0).item) == null) {
            parentSelected = true;
        } else {
            childSelected = true;
        }
        for (RestoreInfo restoreInfo : mRestoreList) {
            if (restoreInfo.item.isSelectable()) {
                addSelection(getGlobalPositionOf(restoreInfo.item));
            }
        }
        log.d("Selected positions after restore %s", getSelectedPositions());
    }
    // Call listener to update EmptyView
    multiRange = false;
    if (mUpdateListener != null && initialCount == 0 && getItemCount() > 0) {
        mUpdateListener.onUpdateEmptyView(getMainItemCount());
    }
    emptyBin();
}
Also used : IHeader(eu.davidea.flexibleadapter.items.IHeader) ISectionable(eu.davidea.flexibleadapter.items.ISectionable) SuppressLint(android.annotation.SuppressLint)

Aggregations

ISectionable (eu.davidea.flexibleadapter.items.ISectionable)15 SuppressLint (android.annotation.SuppressLint)9 IHeader (eu.davidea.flexibleadapter.items.IHeader)8 ArrayList (java.util.ArrayList)2 NonNull (androidx.annotation.NonNull)1 EditItemInteractor (de.djuelg.neuronizer.domain.interactors.todolist.EditItemInteractor)1 EditItemInteractorImpl (de.djuelg.neuronizer.domain.interactors.todolist.impl.EditItemInteractorImpl)1 TodoListItem (de.djuelg.neuronizer.domain.model.todolist.TodoListItem)1 TodoListItemViewModel (de.djuelg.neuronizer.presentation.ui.flexibleadapter.TodoListItemViewModel)1 FlexibleAdapter (eu.davidea.flexibleadapter.FlexibleAdapter)1 IExpandable (eu.davidea.flexibleadapter.items.IExpandable)1 IFlexible (eu.davidea.flexibleadapter.items.IFlexible)1 AbstractItem (eu.davidea.samples.flexibleadapter.items.AbstractItem)1 ExpandableHeaderItem (eu.davidea.samples.flexibleadapter.items.ExpandableHeaderItem)1 HeaderItem (eu.davidea.samples.flexibleadapter.items.HeaderItem)1 InstagramHeaderItem (eu.davidea.samples.flexibleadapter.items.InstagramHeaderItem)1 StaggeredHeaderItem (eu.davidea.samples.flexibleadapter.items.StaggeredHeaderItem)1 List (java.util.List)1