Java Code Examples for android.support.v7.widget.RecyclerView#NO_ID

The following examples show how to use android.support.v7.widget.RecyclerView#NO_ID . 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: BasicListComponent.java    From weex-uikit with MIT License 6 votes vote down vote up
/**
 * generate viewtype by component
 *
 * @param component
 * @return
 */
private int generateViewType(WXComponent component) {
  long id;
  try {
    id = Integer.parseInt(component.getDomObject().getRef());
    String type = component.getDomObject().getAttrs().getScope();

    if (!TextUtils.isEmpty(type)) {
      if (mRefToViewType == null) {
        mRefToViewType = new ArrayMap<>();
      }
      if (!mRefToViewType.containsKey(type)) {
        mRefToViewType.put(type, id);
      }
      id = mRefToViewType.get(type);

    }
  } catch (RuntimeException e) {
    WXLogUtils.eTag(TAG, e);
    id = RecyclerView.NO_ID;
    WXLogUtils.e(TAG, "getItemViewType: NO ID, this will crash the whole render system of WXListRecyclerView");
  }
  return (int) id;
}
 
Example 2
Source File: WXListComponent.java    From weex with Apache License 2.0 6 votes vote down vote up
/**
 * Return the child component type. The type is defined by scopeValue in .we file.
 *
 * @param position the position of the child component.
 * @return the type of certain component.
 */
@Override
public int getItemViewType(int position) {
    long id;
    try {
        id = Integer.parseInt(getChild(position).getDomObject().ref);
        String type = mChildren.get(position).getDomObject().attr.getScope();

        if (!TextUtils.isEmpty(type)) {
            if (mRefToViewType == null) {
                mRefToViewType = new HashMap<>();
            }
            if (!mRefToViewType.containsKey(type)) {
                mRefToViewType.put(type, id);
            }
            id = mRefToViewType.get(type);

        }
    } catch (RuntimeException e) {
        WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
        id = RecyclerView.NO_ID;
        WXLogUtils.e(TAG, "getItemViewType: NO ID, this will crash the whole render system of WXListRecyclerView");

    }
    return (int) id;
}
 
Example 3
Source File: BasicListComponent.java    From ucar-weex-core with Apache License 2.0 5 votes vote down vote up
@Override
public long getItemId(int position) {
  long id;
  try {
    id = Long.parseLong(getChild(position).getDomObject().getRef());
  } catch (RuntimeException e) {
    WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
    id = RecyclerView.NO_ID;
  }
  return id;
}
 
Example 4
Source File: BookmarksFragment.java    From Xndroid with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v) {
    int index = getAdapterPosition();
    if (onItemClickListener != null && index != RecyclerView.NO_ID) {
        onItemClickListener.onItemClick(adapter.itemAt(index));
    }
}
 
Example 5
Source File: ShieldDisplayNodeAdapter.java    From Shield with MIT License 5 votes vote down vote up
@Override
public long getItemId(int position) {
    ShieldDisplayNode displayNode = getDisplayNode(position);
    if (displayNode != null && displayNode.stableid != null) {
        if (nodeIdIndex.containsValue(displayNode.stableid)) {
            return nodeIdIndex.getIndex(displayNode.stableid);
        } else {
            nodeIdIndex.putValue(displayNode.stableid);
            return nodeIdIndex.getIndex(displayNode.stableid);
        }
    }
    return RecyclerView.NO_ID;
}
 
Example 6
Source File: UploadRecyclerAdapter.java    From RxUploader with Apache License 2.0 5 votes vote down vote up
@Override
public long getItemId(int position) {
    final DataModel m = getItemAt(position);
    if (m == null) {
        return RecyclerView.NO_ID;
    }
    return m.id().hashCode();
}
 
Example 7
Source File: BasicListComponent.java    From weex-uikit with MIT License 5 votes vote down vote up
@Override
public long getItemId(int position) {
  long id;
  try {
    id = Long.parseLong(getChild(position).getDomObject().getRef());
  } catch (RuntimeException e) {
    WXLogUtils.e(TAG, WXLogUtils.getStackTrace(e));
    id = RecyclerView.NO_ID;
  }
  return id;
}
 
Example 8
Source File: SquidRecyclerAdapter.java    From squidb with Apache License 2.0 5 votes vote down vote up
@Override
public long getItemId(int position) {
    if (hasStableIds()) {
        if (cursor != null && cursor.moveToPosition(position)) {
            return cursor.get(idProperty);
        }
        return RecyclerView.NO_ID;
    }
    return super.getItemId(position);
}
 
Example 9
Source File: RecyclerViewFragment.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
public final void performScrollToStableId(long stableId) {
    if (stableId != RecyclerView.NO_ID) {
        int position = -1;
        for (int i = 0; i < mAdapter.getItemCount(); i++) {
            if (mAdapter.getItemId(i) == stableId) {
                position = i;
                break;
            }
        }
        if (position >= 0) {
            scrollToPosition(position);
            onScrolledToStableId(stableId, position);
        }
    }
}
 
Example 10
Source File: DateDividedAdapter.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
public long getItemId(int position) {
    if (!hasStableIds()) return RecyclerView.NO_ID;

    Pair<Date, TimedItem> pair = getItemAt(position);
    return pair.second == null ? getStableIdFromDate(pair.first) : pair.second.getStableId();
}
 
Example 11
Source File: DateDividedAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public long getItemId(int position) {
    if (!hasStableIds()) return RecyclerView.NO_ID;

    Pair<Date, TimedItem> pair = getItemAt(position);
    return pair.second == null ? getStableIdFromDate(pair.first) : pair.second.getStableId();
}
 
Example 12
Source File: FeedAdapter.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public long getItemId(int position) {
	try {
		return data.getJSONObject(position).getJSONObject("id").getString("$t").hashCode();
	} catch (JSONException e) {
		return RecyclerView.NO_ID;
	}
}
 
Example 13
Source File: AlarmsCursorAdapter.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
    public int getItemViewType(int position) {
        final long stableId = getItemId(position);
        return stableId != RecyclerView.NO_ID && stableId == mExpandedId
//                position == mExpandedPosition
                ? VIEW_TYPE_EXPANDED : VIEW_TYPE_COLLAPSED;
    }
 
Example 14
Source File: AlarmsCursorAdapter.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
public boolean expand(int position) {
        if (position == RecyclerView.NO_POSITION)
            return false;
        final long stableId = getItemId(position);
        if (stableId == RecyclerView.NO_ID || mExpandedId == stableId)
            return false;
        mExpandedId = stableId;
        // If we can call this, the item is in view, so we don't need to scroll to it?
//        mScrollHandler.smoothScrollTo(position);
        if (mExpandedPosition >= 0) {
            // Collapse this position first. getItemViewType() will be called
            // in onCreateViewHolder() to verify which ViewHolder to create
            // for the position.
            notifyItemChanged(mExpandedPosition);
        }
        mExpandedPosition = position;
        notifyItemChanged(position);
        return true;

        // This would be my alternative solution. But we're keeping Google's
        // because the stable ID *could* hold up better for orientation changes
        // than the position? I.e. when saving instance state we save the id.
//        int oldExpandedPosition = mExpandedPosition;
//        mExpandedPosition = position;
//        if (oldExpandedPosition >= 0) {
//            notifyItemChanged(oldExpandedPosition);
//        }
//        notifyItemChanged(mExpandedPosition);
    }
 
Example 15
Source File: RecyclerViewFragment.java    From ClockPlus with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onLoadFinished(Loader<C> loader, C data) {
    mAdapter.swapCursor(data);
    if (hasEmptyView() && mEmptyView != null) {
        // TODO: Last I checked after a fresh install, this worked fine.
        // However, previous attempts (without fresh installs) didn't hide the empty view
        // upon an item being added. Verify this is no longer the case.
        mEmptyView.setVisibility(mAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
    }
    // This may have been a requery due to content change. If the change
    // was an insertion, scroll to the last modified alarm.
    performScrollToStableId(mScrollToStableId);
    mScrollToStableId = RecyclerView.NO_ID;
}
 
Example 16
Source File: SimpleRecyclerAdapter.java    From SimpleRecyclerAdapter with Apache License 2.0 4 votes vote down vote up
protected long getItemId(@NonNull final T item, final int position) {
    return RecyclerView.NO_ID;
}
 
Example 17
Source File: AlarmsCursorAdapter.java    From ClockPlus with GNU General Public License v3.0 4 votes vote down vote up
public void collapse(int position) {
    mExpandedId = RecyclerView.NO_ID;
    mExpandedPosition = RecyclerView.NO_POSITION;
    notifyItemChanged(position);
}
 
Example 18
Source File: WrapperAdapter.java    From Paginate with Apache License 2.0 4 votes vote down vote up
@Override
public long getItemId(int position) {
    return isLoadingRow(position) ? RecyclerView.NO_ID : wrappedAdapter.getItemId(position);
}
 
Example 19
Source File: BaseItem.java    From AndroidUtilCode with Apache License 2.0 4 votes vote down vote up
public long getItemId() {
    return RecyclerView.NO_ID;
}
 
Example 20
Source File: RepositoryPresenter.java    From agera with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the stable ID for the {@code index}-th item to present the data. Called only if stable
 * IDs are enabled with {@link RepositoryAdapter#setHasStableIds
 * RepositoryAdapter.setHasStableIds(true)}, and therefore this method is optional with a default
 * implementation of returning {@link RecyclerView#NO_ID}. If stable IDs are enabled, this ID and
 * the item's {@linkplain #getLayoutResId layout resource ID} should together uniquely identify
 * this item in the whole {@link RecyclerView} throughout all changes.
 *
 * @param index The item index between 0 (incl.) and {@link #getItemCount} (excl.).
 */
public long getItemId(@NonNull final T data, final int index) {
  return RecyclerView.NO_ID;
}