示例#1
0
  private void setupFeed() {
    final LinearLayoutManager linearLayoutManager =
        new LinearLayoutManager(getActivity()) {
          @Override
          protected int getExtraLayoutSpace(RecyclerView.State state) {
            return 300;
          }
        };
    rvFeed.setLayoutManager(linearLayoutManager);

    feedAdapter = new VideoFeedAdapter(getActivity());
    feedAdapter.setOnFeedItemClickListener(this);
    rvFeed.setAdapter(feedAdapter);

    ViewUtils.setSwipeRefreshLayoutColor(mSwipeRefreshLayout);
    mSwipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            lazyLoad();
            isFeedEnd = false;
            mSwipeRefreshLayout.setEnabled(false);
          }
        });

    // RecyclerView滑动监听
    rvFeed.addOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            if (isLoading || isFeedEnd) {
              return;
            }
            if (newState == RecyclerView.SCROLL_STATE_IDLE
                && lastVisibleItem + 1 == feedAdapter.getItemCount()) {
              loadMore();
            }
          }

          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            lastVisibleItem = linearLayoutManager.findLastVisibleItemPosition();
          }
        });

    mIsPrepared = true;
    lazyLoad();
  }
示例#2
0
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_video_feed, container, false);
    ButterKnife.bind(this, view);

    if (!LibsChecker.checkVitamioLibs(getActivity())) return null;

    setupFeed();

    if (savedInstanceState == null) {
      pendingIntroAnimation = true;
    } else {
      feedAdapter.updateItems(false);
    }
    return view;
  }