コード例 #1
0
ファイル: FeedFragment.java プロジェクト: lpjhblpj/football
  private void initListView(View v) {
    mListView = (RecyclerView) v.findViewById(R.id.list);
    layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
    mListView.setLayoutManager(layoutManager);
    mListView.addItemDecoration(
        new SimpleDividerItemDecoration(
            getActivity(), LinearLayoutManager.VERTICAL, 8f, 0xffEDEDED));
    adapter = new FeedAdapter(getActivity(), data, listener);
    mListView.setAdapter(adapter);
    mEmptyView = (EmptyView) v.findViewById(R.id.view_list_empty_layout);
    mEmptyView.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {}
        });
    mRefresh = v.findViewById(R.id.refresh);
    mRefresh.setOnClickListener(onClickListener);
    refreshTextView = (TextView) v.findViewById(R.id.refresh_news_count);
    refreshTextView.setOnClickListener(mRefreshNewsListener);
    lineView = v.findViewById(R.id.line);
    swipeRefreshLayout = (SwipeRefreshLayout) v.findViewById(R.id.swipe_refresh_layout);
    swipeRefreshLayout.setOnRefreshListener(
        new SwipeRefreshLayout.OnRefreshListener() {
          @Override
          public void onRefresh() {
            FeedFragment.this.onRefresh();
          }
        });
    mListView.setOnScrollListener(
        new RecyclerView.OnScrollListener() {
          @Override
          public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            super.onScrollStateChanged(recyclerView, newState);
            // 加载更多
            if (!isLoading
                && adapter.getItemCount() == (layoutManager.findLastVisibleItemPosition() + 1)
                && newState == RecyclerView.SCROLL_STATE_IDLE) {
              isLoading = true;
              adapter.setLoadMoreEnable(true);
              adapter.setLoadMoreState(XListViewFooter.STATE_LOADING);
              adapter.notifyDataSetChanged();
              onLoadMore();
            }
          }

          @Override
          public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            // 解决RecyclerView和SwipeRefreshLayout共用存在的bug
            swipeRefreshLayout.setEnabled(
                layoutManager.findFirstCompletelyVisibleItemPosition() == 0);
          }
        });
    request(Urls.SERVER_PATH + "/user/feeds", 0);
  }
コード例 #2
0
ファイル: FeedFragment.java プロジェクト: lpjhblpj/football
 public void onEventMainThread(SubscriptionAddActivity.FollowFlagEvent event) {
   if (event.flag) {
     if (mSetting != null) mSetting.setVisibility(View.GONE);
     if (listLayout == null) {
       listLayout = mListViewStub.inflate();
       initListView(listLayout);
     } else {
       listLayout.setVisibility(View.VISIBLE);
       data.clear();
       adapter.notifyDataSetChanged();
       mEmptyView.show(true);
       mEmptyView.onLoading();
       request(Urls.SERVER_PATH + "/user/feeds", 0);
     }
   } else {
     stopRefreshNews();
     if (mListViewStub != null) mListViewStub.setVisibility(View.GONE);
     if (settingLayout == null) {
       settingLayout = mSetting.inflate();
       initSettingView(settingLayout);
     } else settingLayout.setVisibility(View.VISIBLE);
   }
 }
コード例 #3
0
ファイル: FeedFragment.java プロジェクト: lpjhblpj/football
 @Override
 public void onLoadMore() {
   if (!TextUtils.isEmpty(nextUrl)) {
     request(nextUrl, 1);
   }
 }
コード例 #4
0
ファイル: FeedFragment.java プロジェクト: lpjhblpj/football
 @Override
 public void onRefresh() {
   new ParseText().recordRefreshTime(mListView, REFRESH_TIME);
   request(Urls.SERVER_PATH + "/user/feeds", 0);
 }