Java Code Examples for androidx.recyclerview.widget.RecyclerView#post()
The following examples show how to use
androidx.recyclerview.widget.RecyclerView#post() .
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: PageRequester.java From OmegaRecyclerView with MIT License | 6 votes |
@Override public void getItemOffsets(Rect outRect, View view, RecyclerView recyclerView, RecyclerView.State state) { if (mCallback == null || !mEnabled) return; int adapterPosition = ((RecyclerView.LayoutParams) view.getLayoutParams()).getViewAdapterPosition(); int itemCount = recyclerView.getAdapter().getItemCount(); // RecyclerView.Adapter getItemCount gives count of values + 1 (PaginationViewHolder) int preventionPosition = itemCount - mCallback.getPagePreventionForEnd() - 1; if (adapterPosition >= preventionPosition && itemCount > mLastItemCount) { mCurrentPage++; recyclerView.post(new Runnable() { @Override public void run() { mCallback.onPageRequest(mCurrentPage); } }); mLastItemCount = itemCount; } }
Example 2
Source File: InfiniteRecyclerView.java From CommonUtils with Apache License 2.0 | 5 votes |
@Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, final int dy) { recyclerView.post(() -> { if (!canScrollVertically(1) && dy > 0) if (getAdapter() instanceof InfiniteAdapter) ((InfiniteAdapter) getAdapter()).loadMoreContent(); }); }
Example 3
Source File: StickyViewBehavior.java From brickkit-android with Apache License 2.0 | 5 votes |
@Override protected boolean attach(RecyclerView recyclerView) { if (recyclerView != null) { recyclerView.addOnScrollListener(this); recyclerView.post(new Runnable() { @Override public void run() { onScroll(); } }); } return true; }
Example 4
Source File: PagedLoadScrollListener.java From StickyHeaders with MIT License | 5 votes |
@Override public void onScrolled(RecyclerView view, int dx, int dy) { // no-op if we're loading, or exhausted if (loading || loadExhausted) { return; } // If the total item count is zero and the previous isn't, assume the // list is invalidated and should be reset back to initial state int totalItemCount = layoutManager.getItemCount(); if (totalItemCount < previousTotalItemCount) { this.currentPage = 0; this.previousTotalItemCount = totalItemCount; } else if (totalItemCount > 0) { View lastVisibleItem = layoutManager.getBottommostChildView(); int lastVisibleItemAdapterPosition = layoutManager.getViewAdapterPosition(lastVisibleItem); if ((lastVisibleItemAdapterPosition + visibleThreshold) > totalItemCount) { currentPage++; loading = true; view.post(new Runnable() { @Override public void run() { onLoadMore(currentPage, loadCompleteNotifier); } }); } } }
Example 5
Source File: EndlessRecyclerAdapter.java From GestureViews with Apache License 2.0 | 5 votes |
private void loadNextItemsIfNeeded(RecyclerView recyclerView) { if (!isLoading && !isError) { View lastVisibleChild = recyclerView.getChildAt(recyclerView.getChildCount() - 1); int lastVisiblePos = recyclerView.getChildAdapterPosition(lastVisibleChild); int total = getItemCount(); if (lastVisiblePos >= total - loadingOffset) { // We need to use runnable, since recycler view does not like when we are notifying // about changes during scroll callback. recyclerView.post(this::loadNextItems); } } }
Example 6
Source File: PostItemsListFragment.java From mimi-reader with Apache License 2.0 | 4 votes |
private void scrollListToTop(final RecyclerView recyclerView) { recyclerView.post(() -> recyclerView.scrollToPosition(0)); }
Example 7
Source File: CardDisplayManageActivity.java From GeometricWeather with GNU Lesser General Public License v3.0 | 4 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); this.setContentView(R.layout.activity_card_display_manage); Toolbar toolbar = findViewById(R.id.activity_card_display_manage_toolbar); toolbar.setNavigationIcon(R.drawable.ic_toolbar_back); toolbar.setNavigationOnClickListener(view -> finish()); List<CardDisplay> displayCards = SettingsOptionManager.getInstance(this).getCardDisplayList(); cardDisplayAdapter = new CardDisplayAdapter(displayCards, cardDisplay -> { setResult(RESULT_OK); tagAdapter.insertItem(new CardTag(cardDisplay)); resetBottomBarVisibility(); }); RecyclerView recyclerView = findViewById(R.id.activity_card_display_manage_recyclerView); recyclerView.setLayoutManager(new LinearLayoutManager(this)); recyclerView.addItemDecoration(new ListDecoration(this)); recyclerView.setAdapter(cardDisplayAdapter); new ItemTouchHelper( new CardDisplaySwipeCallback( ItemTouchHelper.UP | ItemTouchHelper.DOWN, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT ) ).attachToRecyclerView(recyclerView); List<CardDisplay> otherCards = new ArrayList<>(); otherCards.add(CardDisplay.CARD_DAILY_OVERVIEW); otherCards.add(CardDisplay.CARD_HOURLY_OVERVIEW); otherCards.add(CardDisplay.CARD_AIR_QUALITY); otherCards.add(CardDisplay.CARD_ALLERGEN); otherCards.add(CardDisplay.CARD_SUNRISE_SUNSET); otherCards.add(CardDisplay.CARD_LIFE_DETAILS); for (int i = otherCards.size() - 1; i >= 0; i --) { for (int j = 0; j < displayCards.size(); j ++) { if (otherCards.get(i) == displayCards.get(j)) { otherCards.remove(i); break; } } } List<TagAdapter.Tag> tagList = new ArrayList<>(); for (CardDisplay card : otherCards) { tagList.add(new CardTag(card)); } tagAdapter = new TagAdapter(this, tagList, (checked, oldPosition, newPosition) -> { setResult(RESULT_OK); CardTag tag = (CardTag) tagAdapter.removeItem(newPosition); cardDisplayAdapter.insertItem(tag.card); resetBottomBarVisibility(); return true; }); bottomBar = findViewById(R.id.activity_card_display_manage_bottomBar); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { bottomBar.setOnApplyWindowInsetsListener((v, insets) -> { bottomBar.setPadding(0, 0, 0, insets.getSystemWindowInsetBottom()); return insets; }); } RecyclerView bottomRecyclerView = findViewById(R.id.activity_card_display_manage_bottomRecyclerView); bottomRecyclerView.setLayoutManager( new LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)); bottomRecyclerView.addItemDecoration( new GridMarginsDecoration( getResources().getDimension(R.dimen.normal_margin), bottomRecyclerView ) ); bottomRecyclerView.setAdapter(tagAdapter); bottomAnimator = null; bottomBarVisibility = false; bottomRecyclerView.post(this::resetBottomBarVisibility); }
Example 8
Source File: BottomSheetAdapterBuilder.java From SimplicityBrowser with MIT License | 4 votes |
@SuppressLint("InflateParams") public View createView(int titleTextColor, int backgroundDrawable, int backgroundColor, int dividerBackground, int itemTextColor, int itemBackground, int tintColor, BottomSheetItemClickListener itemClickListener) { if (mFromMenu) { mItems = createAdapterItems(dividerBackground, titleTextColor, itemTextColor, itemBackground, tintColor); } LayoutInflater layoutInflater = LayoutInflater.from(mContext); View sheet = mMode == BottomSheetBuilder.MODE_GRID ? layoutInflater.inflate(R.layout.bottomsheetbuilder_sheet_grid, null) : layoutInflater.inflate(R.layout.bottomsheetbuilder_sheet_list, null); final RecyclerView recyclerView = (RecyclerView) sheet.findViewById(R.id.recyclerView); recyclerView.setHasFixedSize(true); if (backgroundDrawable != 0) { sheet.setBackgroundResource(backgroundDrawable); } else { if (backgroundColor != 0) { sheet.setBackgroundColor(backgroundColor); } } // If we only have one title and it's the first item, set it as fixed if (mTitles == 1 && mMode == BottomSheetBuilder.MODE_LIST) { BottomSheetItem header = mItems.get(0); TextView headerTextView = (TextView) sheet.findViewById(R.id.textView); if (header instanceof BottomSheetHeader) { headerTextView.setVisibility(View.VISIBLE); headerTextView.setText(header.getTitle()); if (titleTextColor != 0) { headerTextView.setTextColor(titleTextColor); } mItems.remove(0); } } final BottomSheetItemAdapter adapter = new BottomSheetItemAdapter(mItems, mMode, itemClickListener); if (mMode == BottomSheetBuilder.MODE_LIST) { recyclerView.setLayoutManager(new LinearLayoutManager(mContext)); recyclerView.setAdapter(adapter); } else { final int columns = mContext.getResources().getInteger(R.integer.bottomsheet_grid_columns); GridLayoutManager layoutManager = new GridLayoutManager(mContext, columns); recyclerView.setLayoutManager(layoutManager); recyclerView.post(new Runnable() { @Override public void run() { float margin = mContext.getResources() .getDimensionPixelSize(R.dimen.bottomsheet_grid_horizontal_margin); adapter.setItemWidth((int) ((recyclerView.getWidth() - 2 * margin) / columns)); recyclerView.setAdapter(adapter); } }); } return sheet; }