|
|
@ -1,12 +1,8 @@ |
|
|
|
package com.kanglai.push.ui.vm; |
|
|
|
package com.kanglai.push.ui.vm; |
|
|
|
|
|
|
|
|
|
|
|
import android.app.Activity; |
|
|
|
|
|
|
|
import android.app.Application; |
|
|
|
import android.app.Application; |
|
|
|
import android.content.Intent; |
|
|
|
|
|
|
|
import android.icu.text.SimpleDateFormat; |
|
|
|
import android.icu.text.SimpleDateFormat; |
|
|
|
import android.icu.util.Calendar; |
|
|
|
import android.icu.util.Calendar; |
|
|
|
import android.os.Handler; |
|
|
|
|
|
|
|
import android.os.Looper; |
|
|
|
|
|
|
|
import android.util.Pair; |
|
|
|
import android.util.Pair; |
|
|
|
import android.view.View; |
|
|
|
import android.view.View; |
|
|
|
|
|
|
|
|
|
|
@ -26,7 +22,6 @@ import com.dolphin.core.util.RxUtil; |
|
|
|
import com.dolphin.core.util.ToastUtil; |
|
|
|
import com.dolphin.core.util.ToastUtil; |
|
|
|
import com.kanglai.push.app.AppApplication; |
|
|
|
import com.kanglai.push.app.AppApplication; |
|
|
|
import com.kanglai.push.constant.CacheConstant; |
|
|
|
import com.kanglai.push.constant.CacheConstant; |
|
|
|
import com.kanglai.push.constant.CommonConstant; |
|
|
|
|
|
|
|
import com.kanglai.push.di.component.DaggerServiceComponent; |
|
|
|
import com.kanglai.push.di.component.DaggerServiceComponent; |
|
|
|
import com.kanglai.push.entity.LocalPushChatMsg; |
|
|
|
import com.kanglai.push.entity.LocalPushChatMsg; |
|
|
|
import com.kanglai.push.entity.MsgVo; |
|
|
|
import com.kanglai.push.entity.MsgVo; |
|
|
@ -35,7 +30,7 @@ import com.kanglai.push.entity.User; |
|
|
|
import com.kanglai.push.service.PushService; |
|
|
|
import com.kanglai.push.service.PushService; |
|
|
|
import com.kanglai.push.ui.activity.InstantActivity; |
|
|
|
import com.kanglai.push.ui.activity.InstantActivity; |
|
|
|
import com.kanglai.push.util.LocalPushChatMsgUtil; |
|
|
|
import com.kanglai.push.util.LocalPushChatMsgUtil; |
|
|
|
import com.luck.picture.lib.config.PictureConfig; |
|
|
|
import com.scwang.smart.refresh.layout.api.RefreshLayout; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Collections; |
|
|
@ -59,17 +54,10 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{ |
|
|
|
public User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); |
|
|
|
public User user = CacheDiskUtils.getInstance().getParcelable(CacheConstant.USER_INFO, User.CREATOR, new User()); |
|
|
|
public LocalPushChatMsg adverseData; // 对方用户基础信息
|
|
|
|
public LocalPushChatMsg adverseData; // 对方用户基础信息
|
|
|
|
|
|
|
|
|
|
|
|
public int size = 10; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int current = 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String cursor = ""; |
|
|
|
public String cursor = ""; |
|
|
|
|
|
|
|
|
|
|
|
public ArrayList<LocalPushChatMsg> localPushChatMsgs; // 本地缓存的列表数据
|
|
|
|
public ArrayList<LocalPushChatMsg> localPushChatMsgs; // 本地缓存的列表数据
|
|
|
|
|
|
|
|
|
|
|
|
/** 所有的记录数据 */ |
|
|
|
|
|
|
|
private ArrayList<PushChatMessage> requestList = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public InstantViewModel(@NonNull Application application) { |
|
|
|
public InstantViewModel(@NonNull Application application) { |
|
|
|
super(application); |
|
|
|
super(application); |
|
|
|
DaggerServiceComponent |
|
|
|
DaggerServiceComponent |
|
|
@ -159,101 +147,81 @@ public class InstantViewModel extends ToolbarViewModel<InstantActivity>{ |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
public void init() { |
|
|
|
public void initData(RefreshLayout refresh) { |
|
|
|
pushService.listFriendHistoryMessage( |
|
|
|
pushService.listFriendHistoryMessage( |
|
|
|
MapUtils.newHashMap( |
|
|
|
MapUtils.newHashMap( |
|
|
|
Pair.create("size", size), |
|
|
|
Pair.create("size", pageSize), |
|
|
|
Pair.create("current", current), |
|
|
|
Pair.create("alias", adverseData.getId()), |
|
|
|
Pair.create("alias", adverseData.getId()), |
|
|
|
Pair.create("userId", user.getId()) |
|
|
|
Pair.create("userId", user.getId()) |
|
|
|
)) |
|
|
|
)) |
|
|
|
.compose(RxUtil.schedulersTransformer()) |
|
|
|
.compose(RxUtil.schedulersTransformer()) |
|
|
|
.compose(RxUtil.exceptionTransformer()) |
|
|
|
.compose(RxUtil.exceptionTransformer()) |
|
|
|
.doOnSubscribe(this) |
|
|
|
.doOnSubscribe(this) |
|
|
|
.subscribe(new DisposableObserver<ResultResponse<Map<String, Object>>>() { |
|
|
|
.subscribe(new DisposableObserver<ResultResponse<Map<String, Object>>>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(ResultResponse<Map<String, Object>> R) { |
|
|
|
public void onNext(ResultResponse<Map<String, Object>> R) { |
|
|
|
if (R.getCode() == R.SUCCESS) { |
|
|
|
if (R.getCode() == R.SUCCESS ) { |
|
|
|
MsgVo msgVo = (MsgVo) R.getData(); |
|
|
|
MsgVo msgVo = (MsgVo) R.getData(); |
|
|
|
cursor = msgVo.getCursor(); |
|
|
|
cursor = msgVo.getCursor(); |
|
|
|
List<PushChatMessage> data = msgVo.getData(); |
|
|
|
List<PushChatMessage> data = msgVo.getData(); |
|
|
|
if (!CollectionUtils.isEmpty(data)) { |
|
|
|
if (CollectionUtils.isEmpty(data)) { // 暂无
|
|
|
|
Collections.reverse(data); |
|
|
|
return; |
|
|
|
mActivity.mAdapter.refresh(data); |
|
|
|
} |
|
|
|
} |
|
|
|
Collections.reverse(data); // 把顺序颠倒下方便排列
|
|
|
|
} else { |
|
|
|
requestList.addAll(data); |
|
|
|
refresh.finishRefresh(false); |
|
|
|
|
|
|
|
ToastUtil.showBottomWarn(R.getMsg()); |
|
|
|
}else ToastUtil.showBottomWarn(R.getMsg()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
|
|
|
ExceptionHandle.baseExceptionMsg(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onComplete() { |
|
|
|
|
|
|
|
if (requestList.size() > 0) mActivity.adapterInit(requestList); // 有新数据才做界面刷新
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onError(Throwable e) { |
|
|
|
|
|
|
|
refresh.finishRefresh(false); |
|
|
|
|
|
|
|
ExceptionHandle.baseExceptionMsg(e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onComplete() {} |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void loadMore() { // 加载更多数据
|
|
|
|
public void loadMore(RefreshLayout layout) { |
|
|
|
if (CollectionUtils.isEmpty(requestList)) { // 如果此时的列表为空 则重新初始化
|
|
|
|
|
|
|
|
init(); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pushService.listFriendHistoryMessage( |
|
|
|
pushService.listFriendHistoryMessage( |
|
|
|
MapUtils.newHashMap( |
|
|
|
MapUtils.newHashMap( |
|
|
|
Pair.create("size", size), |
|
|
|
Pair.create("size", pageSize), |
|
|
|
Pair.create("current", current + 1), |
|
|
|
Pair.create("current", pageCurrent += 1), |
|
|
|
Pair.create("alias", adverseData.getId()), |
|
|
|
Pair.create("alias", adverseData.getId()), |
|
|
|
Pair.create("userId", user.getId()) |
|
|
|
Pair.create("userId", user.getId()) |
|
|
|
)) |
|
|
|
)) |
|
|
|
.compose(RxUtil.schedulersTransformer()) |
|
|
|
.compose(RxUtil.schedulersTransformer()) |
|
|
|
.compose(RxUtil.exceptionTransformer()) |
|
|
|
.compose(RxUtil.exceptionTransformer()) |
|
|
|
.doOnSubscribe(this) |
|
|
|
.doOnSubscribe(this) |
|
|
|
.subscribe(new DisposableObserver<ResultResponse<Map<String, Object>>>() { |
|
|
|
.subscribe(new DisposableObserver<ResultResponse<Map<String, Object>>>() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onNext(ResultResponse<Map<String, Object>> R) { |
|
|
|
public void onNext(ResultResponse<Map<String, Object>> R) { |
|
|
|
if (R.getCode() == R.SUCCESS) { |
|
|
|
if (R.getCode() == R.SUCCESS) { |
|
|
|
MsgVo msgVo = (MsgVo) R.getData(); |
|
|
|
MsgVo msgVo = (MsgVo) R.getData(); |
|
|
|
cursor = msgVo.getCursor(); |
|
|
|
cursor = msgVo.getCursor(); |
|
|
|
List<PushChatMessage> data = msgVo.getData(); |
|
|
|
List<PushChatMessage> pushChatMessages = msgVo.getData(); |
|
|
|
|
|
|
|
if (CollectionUtils.isEmpty(pushChatMessages)) { |
|
|
|
if (CollectionUtils.isEmpty(data)) { |
|
|
|
ToastUtil.showBottomSuccess("数据加载完毕"); |
|
|
|
ToastUtil.showBottomSuccess("已加载全部数据"); |
|
|
|
mActivity.refreshLayout.setEnableRefresh(false); |
|
|
|
mActivity.refreshLayout.setEnableRefresh(false); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
Collections.reverse(pushChatMessages); |
|
|
|
Collections.reverse(data); |
|
|
|
mActivity.mAdapter.loadMore(msgVo.getData()); |
|
|
|
if (data.get(0).getId().equals(requestList.get(0).getId())){ |
|
|
|
if (mActivity.mAdapter.getItemCount() < R.getTotal()) { |
|
|
|
ToastUtil.showBottomSuccess("暂无更多"); |
|
|
|
layout.finishLoadMore(); |
|
|
|
mActivity.refreshLayout.setEnableRefresh(false); |
|
|
|
} else layout.finishLoadMoreWithNoMoreData(); |
|
|
|
return; |
|
|
|
} else ToastUtil.show(R.getMsg()); |
|
|
|
} |
|
|
|
} |
|
|
|
requestList.addAll(0, data); |
|
|
|
|
|
|
|
mActivity.mAdapter.loadHistory(data); |
|
|
|
|
|
|
|
current = current + 1; |
|
|
|
|
|
|
|
if (data.size() < size){ |
|
|
|
|
|
|
|
ToastUtil.showBottomSuccess("已加载全部聊天数据"); |
|
|
|
|
|
|
|
mActivity.refreshLayout.setEnableRefresh(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}else ToastUtil.showBottomWarn(R.getMsg()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onError(Throwable e) { |
|
|
|
public void onError(Throwable e) { |
|
|
|
mActivity.refreshLayout.finishRefresh(false); |
|
|
|
layout.finishLoadMore(false); |
|
|
|
ExceptionHandle.baseExceptionMsg(e); |
|
|
|
ExceptionHandle.baseExceptionMsg(e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onComplete() { |
|
|
|
public void onComplete() {} |
|
|
|
/** 完成刷新 */ |
|
|
|
}); |
|
|
|
mActivity.refreshLayout.finishRefresh(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|