Skip to content

Commit

Permalink
🎉 commit v1.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
maoqitian committed Oct 13, 2019
1 parent b2ba709 commit 64cc435
Show file tree
Hide file tree
Showing 11 changed files with 127 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
public interface PrivateArticleContract {

interface PrivateArticleView extends BaseView{
void showPrivateArticleData(List<HomeArticleData> articleDataList);
void showPrivateArticleData(boolean isLoadMore,List<HomeArticleData> articleDataList);
}


Expand All @@ -27,6 +27,10 @@ interface PrivateArticleFragmentPresenter extends AbstractBasePresenter<Private
void getUserShareArticlesData(int userId);

void getUserArticleDelete(Context context,int id);

void getUserShareArticlesMoreData(int userId);

void getPrivateArticleMoreData();
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import io.reactivex.Observable;
import io.reactivex.functions.Consumer;
import mao.com.mao_wanandroid_client.R;
import mao.com.mao_wanandroid_client.application.MyApplication;
import mao.com.mao_wanandroid_client.base.presenter.RxBasePresenter;
import mao.com.mao_wanandroid_client.compoent.RxBus;
import mao.com.mao_wanandroid_client.compoent.event.ShareArticleEvent;
Expand All @@ -31,6 +32,8 @@ public class PrivateArticlePresenter extends RxBasePresenter<PrivateArticleContr

private DataClient mDataClient;

private int curPage;

@Inject
public PrivateArticlePresenter(DataClient dataClient) {
super(dataClient);
Expand All @@ -46,7 +49,7 @@ public void attachView(PrivateArticleContract.PrivateArticleView view) {
public void accept(ShareArticleEvent shareArticleEvent) throws Exception {
if(shareArticleEvent.ismIsShareSuccess()){
//分享成功 刷新页面数据
getPrivateArticleDataList(0);
getPrivateArticleDataList(1,false);
mView.showErrorMsg(shareArticleEvent.getmMsg());
}else{
mView.showErrorMsg(shareArticleEvent.getmMsg());
Expand All @@ -55,21 +58,32 @@ public void accept(ShareArticleEvent shareArticleEvent) throws Exception {
}));
}

//个人分享数据
@Override
public void getPrivateArticleData() {

getPrivateArticleDataList(0);
getPrivateArticleDataList(1,false);
}
//获取更多个人分享数据
@Override
public void getPrivateArticleMoreData() {
getPrivateArticleDataList(curPage+1,true);
}

//广场用户信息获取
@Override
public void getUserShareArticlesData(int userId) {

getUserShareArticlesDataList(userId,1);

getUserShareArticlesDataList(userId,1,false);
}

//用户分享 获取更多数据
@Override
public void getUserShareArticlesMoreData(int userId) {
getUserShareArticlesDataList(userId,curPage+1,true);
}


//删除自己分享的文章
@Override
public void getUserArticleDelete(Context context,int id) {
Expand All @@ -79,7 +93,7 @@ public void getUserArticleDelete(Context context,int id) {
@Override
public void onSuccess(String result) {
//分享成功 刷新页面数据
getPrivateArticleDataList(0);
getPrivateArticleDataList(1,false);
mView.showErrorMsg(context.getString(R.string.delete_article_success_text));
}

Expand All @@ -92,13 +106,19 @@ public void onFailure(Throwable e, String errorMsg) {
}

//用户分享文章列表
private void getUserShareArticlesDataList(int userId, int pageNum) {
private void getUserShareArticlesDataList(int userId, int pageNum,boolean isLoadMore) {
Observable<ResponseBody<BaseMultipleData<RankData, BaseListData<HomeArticleData>>>> userShareArticlesData = mDataClient.getUserShareArticlesData(userId, pageNum);
userShareArticlesData.compose(RxSchedulers.observableIO2Main())
.subscribe(new BaseObserver<BaseMultipleData<RankData, BaseListData<HomeArticleData>>>() {
@Override
public void onSuccess(BaseMultipleData<RankData, BaseListData<HomeArticleData>> 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
Expand All @@ -110,13 +130,19 @@ public void onFailure(Throwable e, String errorMsg) {
}

//个人分享文章列表
private void getPrivateArticleDataList(int pageNum) {
private void getPrivateArticleDataList(int pageNum,boolean isLoadMore) {
Observable<ResponseBody<BaseMultipleData<RankData, BaseListData<HomeArticleData>>>> privateShareArticlesData = mDataClient.getPrivateShareArticlesData(pageNum);
privateShareArticlesData.compose(RxSchedulers.observableIO2Main())
.subscribe(new BaseObserver<BaseMultipleData<RankData, BaseListData<HomeArticleData>>>() {
@Override
public void onSuccess(BaseMultipleData<RankData, BaseListData<HomeArticleData>> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,4 +263,9 @@ public void updateDate() {
//刷新数据
mPresenter.getCollectListData();
}

public void loadDate() {
//加载更多
mPresenter.getLoadCollectListData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -249,4 +249,7 @@ public void onClick(View v) {
public void updateDate() {
mPresenter.getCollectWebData();
}

public void loadDate() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -150,10 +146,14 @@ protected void initEventAndData() {
}

@Override
public void showPrivateArticleData(List<HomeArticleData> articleDataList) {
mArticleDataList.clear();
mArticleDataList.addAll(articleDataList);
mAdapter.replaceData(mArticleDataList);
public void showPrivateArticleData(boolean isLoadMore,List<HomeArticleData> articleDataList) {
if(isLoadMore){
mAdapter.addData(articleDataList);
}else {
mArticleDataList.clear();
mArticleDataList.addAll(articleDataList);
mAdapter.replaceData(mArticleDataList);
}

}

Expand Down Expand Up @@ -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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,6 +24,18 @@ public class HomeTabPageAdapter extends FragmentPagerAdapter {
List<String> mTitle;
List<Fragment> mFragments;



private String type;

public String getType() {
return type;
}

public void setType(String type) {
this.type = type;
}

public HomeTabPageAdapter(FragmentManager fm, List<String> titles, List<Fragment> fragments) {
super(fm);
this.mTitle = titles;
Expand Down Expand Up @@ -51,6 +64,8 @@ public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Obj
//super.destroyItem(container,position,object);
}



/**
* CollectionFragment CollectionWebFragment 收藏界面做处理,方便个人中心下拉刷新
* @param object
Expand All @@ -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);
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/layout/activity_user_center_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@
>
</android.support.v4.view.ViewPager>
</android.support.design.widget.CoordinatorLayout>
<com.scwang.smartrefresh.header.TaurusHeader
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.scwang.smartrefresh.layout.SmartRefreshLayout>

<android.support.v7.widget.Toolbar
Expand Down
4 changes: 2 additions & 2 deletions config.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ ext {
buildToolsVersion : "28.0.0",
minSdkVersion : 21,
targetSdkVersion : 28,
versionCode : 5,
versionName : "1.0.4",
versionCode : 6,
versionName : "1.0.5",
renderscriptTargetApi : 21
]

Expand Down

0 comments on commit 64cc435

Please sign in to comment.