4
4
import android .content .Intent ;
5
5
import android .net .Uri ;
6
6
import android .os .Build ;
7
+ import android .os .Handler ;
8
+ import android .os .Message ;
7
9
import android .provider .Settings ;
8
10
9
11
import androidx .annotation .NonNull ;
10
12
import androidx .annotation .Nullable ;
13
+
14
+ import com .zendesk .service .ZendeskCallback ;
11
15
import com .zopim .android .sdk .api .ZopimChat ;
12
16
import com .zopim .android .sdk .api .ZopimChatApi ;
17
+ import com .zopim .android .sdk .data .LivechatAgentsPath ;
18
+ import com .zopim .android .sdk .data .LivechatChatLogPath ;
19
+ import com .zopim .android .sdk .data .observers .ChatLogObserver ;
20
+ import com .zopim .android .sdk .model .ChatLog ;
21
+ import com .zopim .android .sdk .model .PushData ;
13
22
import com .zopim .android .sdk .model .VisitorInfo ;
14
23
import com .zopim .android .sdk .prechat .ZopimChatActivity ;
15
24
import com .zopim .android .sdk .util .AppInfo ;
16
25
import com .zopim .android .sdk .widget .ChatWidgetService ;
17
26
27
+ import java .util .HashMap ;
28
+ import java .util .LinkedHashMap ;
29
+ import java .util .Map ;
30
+
18
31
import androidx .annotation .RequiresApi ;
19
32
import io .flutter .Log ;
20
33
import io .flutter .plugin .common .MethodCall ;
34
+ import io .flutter .plugin .common .MethodChannel ;
21
35
import io .flutter .plugin .common .MethodChannel .MethodCallHandler ;
22
36
import io .flutter .plugin .common .MethodChannel .Result ;
23
37
24
38
public class MethodCallHandlerImpl implements MethodCallHandler {
25
39
26
40
@ Nullable
27
41
private Activity activity ;
42
+ int initCount = 0 ;
43
+ private MethodChannel methodCallHandler ;
44
+
45
+ Handler mhandler =new Handler (){
46
+ @ Override
47
+ public void dispatchMessage (Message msg ) {
48
+ methodCallHandler .invokeMethod ("UnreadListener" ,msg .what );
49
+ }
50
+ };
28
51
52
+ void setMethodCall (MethodChannel methodCallHandler ){
53
+ this .methodCallHandler =methodCallHandler ;
54
+ }
29
55
void setActivity (@ Nullable Activity activity ) {
30
56
this .activity = activity ;
31
57
}
@@ -68,6 +94,7 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
68
94
}
69
95
}
70
96
97
+
71
98
private void closeChatWidget (Result result ) {
72
99
Log .d ("closeChatWidget" ,"closeChatWidget" );
73
100
ChatWidgetService .stopService (activity );
@@ -86,6 +113,11 @@ private void handleInit(MethodCall call, Result result) {
86
113
result .success (true );
87
114
}
88
115
116
+ public void getInitCountMessage (){
117
+ initCount =LivechatChatLogPath .getInstance ().countMessages (new ChatLog .Type []{ChatLog .Type .CHAT_MSG_AGENT });
118
+ Log .d ("onActivity" ,"initCount==" +initCount );
119
+ }
120
+
89
121
90
122
private void handleSetVisitorInfo (MethodCall call , Result result ) {
91
123
VisitorInfo .Builder builder = new VisitorInfo .Builder ();
@@ -112,6 +144,7 @@ private void handleSetVisitorInfo(MethodCall call, Result result) {
112
144
}
113
145
}
114
146
ZopimChat .setVisitorInfo (builder .build ());
147
+
115
148
result .success (true );
116
149
}
117
150
@@ -126,7 +159,7 @@ private void handleSetToken(MethodCall call, Result result) {
126
159
}
127
160
128
161
private void handleStartChat (MethodCall call , Result result ) {
129
- Log . d ( "handleStartChat" , "handleStartChat activity=" +( activity == null ) );
162
+ ZopimChatApi . getDataSource (). addChatLogObserver ( mChannelLogObserver );
130
163
if (activity != null ) {
131
164
Intent intent = new Intent (activity , ZopimChatActivity .class );
132
165
activity .startActivity (intent );
@@ -181,4 +214,17 @@ private void checkSystemAlertPermission(Result result) {
181
214
}
182
215
}
183
216
217
+ ChatLogObserver mChannelLogObserver = new ChatLogObserver () {
218
+ public void update (LinkedHashMap <String , ChatLog > chatLog ) {
219
+ if (!ZendeskPlugin .isFore ){
220
+ int currentCount = LivechatChatLogPath .getInstance ().countMessages (new ChatLog .Type []{ChatLog .Type .CHAT_MSG_AGENT });
221
+ if (initCount ==0 ){
222
+ initCount =LivechatChatLogPath .getInstance ().countMessages (new ChatLog .Type []{ChatLog .Type .CHAT_MSG_AGENT });
223
+ }
224
+ final int unread = currentCount -initCount ;
225
+ mhandler .sendEmptyMessage (unread );
226
+ }
227
+ }
228
+ };
229
+
184
230
}
0 commit comments