remove pluginListener dependency from UI listener
@@ -37,15 +37,7 @@ public class AlEventManager {
if (listenerMap == null) {
listenerMap = new HashMap<>();
}
- if (uiHandler == null) {
- uiHandler = new Handler(new Handler.Callback() {
- @Override
- public boolean handleMessage(Message msg) {
- handleState(msg);
- return false;
- }
- });
- }
+ initHandler();
if (!listenerMap.containsKey(id)) {
listenerMap.put(id, listener);
}
@@ -93,6 +85,19 @@ public class AlEventManager {
public void registerPluginEventListener(KmPluginEventListener kmPluginEventListener) {
this.kmPluginEventListener = kmPluginEventListener;
+ initHandler();
+ }
+
+ private void initHandler() {
+ if (uiHandler == null) {
+ uiHandler = new Handler(new Handler.Callback() {
+ @Override
+ public boolean handleMessage(Message msg) {
+ handleState(msg);
+ return false;
+ }
+ });
+ }
}
public void unregisterPluginEventListener() {
@@ -130,7 +135,7 @@ public class AlEventManager {
}
private void handleState(Message message) {
- if (message != null && listenerMap != null && !listenerMap.isEmpty()) {
+ if (message != null) {
Bundle bundle = message.getData();
AlMessageEvent messageEvent = null;
if (bundle != null) {
@@ -139,6 +144,12 @@ public class AlEventManager {
if (messageEvent == null) {
return;
}
+ if (kmPluginEventListener != null && AlMessageEvent.ActionType.MESSAGE_SYNC.equals(messageEvent.getAction())) {
+ sendOnConversationResolvedEvent(messageEvent.getMessage());
+ sendOnConversationRestartedEvent(messageEvent.getMessage());
+ }
+
+ if (listenerMap != null && !listenerMap.isEmpty()) {
for (ApplozicUIListener listener : listenerMap.values()) {
switch (messageEvent.getAction()) {
case AlMessageEvent.ActionType.MESSAGE_SENT:
@@ -146,8 +157,6 @@ public class AlEventManager {
break;
case AlMessageEvent.ActionType.MESSAGE_RECEIVED:
listener.onMessageReceived(messageEvent.getMessage());
- sendOnConversationResolvedEvent(messageEvent.getMessage());
- sendOnConversationRestartedEvent(messageEvent.getMessage());
break;
case AlMessageEvent.ActionType.MESSAGE_SYNC:
listener.onMessageSync(messageEvent.getMessage(), messageEvent.getMessageKey());
@@ -213,3 +222,4 @@ public class AlEventManager {
}
}
}
+}
