Skip to content

Instantly share code, notes, and snippets.

@neonankiti
Last active February 22, 2018 20:04
Show Gist options
  • Save neonankiti/9faad768778c234cb57977cb0150e4fb to your computer and use it in GitHub Desktop.
Save neonankiti/9faad768778c234cb57977cb0150e4fb to your computer and use it in GitHub Desktop.
add onScrollStateChanged() for checking if there is an item view inside the screen. If so, tell the item view(VideoView) that it can start movie.
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
int firstCompletelyVisibleItemPosition = ((LinearLayoutManager) recyclerView.getLayoutManager())
.findFirstCompletelyVisibleItemPosition();
boolean isVideo = recyclerView.getAdapter()
.getItemViewType(firstCompletelyVisibleItemPosition) == TYPE_MOVIE;
if (!isVideo) {
return;
}
}
@Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
}
});
interface OnScreenScopeListener {
void getCompletelyVisiblePosition(int firstCompletelyVisibleItemPosition);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment