diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/application/Constants.java b/app/src/main/java/mao/com/mao_wanandroid_client/application/Constants.java index 4ac11fe..d532ddb 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/application/Constants.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/application/Constants.java @@ -157,4 +157,11 @@ public class Constants { //个人中心 type 广场用户个人信息 public static final String SQUARE_USER_TYPE = "square_user_type"; + + //个人 中心 fragment 刷新 type(用于辨别当前adapter 动作) + public static final String REFRESH_TYPE = "refresh_type"; + + //个人 中心 fragment 加载更多 type + public static final String LOAD_MORE_TYPE = "load_more_type"; + } diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/CollectionPresenter.java b/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/CollectionPresenter.java index 7424202..4e26b5a 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/CollectionPresenter.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/CollectionPresenter.java @@ -90,12 +90,12 @@ public void onSuccess(CollectListData result) { if(pageNum >= 1){ //如果加载第二页 if(result.getDatas().size()> 0){ - curPage = result.getCurPage(); - mView.showCollectListData(result.getDatas(),isRefresh); - }else { - //哥这回真没了 - mView.showLoadDataMessage(MyApplication.getInstance().getString(R.string.not_load_more_msg)); - } + curPage = result.getCurPage(); + mView.showCollectListData(result.getDatas(),isRefresh); + }else { + //哥这回真没了 + mView.showLoadDataMessage(MyApplication.getInstance().getString(R.string.not_load_more_msg)); + } }else { //收藏首页 则直接反回数据 方便没有收藏数据判空 mView.showCollectListData(result.getDatas(),isRefresh); diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/PrivateArticleContract.java b/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/PrivateArticleContract.java index 157b043..d37a2c5 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/PrivateArticleContract.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/presenter/drawer/PrivateArticleContract.java @@ -17,7 +17,7 @@ public interface PrivateArticleContract { interface PrivateArticleView extends BaseView{ - void showPrivateArticleData(List articleDataList); + void showPrivateArticleData(boolean isLoadMore,List articleDataList); } @@ -27,6 +27,10 @@ interface PrivateArticleFragmentPresenter extends AbstractBasePresenter>>> userShareArticlesData = mDataClient.getUserShareArticlesData(userId, pageNum); userShareArticlesData.compose(RxSchedulers.observableIO2Main()) .subscribe(new BaseObserver>>() { @Override public void onSuccess(BaseMultipleData> result) { - mView.showPrivateArticleData(result.getData2().getDatas()); + if(result.getData2().getDatas().size()> 0){ + curPage = result.getData2().getCurPage(); + mView.showPrivateArticleData(isLoadMore,result.getData2().getDatas()); + }else { + //哥这回真没了 + mView.showErrorMsg(MyApplication.getInstance().getString(R.string.not_load_more_msg)); + } } @Override @@ -110,13 +130,19 @@ public void onFailure(Throwable e, String errorMsg) { } //个人分享文章列表 - private void getPrivateArticleDataList(int pageNum) { + private void getPrivateArticleDataList(int pageNum,boolean isLoadMore) { Observable>>> privateShareArticlesData = mDataClient.getPrivateShareArticlesData(pageNum); privateShareArticlesData.compose(RxSchedulers.observableIO2Main()) .subscribe(new BaseObserver>>() { @Override public void onSuccess(BaseMultipleData> result) { - mView.showPrivateArticleData(result.getData2().getDatas()); + if(result.getData2().getDatas().size()> 0){ + curPage = result.getData2().getCurPage(); + mView.showPrivateArticleData(isLoadMore,result.getData2().getDatas()); + }else { + //哥这回真没了 + mView.showErrorMsg(MyApplication.getInstance().getString(R.string.not_load_more_msg)); + } } @Override diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionFragment.java b/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionFragment.java index 62f97db..88c5119 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionFragment.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionFragment.java @@ -263,4 +263,9 @@ public void updateDate() { //刷新数据 mPresenter.getCollectListData(); } + + public void loadDate() { + //加载更多 + mPresenter.getLoadCollectListData(); + } } diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionWebFragment.java b/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionWebFragment.java index 820d6f5..023294d 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionWebFragment.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/CollectionWebFragment.java @@ -249,4 +249,7 @@ public void onClick(View v) { public void updateDate() { mPresenter.getCollectWebData(); } + + public void loadDate() { + } } diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/PrivateArticleFragment.java b/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/PrivateArticleFragment.java index 62eefdd..f57d6ed 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/PrivateArticleFragment.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/view/drawer/fragment/PrivateArticleFragment.java @@ -92,19 +92,15 @@ protected void initView() { mArticleDataList = new ArrayList<>(); //拖动Header的时候是否同时拖动内容(默认true) mSmartRefreshLayout.setEnableHeaderTranslationContent(false); - //关闭下拉刷新 + //关闭下拉刷新 上拉加载 mSmartRefreshLayout.setEnableRefresh(false); mSmartRefreshLayout.setEnableLoadMore(false); initRecyclerView(); //添加收藏网站监听 tvAddFavorites.setOnClickListener(this); mFabAdd.setOnClickListener(this); - setSmartRefreshLayoutListener(); } - private void setSmartRefreshLayoutListener() { - - } private void initRecyclerView() { mRecyclerView.setHasFixedSize(true); @@ -150,10 +146,14 @@ protected void initEventAndData() { } @Override - public void showPrivateArticleData(List articleDataList) { - mArticleDataList.clear(); - mArticleDataList.addAll(articleDataList); - mAdapter.replaceData(mArticleDataList); + public void showPrivateArticleData(boolean isLoadMore,List articleDataList) { + if(isLoadMore){ + mAdapter.addData(articleDataList); + }else { + mArticleDataList.clear(); + mArticleDataList.addAll(articleDataList); + mAdapter.replaceData(mArticleDataList); + } } @@ -187,4 +187,12 @@ public void updateDate() { mPresenter.getPrivateArticleData(); } } + + public void loadDate() { + if(Constants.SQUARE_USER_TYPE.equals(mType)){ + mPresenter.getUserShareArticlesMoreData(mUserId); + }else { + mPresenter.getPrivateArticleMoreData(); + } + } } diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/view/main/UserCenterActivity.java b/app/src/main/java/mao/com/mao_wanandroid_client/view/main/UserCenterActivity.java index c0cefd0..9b9ec77 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/view/main/UserCenterActivity.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/view/main/UserCenterActivity.java @@ -121,8 +121,8 @@ protected void initEventAndData() { @Override public void showCoinAndRank(RankData rankData) { - tvNickName.setText(rankData.getUsername()); - tvTbNickName.setText(rankData.getUsername()); + tvNickName.setText(Constants.SQUARE_USER_TYPE.equals(pageType) ? rankData.getUsername():mPresenter.getLoginUserName()); + tvTbNickName.setText(Constants.SQUARE_USER_TYPE.equals(pageType) ? rankData.getUsername():mPresenter.getLoginUserName()); tvUserCenterCoin.setText("积分:"+rankData.getCoinCount()); tvUserCenterRank.setText("lv "+ToolsUtils.getRank(rankData.getCoinCount())); } @@ -131,20 +131,24 @@ private void refreshListener() { mSmartRefreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){ @Override public void onRefresh(@NonNull RefreshLayout refreshLayout) { - refreshLayout.finishRefresh(3000); + refreshLayout.finishRefresh(2000); if(Constants.SQUARE_USER_TYPE.equals(pageType)){ mPresenter.getUserShareArticlesData(userId,1); }else { mPresenter.getCoinAndRank(); - mAdapter.notifyDataSetChanged(); ToolsUtils.setIndicatorWidth(mCollectionTab,getResources().getDimensionPixelSize(R.dimen.dp_30)); } + mAdapter.setType(Constants.REFRESH_TYPE); + mAdapter.notifyDataSetChanged(); } @Override public void onLoadMore(@NonNull RefreshLayout refreshLayout) { refreshLayout.finishLoadMore(2000); + mAdapter.setType(Constants.LOAD_MORE_TYPE); + mAdapter.notifyDataSetChanged(); + ToolsUtils.setIndicatorWidth(mCollectionTab,getResources().getDimensionPixelSize(R.dimen.dp_30)); } //处理头部下拉刷新 @Override diff --git a/app/src/main/java/mao/com/mao_wanandroid_client/view/main/adapter/HomeTabPageAdapter.java b/app/src/main/java/mao/com/mao_wanandroid_client/view/main/adapter/HomeTabPageAdapter.java index f2f39f2..52e6f52 100644 --- a/app/src/main/java/mao/com/mao_wanandroid_client/view/main/adapter/HomeTabPageAdapter.java +++ b/app/src/main/java/mao/com/mao_wanandroid_client/view/main/adapter/HomeTabPageAdapter.java @@ -9,6 +9,7 @@ import java.util.List; +import mao.com.mao_wanandroid_client.application.Constants; import mao.com.mao_wanandroid_client.view.drawer.fragment.CollectionFragment; import mao.com.mao_wanandroid_client.view.drawer.fragment.CollectionWebFragment; import mao.com.mao_wanandroid_client.view.drawer.fragment.PrivateArticleFragment; @@ -23,6 +24,18 @@ public class HomeTabPageAdapter extends FragmentPagerAdapter { List mTitle; List mFragments; + + + private String type; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + public HomeTabPageAdapter(FragmentManager fm, List titles, List fragments) { super(fm); this.mTitle = titles; @@ -51,6 +64,8 @@ public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Obj //super.destroyItem(container,position,object); } + + /** * CollectionFragment CollectionWebFragment 收藏界面做处理,方便个人中心下拉刷新 * @param object @@ -59,11 +74,29 @@ public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Obj @Override public int getItemPosition(@NonNull Object object) { if(object instanceof CollectionFragment){ - ((CollectionFragment) object).updateDate(); + if(Constants.REFRESH_TYPE.equals(type)){ + ((CollectionFragment) object).updateDate(); + }else if(Constants.LOAD_MORE_TYPE.equals(type)){ + ((CollectionFragment) object).loadDate(); + }else { + return super.getItemPosition(object); + } }else if(object instanceof CollectionWebFragment){ - ((CollectionWebFragment) object).updateDate(); + if(Constants.REFRESH_TYPE.equals(type)){ + ((CollectionWebFragment) object).updateDate(); + }else if(Constants.LOAD_MORE_TYPE.equals(type)){ + ((CollectionWebFragment) object).loadDate(); + }else { + return super.getItemPosition(object); + } }else if(object instanceof PrivateArticleFragment){ - ((PrivateArticleFragment) object).updateDate(); + if(Constants.REFRESH_TYPE.equals(type)){ + ((PrivateArticleFragment) object).updateDate(); + }else if(Constants.LOAD_MORE_TYPE.equals(type)){ + ((PrivateArticleFragment) object).loadDate(); + }else { + return super.getItemPosition(object); + } } return super.getItemPosition(object); } diff --git a/app/src/main/res/layout/activity_user_center_layout.xml b/app/src/main/res/layout/activity_user_center_layout.xml index 49cf945..9b31c89 100644 --- a/app/src/main/res/layout/activity_user_center_layout.xml +++ b/app/src/main/res/layout/activity_user_center_layout.xml @@ -83,6 +83,9 @@ > +