danylovolokh / VideoPlayerManager

This is a project designed to help controlling Android MediaPlayer class. It makes it easier to use MediaPlayer ListView and RecyclerView. Also it tracks the most visible item in scrolling list. When new item in the list become the most visible, this library gives an API to track it.
3.15k stars 747 forks source link

I modified the calculateActiveItem method and the calculateMostVisibleItem method. #109

Open JakePrim opened 4 years ago

JakePrim commented 4 years ago

I modified the calculateActiveItem method and the calculateMostVisibleItem method. I think the call to the deactivate method should destroy the previous call to the deactivate method on the next display, which is more logical.

` private void calculateActiveItem(ItemsPositionGetter itemsPositionGetter, ListItemData listItemData) { /* 1. / int currentItemVisibilityPercents = listItemData.getVisibilityPercents(mListItems); if (SHOW_LOGS) Logger.v(TAG, "calculateActiveItem, mScrollDirection " + mScrollDirection);

    /** 2. */
    ListItemData neighbourItemData = new ListItemData();
    switch (mScrollDirection) {
        case UP:
            findPreviousItem(itemsPositionGetter, listItemData, neighbourItemData);
            break;
        case DOWN:
            findNextItem(itemsPositionGetter, listItemData, neighbourItemData);
            break;
    }
    if (SHOW_LOGS)
        Logger.v(TAG, "calculateActiveItem, currentItemVisibilityPercents " + currentItemVisibilityPercents);

    /** 3. */
    if (enoughPercentsForDeactivation(currentItemVisibilityPercents) && neighbourItemData.isAvailable()) {

        // neighbour item become active (current)
        if (mOldItem == null) {
            mOldItem = mCurrentItem;
        } else {
            mCallback.deactivateCurrentItem(mListItems.get(mOldItem.getIndex()), mOldItem.getView(), mOldItem.getIndex());
            mOldItem = mCurrentItem;
        }
        /** 4. */
        setCurrentItem(neighbourItemData);
    } else {
        calculateMostVisibleItem(itemsPositionGetter, itemsPositionGetter.getFirstVisiblePosition(),
                itemsPositionGetter.getLastVisiblePosition());
    }
}`