package com.community.easeim.section.chat;
import android.app.Activity;
import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import com.community.easeim.DemoApplication;
import com.community.easeim.DemoHelper;
import com.community.easeim.MainActivity;
import com.community.easeim.R;
import com.community.easeim.common.constant.DemoConstant;
import com.community.easeim.common.db.DemoDbHelper;
import com.community.easeim.common.db.dao.EmUserDao;
import com.community.easeim.common.db.entity.EmUserEntity;
import com.community.easeim.common.db.entity.InviteMessageStatus;
import com.community.easeim.common.interfaceOrImplement.ResultCallBack;
import com.community.easeim.common.leancloud.GroundManager;
import com.community.easeim.common.leancloud.LeanCloudManager;
import com.community.easeim.common.livedatas.LiveDataBus;
import com.community.easeim.common.manager.AppManager;
import com.community.easeim.common.manager.PushAndMessageHelper;
import com.community.easeim.common.repositories.EMContactManagerRepository;
import com.community.easeim.common.repositories.EMGroupManagerRepository;
import com.community.easeim.common.repositories.EMPushManagerRepository;
import com.community.easeim.imkit.constants.EaseConstant;
import com.community.easeim.imkit.domain.EaseUser;
import com.community.easeim.imkit.interfaces.EaseGroupListener;
import com.community.easeim.imkit.manager.EaseAtMessageHelper;
import com.community.easeim.imkit.manager.EaseChatPresenter;
import com.community.easeim.imkit.manager.EaseSystemMsgManager;
import com.community.easeim.imkit.model.EaseEvent;
import com.community.easeim.section.chat.activity.ChatActivity;
import com.community.easeim.section.dialog.CustomDialogFragment;
import com.community.easeim.section.ground.bean.GroundGroupBean;
import com.community.easeim.section.group.GroupHelper;
import com.community.easeim.section.home.dialog.CustomDialog;
import com.community.easeim.section.voice.VoiceTalkActivity;
import com.community.easeim.section.voice.bean.ChannelCmd;
import com.community.easeim.voice.CmdMediaCtrl;
import com.google.gson.Gson;
import com.hyphenate.EMChatRoomChangeListener;
import com.hyphenate.EMConnectionListener;
import com.hyphenate.EMContactListener;
import com.hyphenate.EMConversationListener;
import com.hyphenate.EMError;
import com.hyphenate.EMMultiDeviceListener;
import com.hyphenate.EMValueCallBack;
import com.hyphenate.chat.EMClient;
import com.hyphenate.chat.EMCmdMessageBody;
import com.hyphenate.chat.EMConversation;
import com.hyphenate.chat.EMGroup;
import com.hyphenate.chat.EMMessage;
import com.hyphenate.chat.EMMucSharedFile;
import com.hyphenate.chat.EMTextMessageBody;
import com.hyphenate.chat.adapter.EMAChatRoomManagerListener;
import com.hyphenate.exceptions.HyphenateException;
import com.hyphenate.util.EMLog;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.UUID;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
* 主要用于chat过程中的全局监听,并对相应的事件进行处理
* {@link #init()}方法建议在登录成功以后进行调用
*/
public class ChatPresenter extends EaseChatPresenter {
private static final String TAG = ChatPresenter.class.getSimpleName();
private static final int HANDLER_SHOW_TOAST = 0;
private static ChatPresenter instance;
private LiveDataBus messageChangeLiveData;
private boolean isGroupsSyncedWithServer = false;
private boolean isContactsSyncedWithServer = false;
private boolean isBlackListSyncedWithServer = false;
private boolean isPushConfigsWithServer = false;
private Context appContext;
protected Handler handler;
Queue<String> msgQueue = new ConcurrentLinkedQueue<>();
private ChatPresenter() {
appContext = DemoApplication.getInstance();
initHandler(appContext.getMainLooper());
messageChangeLiveData = LiveDataBus.get();
//添加网络连接状态监听
DemoHelper.getInstance().getEMClient().addConnectionListener(new ChatConnectionListener());
//添加多端登录监听
DemoHelper.getInstance().getEMClient().addMultiDeviceListener(new ChatMultiDeviceListener());
//添加群组监听
DemoHelper.getInstance().getGroupManager().addGroupChangeListener(new ChatGroupListener());
//添加联系人监听
DemoHelper.getInstance().getContactManager().setContactListener(new ChatContactListener());
//添加聊天室监听
DemoHelper.getInstance().getChatroomManager().addChatRoomChangeListener(new ChatRoomListener());
//添加对会话的监听(监听已读回执)
DemoHelper.getInstance().getChatManager().addConversationListener(new ChatConversationListener());
}
public static ChatPresenter getInstance() {
if (instance == null) {
synchronized (ChatPresenter.class) {
if (instance == null) {
instance = new ChatPresenter();
}
}
}
return instance;
}
/**
* 将需要登录成功进入MainActivity中初始化的逻辑,放到此处进行处理
*/
public void init() {
}
public void initHandler(Looper looper) {
handler = new Handler(looper) {
@Override
public void handleMessage(Message msg) {
Object obj = msg.obj;
switch (msg.what) {
case HANDLER_SHOW_TOAST:
if (obj instanceof String) {
String str = (String) obj;
//ToastUtils.showToast(str);
Toast.makeText(appContext, str, Toast.LENGTH_SHORT).show();
}
break;
}
}
};
while (!msgQueue.isEmpty()) {
showToast(msgQueue.remove());
}
}
void showToast(@StringRes int mesId) {
showToast(context.getString(mesId));
}
void showToast(final String message) {
Log.d(TAG, "receive invitation to join the group:" + message);
if (handler != null) {
Message msg = Message.obtain(handler, HANDLER_SHOW_TOAST, message);
handler.sendMessage(msg);
} else {
msgQueue.add(message);
}
}
@Override
public void onMessageReceived(List<EMMessage> messages) {
super.onMessageReceived(messages);
EaseEvent event = EaseEvent.create(DemoConstant.MESSAGE_CHANGE_RECEIVE, EaseEvent.TYPE.MESSAGE);
messageChangeLiveData.with(DemoConstant.MESSAGE_CHANGE_CHANGE).postValue(event);
for (EMMessage message : messages) {
EMLog.d(TAG, "onMessageReceived id : " + message.getMsgId());
EMLog.d(TAG, "onMessageReceived: " + message.getType());
// 如果设置群组离线消息免打扰,则不进行消息通知
List<String> disabledIds = DemoHelper.getInstance().getPushManager().getNoPushGroups();
if (disabledIds != null && disabledIds.contains(message.conversationId())) {
return;
}
// in background, do not refresh UI, notify it in notification bar
if (!DemoApplication.getInstance().getLifecycleCallbacks().isFront()) {
getNotifier().notify(message);
}
//notify new message
getNotifier().vibrateAndPlayTone(message);
}
}
/**
* 判断是否已经启动�
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
easemob_supercommunity-android studio开发app项目 (1705个子文件)
oppo_push_v2.1.0.aar 31KB
gradlew.bat 3KB
hyphenate_root.crt.der 896B
icon_022.gif 85KB
icon_018.gif 77KB
icon_007.gif 67KB
icon_027.gif 62KB
icon_020.gif 56KB
icon_019.gif 46KB
icon_012.gif 44KB
icon_021.gif 43KB
icon_040.gif 42KB
icon_010.gif 42KB
icon_013.gif 26KB
icon_030.gif 26KB
icon_029.gif 23KB
icon_035.gif 21KB
icon_002.gif 16KB
icon_024.gif 11KB
.gitignore 518B
build.gradle 7KB
build.gradle 3KB
settings.gradle 658B
gradlew 6KB
BaiduLBS_Android.jar 1.3MB
mi_push_v3.6.12.jar 685KB
pinyin4j-2.5.0.jar 184KB
vivo_push_v2.3.1.jar 177KB
gradle-wrapper.jar 58KB
ChatPresenter.java 69KB
EMGroupManagerRepository.java 45KB
GroundDetailFragment.java 45KB
EaseChatLayout.java 38KB
DemoHelper.java 38KB
EaseCommonUtils.java 35KB
EaseChatMessageListLayout.java 33KB
EasyVideoPlayer.java 33KB
EMContactManagerRepository.java 28KB
PhotoViewAttacher.java 28KB
ChatActivity.java 27KB
EaseConversationListLayout.java 25KB
DemoModel.java 24KB
EaseChatRow.java 23KB
ChatFragment.java 22KB
EMChatRoomManagerRepository.java 22KB
MainActivity.java 22KB
OkHttpUtil.java 22KB
GroupMemberAuthorityActivity.java 20KB
VoiceTalkActivity.java 20KB
EaseContactListLayout.java 20KB
PreferenceManager.java 19KB
TimePickerDialogFragment.java 18KB
RecorderVideoActivity.java 18KB
ImageCache.java 18KB
ConferenceInviteActivity.java 18KB
GroupDetailActivity.java 17KB
PermissionsManager.java 17KB
BaseActivity.java 17KB
SelectUserCardActivity.java 17KB
ImageWorker.java 17KB
EaseCompat.java 16KB
GroundFragment.java 16KB
EaseNotifier.java 15KB
MembersListActivity.java 15KB
SearchGroundActivity.java 15KB
GroundManager.java 15KB
PushAndMessageHelper.java 14KB
EaseChatFragment.java 14KB
HomeFragment.java 13KB
FloatWindowManager.java 13KB
CustomDialogFragment.java 13KB
EaseTitleBar.java 13KB
DemoDialogFragment.java 13KB
UserDetailActivity.java 13KB
NewGroupActivity.java 13KB
EaseChatExtendMenu.java 13KB
LoginFragment.java 12KB
EaseChatPrimaryMenu.java 12KB
EaseRecyclerView.java 12KB
EaseHandleMessagePresenterImpl.java 12KB
EaseImageView.java 12KB
ContactDetailActivity.java 12KB
EaseImageUtils.java 12KB
ImManager.java 12KB
ImageGridFragment.java 12KB
GroundModifiyActivity.java 11KB
ChatRoomMemberAuthorityActivity.java 11KB
NewFriendsViewModel.java 11KB
ServerSetFragment.java 11KB
ToastUtils.java 11KB
PagingScrollHelper.java 11KB
ContactListFragment.java 11KB
EMChatManagerRepository.java 11KB
EaseBaseRecyclerViewAdapter.java 11KB
HttpLoggingInterceptor.java 11KB
EaseEmojiconPagerView.java 11KB
AppKeyManageActivity.java 10KB
EaseRoundImageView.java 10KB
EasePopupWindowHelper.java 10KB
EaseChatInputMenu.java 10KB
共 1705 条
- 1
- 2
- 3
- 4
- 5
- 6
- 18
资源评论
lly202406
- 粉丝: 2519
- 资源: 5428
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- AxTools CodeSMART 2013 for vb6
- Python 实现基于BP神经网络的时间序列预测-递归预测未来(多指标评价)(含完整的程序和代码详解)
- 毕业设计基于Python的知识图谱和图神经网络的电影推荐系统源码(高分毕设项目)
- 基于Python的知识图谱和图神经网络的电影推荐系统(完整高分毕业设计项目)
- C#程序设计入门与实例代码,基础学习代码入门实操
- 基于c++的图像处理,画线去畸变,接包裹入门代码
- Python基础学习-03逻辑分支语句、循环
- 基于微信小程序的点餐系统源码.zip
- 基于python tensorflow opencv图像处理入门程序代码
- EasyAdmin极简社区简约清爽社区论坛源码下载自适应手机端带后台带会员中心可发帖
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功