Example usage for android.support.v4.util LongSparseArray indexOfValue

List of usage examples for android.support.v4.util LongSparseArray indexOfValue

Introduction

In this page you can find the example usage for android.support.v4.util LongSparseArray indexOfValue.

Prototype

public int indexOfValue(E e) 

Source Link

Usage

From source file:com.facebook.litho.MountState.java

private static boolean shouldUpdateMountItem(LayoutOutput layoutOutput, MountItem currentMountItem,
        boolean useUpdateValueFromLayoutOutput, LongSparseArray<MountItem> indexToItemMap,
        long[] layoutOutputsIds, ComponentsLogger logger) {
    final @LayoutOutput.UpdateState int updateState = layoutOutput.getUpdateState();
    final Component currentComponent = currentMountItem.getComponent();
    final ComponentLifecycle currentLifecycle = currentComponent.getLifecycle();
    final Component nextComponent = layoutOutput.getComponent();
    final ComponentLifecycle nextLifecycle = nextComponent.getLifecycle();

    // If the two components have different sizes and the mounted content depends on the size we
    // just return true immediately.
    if (!sameSize(layoutOutput, currentMountItem) && nextLifecycle.isMountSizeDependent()) {
        return true;
    }//from   w  w w  .j  a  va 2 s .co m

    if (useUpdateValueFromLayoutOutput) {
        if (updateState == LayoutOutput.STATE_UPDATED) {

            // Check for incompatible ReferenceLifecycle.
            if (currentLifecycle instanceof DrawableComponent && nextLifecycle instanceof DrawableComponent
                    && currentLifecycle.shouldComponentUpdate(currentComponent, nextComponent)) {

                if (logger != null) {
                    LayoutOutputLog logObj = new LayoutOutputLog();

                    logObj.currentId = indexToItemMap.keyAt(indexToItemMap.indexOfValue(currentMountItem));
                    logObj.currentLifecycle = currentLifecycle.toString();

                    logObj.nextId = layoutOutput.getId();
                    logObj.nextLifecycle = nextLifecycle.toString();

                    for (int i = 0; i < layoutOutputsIds.length; i++) {
                        if (layoutOutputsIds[i] == logObj.currentId) {
                            if (logObj.currentIndex == -1) {
                                logObj.currentIndex = i;
                            }

                            logObj.currentLastDuplicatedIdIndex = i;
                        }
                    }

                    if (logObj.nextId == logObj.currentId) {
                        logObj.nextIndex = logObj.currentIndex;
                        logObj.nextLastDuplicatedIdIndex = logObj.currentLastDuplicatedIdIndex;
                    } else {
                        for (int i = 0; i < layoutOutputsIds.length; i++) {
                            if (layoutOutputsIds[i] == logObj.nextId) {
                                if (logObj.nextIndex == -1) {
                                    logObj.nextIndex = i;
                                }

                                logObj.nextLastDuplicatedIdIndex = i;
                            }
                        }
                    }

                    final LogEvent mismatchEvent = logger
                            .newEvent(EVENT_SHOULD_UPDATE_REFERENCE_LAYOUT_MISMATCH);
                    mismatchEvent.addParam(PARAM_MESSAGE, logObj.toString());
                    logger.log(mismatchEvent);
                }

                return true;
            }

            return false;
        } else if (updateState == LayoutOutput.STATE_DIRTY) {
            return true;
        }
    }

    if (!currentLifecycle.callsShouldUpdateOnMount()) {
        return true;
    }

    return currentLifecycle.shouldComponentUpdate(currentComponent, nextComponent);
}

From source file:com.facebook.litho.MountState.java

private void unmountItem(ComponentContext context, int index, LongSparseArray<ComponentHost> hostsByMarker) {
    final MountItem item = getItemAt(index);

    // The root host item should never be unmounted as it's a reference
    // to the top-level LithoView.
    if (item == null || mLayoutOutputsIds[index] == ROOT_HOST_ID) {
        return;//from w w  w. j  ava 2s  .  c om
    }

    final Object content = item.getContent();

    // Recursively unmount mounted children items.
    // This is the case when mountDiffing is enabled and unmountOrMoveOldItems() has a matching
    // sub tree. However, traversing the tree bottom-up, it needs to unmount a node holding that
    // sub tree, that will still have mounted items. (Different sequence number on LayoutOutput id)
    if ((content instanceof ComponentHost) && !(content instanceof LithoView)) {
        final ComponentHost host = (ComponentHost) content;

        // Concurrently remove items therefore traverse backwards.
        for (int i = host.getMountItemCount() - 1; i >= 0; i--) {
            final MountItem mountItem = host.getMountItemAt(i);
            final long layoutOutputId = mIndexToItemMap.keyAt(mIndexToItemMap.indexOfValue(mountItem));

            for (int mountIndex = mLayoutOutputsIds.length - 1; mountIndex >= 0; mountIndex--) {
                if (mLayoutOutputsIds[mountIndex] == layoutOutputId) {
                    unmountItem(context, mountIndex, hostsByMarker);
                    break;
                }
            }
        }

        if (host.getMountItemCount() > 0) {
            throw new IllegalStateException("Recursively unmounting items from a ComponentHost, left"
                    + " some items behind maybe because not tracked by its MountState");
        }
    }

    final ComponentHost host = item.getHost();
    host.unmount(index, item);

    unsetViewAttributes(item);

    final Component<?> component = item.getComponent();

    if (isHostSpec(component)) {
        final ComponentHost componentHost = (ComponentHost) content;
        hostsByMarker.removeAt(hostsByMarker.indexOfValue(componentHost));
        removeDisappearingMountContentFromComponentHost(componentHost);
    }

    unbindAndUnmountLifecycle(context, item);

    mIndexToItemMap.remove(mLayoutOutputsIds[index]);
    final String transitionKey = maybeDecrementTransitionKeyMountCount(item);

    if (transitionKey != null && mTransitionManager != null) {
        mTransitionManager.onContentUnmounted(transitionKey);
    }

    if (component.getLifecycle().canMountIncrementally()) {
        mCanMountIncrementallyMountItems.delete(mLayoutOutputsIds[index]);
    }

    ComponentsPools.release(context, item);

    mMountStats.unmountedCount++;
}