MessageManager.java
2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.shunzhi.parent.manager;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.Observer;
import com.netease.nimlib.sdk.auth.AuthService;
import com.netease.nimlib.sdk.auth.LoginInfo;
import com.netease.nimlib.sdk.msg.MsgServiceObserve;
import com.netease.nimlib.sdk.msg.model.CustomNotification;
import com.netease.nimlib.sdk.msg.model.IMMessage;
import java.util.List;
/**
* Created by 10501 on 2018/3/17.
*/
public class MessageManager {
private static class InstanceHolder {
static final MessageManager instance = new MessageManager();
}
public MessageManager getInstance() {
return InstanceHolder.instance;
}
private Observer<List<IMMessage>> messageObserver = new Observer<List<IMMessage>>() {
@Override
public void onEvent(List<IMMessage> imMessages) {
onMessageReceive(imMessages);
}
};
private Observer<CustomNotification> customNotificationObserver = new Observer<CustomNotification>() {
@Override
public void onEvent(CustomNotification customNotification) {
onCustomNotificationReceive(customNotification);
}
};
private MessageManager() {
NIMClient.getService(MsgServiceObserve.class).observeReceiveMessage(messageObserver, true);
NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(customNotificationObserver, true);
}
private void onMessageReceive(List<IMMessage> messageList) {
}
private void onCustomNotificationReceive(CustomNotification customnotification) {
}
public void login(String account, String password) {
NIMClient.getService(AuthService.class).login(new LoginInfo(account, password));
}
public void logout() {
NIMClient.getService(MsgServiceObserve.class).observeReceiveMessage(messageObserver, false);
NIMClient.getService(MsgServiceObserve.class).observeCustomNotification(customNotificationObserver, false);
NIMClient.getService(AuthService.class).logout();
}
}