androidx.recyclerview.widget.RecyclerView.OnScrollListener Java Examples

The following examples show how to use androidx.recyclerview.widget.RecyclerView.OnScrollListener. 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: ConversationFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
private void initializeResources() {
  long oldThreadId = threadId;

  int startingPosition  = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);

  this.recipient         = Recipient.live(getActivity().getIntent().getParcelableExtra(ConversationActivity.RECIPIENT_EXTRA));
  this.threadId          = this.getActivity().getIntent().getLongExtra(ConversationActivity.THREAD_ID_EXTRA, -1);
  this.unknownSenderView = new UnknownSenderView(getActivity(), recipient.get(), threadId, () -> clearHeaderIfNotTyping(getListAdapter()));

  deferred.setDeferred(true);
  conversationViewModel.onConversationDataAvailable(threadId, startingPosition);

  OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
  list.addOnScrollListener(scrollListener);

  if (oldThreadId != threadId) {
    ApplicationContext.getInstance(requireContext()).getTypingStatusRepository().getTypists(oldThreadId).removeObservers(this);
  }
}
 
Example #2
Source File: GridModel.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
GridModel(
        GridHost<K> host,
        ItemKeyProvider<K> keyProvider,
        SelectionPredicate<K> selectionPredicate) {

    checkArgument(host != null);
    checkArgument(keyProvider != null);
    checkArgument(selectionPredicate != null);

    mHost = host;
    mKeyProvider = keyProvider;
    mSelectionPredicate = selectionPredicate;

    mScrollListener = new OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            GridModel.this.onScrolled(recyclerView, dx, dy);
        }
    };

    mHost.addOnScrollListener(mScrollListener);
}
 
Example #3
Source File: RecyclerSpec.java    From litho with Apache License 2.0 5 votes vote down vote up
@OnUnbind
static void onUnbind(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) RecyclerEventsController recyclerEventsController,
    @Prop(optional = true, varArg = "onScrollListener")
        List<OnScrollListener> onScrollListeners) {
  final LithoRecylerView recyclerView = (LithoRecylerView) sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  binder.unbind(recyclerView);

  if (recyclerEventsController != null) {
    recyclerEventsController.setSectionsRecyclerView(null);
  }

  if (onScrollListeners != null) {
    for (OnScrollListener onScrollListener : onScrollListeners) {
      recyclerView.removeOnScrollListener(onScrollListener);
    }
  }

  recyclerView.setTouchInterceptor(null);

  sectionsRecycler.setOnRefreshListener(null);
}
 
Example #4
Source File: ConversationFragment.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void initializeResources() {
    this.chatId            = this.getActivity().getIntent().getIntExtra(ConversationActivity.CHAT_ID_EXTRA, -1);
    this.recipient         = Recipient.from(getActivity(), Address.fromChat((int)this.chatId));
    this.startingPosition  = this.getActivity().getIntent().getIntExtra(ConversationActivity.STARTING_POSITION_EXTRA, -1);
    this.firstLoad         = true;

    OnScrollListener scrollListener = new ConversationScrollListener(getActivity());
    list.addOnScrollListener(scrollListener);
}
 
Example #5
Source File: BandSelectionHelper.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
/**
 * See {@link BandSelectionHelper#create}.
 */
BandSelectionHelper(
        @NonNull BandHost<K> host,
        @NonNull AutoScroller scroller,
        @NonNull ItemKeyProvider<K> keyProvider,
        @NonNull SelectionTracker<K> selectionTracker,
        @NonNull BandPredicate bandPredicate,
        @NonNull FocusDelegate<K> focusDelegate,
        @NonNull OperationMonitor lock) {

    checkArgument(host != null);
    checkArgument(scroller != null);
    checkArgument(keyProvider != null);
    checkArgument(selectionTracker != null);
    checkArgument(bandPredicate != null);
    checkArgument(focusDelegate != null);
    checkArgument(lock != null);

    mHost = host;
    mKeyProvider = keyProvider;
    mSelectionTracker = selectionTracker;
    mBandPredicate = bandPredicate;
    mFocusDelegate = focusDelegate;
    mLock = lock;

    mHost.addOnScrollListener(
            new OnScrollListener() {
                @Override
                public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                    BandSelectionHelper.this.onScrolled(recyclerView, dx, dy);
                }
            });

    mScroller = scroller;

    mGridObserver = new GridModel.SelectionObserver<K>() {
        @Override
        public void onSelectionChanged(Set<K> updatedSelection) {
            mSelectionTracker.setProvisionalSelection(updatedSelection);
        }
    };
}
 
Example #6
Source File: DefaultBandHost.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
void addOnScrollListener(@NonNull OnScrollListener listener) {
    mRecyclerView.addOnScrollListener(listener);
}
 
Example #7
Source File: DefaultBandHost.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Override
void removeOnScrollListener(@NonNull OnScrollListener listener) {
    mRecyclerView.removeOnScrollListener(listener);
}
 
Example #8
Source File: RecyclerSpec.java    From litho with Apache License 2.0 4 votes vote down vote up
@OnBind
protected static void onBind(
    ComponentContext context,
    SectionsRecyclerView sectionsRecycler,
    @Prop Binder<RecyclerView> binder,
    @Prop(optional = true) final RecyclerEventsController recyclerEventsController,
    @Prop(optional = true, varArg = "onScrollListener") List<OnScrollListener> onScrollListeners,
    @Prop(optional = true) SnapHelper snapHelper,
    @Prop(optional = true) boolean pullToRefresh,
    @Prop(optional = true) LithoRecylerView.TouchInterceptor touchInterceptor,
    @Nullable @Prop(optional = true) final EventHandler refreshHandler) {

  // contentDescription should be set on the recyclerView itself, and not the sectionsRecycler.
  sectionsRecycler.setContentDescription(null);

  sectionsRecycler.setEnabled(pullToRefresh && refreshHandler != null);
  sectionsRecycler.setOnRefreshListener(
      new OnRefreshListener() {
        @Override
        public void onRefresh() {
          Recycler.dispatchPTRRefreshEvent(refreshHandler);
        }
      });

  final LithoRecylerView recyclerView = (LithoRecylerView) sectionsRecycler.getRecyclerView();

  if (recyclerView == null) {
    throw new IllegalStateException(
        "RecyclerView not found, it should not be removed from SwipeRefreshLayout "
            + "before unmounting");
  }

  if (onScrollListeners != null) {
    for (OnScrollListener onScrollListener : onScrollListeners) {
      recyclerView.addOnScrollListener(onScrollListener);
    }
  }

  if (touchInterceptor != null) {
    recyclerView.setTouchInterceptor(touchInterceptor);
  }

  // We cannot detach the snap helper in unbind, so it may be possible for it to get
  // attached twice which causes SnapHelper to raise an exception.
  if (snapHelper != null && recyclerView.getOnFlingListener() == null) {
    snapHelper.attachToRecyclerView(recyclerView);
  }

  binder.bind(recyclerView);

  if (recyclerEventsController != null) {
    recyclerEventsController.setSectionsRecyclerView(sectionsRecycler);
  }

  if (sectionsRecycler.hasBeenDetachedFromWindow()) {
    recyclerView.requestLayout();
    sectionsRecycler.setHasBeenDetachedFromWindow(false);
  }
}
 
Example #9
Source File: BandSelectionHelper.java    From FairEmail with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Add a listener to be notified on scroll events.
 */
abstract void addOnScrollListener(@NonNull OnScrollListener listener);
 
Example #10
Source File: GridModel.java    From FairEmail with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Remove the listener.
 *
 * @param listener
 */
abstract void removeOnScrollListener(@NonNull OnScrollListener listener);