15
15
import android .graphics .Color ;
16
16
import android .os .Build ;
17
17
import android .os .Bundle ;
18
+ import android .util .Log ;
19
+
18
20
import androidx .core .app .NotificationCompat ;
19
21
20
22
import com .facebook .react .bridge .ReactApplicationContext ;
21
23
22
24
import java .util .List ;
23
25
24
26
import static android .content .Context .ACTIVITY_SERVICE ;
25
- import static com .hoxfon .react .RNTwilioVoice .Constants .ACTION_HANGUP_CALL ;
26
- import static com .hoxfon .react .RNTwilioVoice .Constants .ACTION_INCOMING_CALL ;
27
- import static com .hoxfon .react .RNTwilioVoice .Constants .ACTION_MISSED_CALL ;
28
- import static com .hoxfon .react .RNTwilioVoice .Constants .INCOMING_CALL_NOTIFICATION_ID ;
29
- import static com .hoxfon .react .RNTwilioVoice .Constants .CALL_SID_KEY ;
30
- import static com .hoxfon .react .RNTwilioVoice .Constants .MISSED_CALLS_GROUP ;
31
- import static com .hoxfon .react .RNTwilioVoice .Constants .MISSED_CALLS_NOTIFICATION_ID ;
32
- import static com .hoxfon .react .RNTwilioVoice .Constants .HANGUP_NOTIFICATION_ID ;
33
- import static com .hoxfon .react .RNTwilioVoice .Constants .PREFERENCE_KEY ;
34
- import static com .hoxfon .react .RNTwilioVoice .Constants .ACTION_CLEAR_MISSED_CALLS_COUNT ;
35
- import static com .hoxfon .react .RNTwilioVoice .Constants .CLEAR_MISSED_CALLS_NOTIFICATION_ID ;
27
+
28
+ import static com .hoxfon .react .RNTwilioVoice .TwilioVoiceModule .TAG ;
36
29
37
30
public class CallNotificationManager {
38
31
@@ -73,12 +66,15 @@ public static Class getMainActivityClass(Context context) {
73
66
}
74
67
75
68
public void createMissedCallNotification (ReactApplicationContext context , String callSid , String callFrom ) {
76
- SharedPreferences sharedPref = context .getSharedPreferences (PREFERENCE_KEY , Context .MODE_PRIVATE );
69
+ if (BuildConfig .DEBUG ) {
70
+ Log .d (TAG , "createMissedCallNotification()" );
71
+ }
72
+ SharedPreferences sharedPref = context .getSharedPreferences (Constants .PREFERENCE_KEY , Context .MODE_PRIVATE );
77
73
SharedPreferences .Editor sharedPrefEditor = sharedPref .edit ();
78
74
79
75
Intent intent = new Intent (context , getMainActivityClass (context ));
80
- intent .setAction (ACTION_MISSED_CALL )
81
- .putExtra (INCOMING_CALL_NOTIFICATION_ID , MISSED_CALLS_NOTIFICATION_ID )
76
+ intent .setAction (Constants . ACTION_MISSED_CALL )
77
+ .putExtra (Constants . INCOMING_CALL_NOTIFICATION_ID , Constants . MISSED_CALLS_NOTIFICATION_ID )
82
78
.addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
83
79
84
80
PendingIntent pendingIntent = PendingIntent .getActivity (
@@ -91,24 +87,24 @@ public void createMissedCallNotification(ReactApplicationContext context, String
91
87
PendingIntent clearMissedCallsCountPendingIntent = PendingIntent .getBroadcast (
92
88
context ,
93
89
0 ,
94
- new Intent (ACTION_CLEAR_MISSED_CALLS_COUNT )
95
- .putExtra (INCOMING_CALL_NOTIFICATION_ID , CLEAR_MISSED_CALLS_NOTIFICATION_ID ),
90
+ new Intent (Constants . ACTION_CLEAR_MISSED_CALLS_COUNT )
91
+ .putExtra (Constants . INCOMING_CALL_NOTIFICATION_ID , Constants . CLEAR_MISSED_CALLS_NOTIFICATION_ID ),
96
92
0
97
93
);
98
94
/*
99
95
* Pass the notification id and call sid to use as an identifier to open the notification
100
96
*/
101
97
Bundle extras = new Bundle ();
102
- extras .putInt (INCOMING_CALL_NOTIFICATION_ID , MISSED_CALLS_NOTIFICATION_ID );
103
- extras .putString (CALL_SID_KEY , callSid );
98
+ extras .putInt (Constants . INCOMING_CALL_NOTIFICATION_ID , Constants . MISSED_CALLS_NOTIFICATION_ID );
99
+ extras .putString (Constants . CALL_SID_KEY , callSid );
104
100
105
101
/*
106
102
* Create the notification shown in the notification drawer
107
103
*/
108
104
String title = context .getString (R .string .call_missed_title );
109
105
NotificationCompat .Builder notification =
110
106
new NotificationCompat .Builder (context , VOICE_CHANNEL )
111
- .setGroup (MISSED_CALLS_GROUP )
107
+ .setGroup (Constants . MISSED_CALLS_GROUP )
112
108
.setGroupSummary (true )
113
109
.setPriority (NotificationCompat .PRIORITY_DEFAULT )
114
110
.setVisibility (NotificationCompat .VISIBILITY_PUBLIC )
@@ -122,16 +118,16 @@ public void createMissedCallNotification(ReactApplicationContext context, String
122
118
.setDeleteIntent (clearMissedCallsCountPendingIntent )
123
119
.setContentIntent (pendingIntent );
124
120
125
- int missedCalls = sharedPref .getInt (MISSED_CALLS_GROUP , 0 );
121
+ int missedCalls = sharedPref .getInt (Constants . MISSED_CALLS_GROUP , 0 );
126
122
missedCalls ++;
127
123
if (missedCalls == 1 ) {
128
124
inboxStyle = new NotificationCompat .InboxStyle ();
129
125
inboxStyle .setBigContentTitle (title );
130
126
} else {
131
- inboxStyle .setBigContentTitle (String .valueOf (missedCalls ) + context .getString (R .string .call_missed_title_plural ));
127
+ inboxStyle .setBigContentTitle (String .valueOf (missedCalls ) + " " + context .getString (R .string .call_missed_title_plural ));
132
128
}
133
- inboxStyle .addLine (context .getString (R .string .call_missed_more ) +callFrom );
134
- sharedPrefEditor .putInt (MISSED_CALLS_GROUP , missedCalls );
129
+ inboxStyle .addLine (context .getString (R .string .call_missed_more ) + " " + callFrom );
130
+ sharedPrefEditor .putInt (Constants . MISSED_CALLS_GROUP , missedCalls );
135
131
sharedPrefEditor .commit ();
136
132
137
133
notification .setStyle (inboxStyle );
@@ -146,13 +142,13 @@ public void createMissedCallNotification(ReactApplicationContext context, String
146
142
}
147
143
148
144
NotificationManager notificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
149
- notificationManager .notify (MISSED_CALLS_NOTIFICATION_ID , notification .build ());
145
+ notificationManager .notify (Constants . MISSED_CALLS_NOTIFICATION_ID , notification .build ());
150
146
}
151
147
152
148
public void createHangupNotification (ReactApplicationContext context , String callSid , String caller ) {
153
149
Intent intent = new Intent (context , getMainActivityClass (context ));
154
- intent .setAction (ACTION_INCOMING_CALL )
155
- .putExtra (INCOMING_CALL_NOTIFICATION_ID , HANGUP_NOTIFICATION_ID )
150
+ intent .setAction (Constants . ACTION_OPEN_CALL_IN_PROGRESS )
151
+ .putExtra (Constants . INCOMING_CALL_NOTIFICATION_ID , Constants . HANGUP_NOTIFICATION_ID )
156
152
.addFlags (Intent .FLAG_ACTIVITY_CLEAR_TOP );
157
153
158
154
PendingIntent pendingIntent = PendingIntent .getActivity (
@@ -165,21 +161,21 @@ public void createHangupNotification(ReactApplicationContext context, String cal
165
161
PendingIntent hangupPendingIntent = PendingIntent .getBroadcast (
166
162
context ,
167
163
0 ,
168
- new Intent (ACTION_HANGUP_CALL )
169
- .putExtra (INCOMING_CALL_NOTIFICATION_ID , HANGUP_NOTIFICATION_ID ),
164
+ new Intent (Constants . ACTION_HANGUP_CALL )
165
+ .putExtra (Constants . INCOMING_CALL_NOTIFICATION_ID , Constants . HANGUP_NOTIFICATION_ID ),
170
166
PendingIntent .FLAG_UPDATE_CURRENT
171
167
);
172
168
173
169
Bundle extras = new Bundle ();
174
- extras .putInt (INCOMING_CALL_NOTIFICATION_ID , HANGUP_NOTIFICATION_ID );
175
- extras .putString (CALL_SID_KEY , callSid );
170
+ extras .putInt (Constants . INCOMING_CALL_NOTIFICATION_ID , Constants . HANGUP_NOTIFICATION_ID );
171
+ extras .putString (Constants . CALL_SID_KEY , callSid );
176
172
177
173
Notification notification ;
178
174
NotificationManager notificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
179
175
String title = context .getString (R .string .call_in_progress );
180
176
String actionText = context .getString (R .string .hangup );
181
177
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .O ) {
182
- notification = new Notification .Builder (context , createChannel (title , notificationManager ))
178
+ notification = new NotificationCompat .Builder (context , createChannel (title , notificationManager ))
183
179
.setContentTitle (title )
184
180
.setContentText (caller )
185
181
.setSmallIcon (R .drawable .ic_call_white_24dp )
@@ -191,6 +187,7 @@ public void createHangupNotification(ReactApplicationContext context, String cal
191
187
.addAction (0 , actionText , hangupPendingIntent )
192
188
.build ();
193
189
} else {
190
+ // noinspection deprecation
194
191
notification = new NotificationCompat .Builder (context )
195
192
.setContentTitle (title )
196
193
.setContentText (caller )
@@ -205,7 +202,7 @@ public void createHangupNotification(ReactApplicationContext context, String cal
205
202
.addAction (0 , actionText , hangupPendingIntent )
206
203
.build ();
207
204
}
208
- notificationManager .notify (HANGUP_NOTIFICATION_ID , notification );
205
+ notificationManager .notify (Constants . HANGUP_NOTIFICATION_ID , notification );
209
206
}
210
207
211
208
@ TargetApi (Build .VERSION_CODES .O )
@@ -221,6 +218,6 @@ private String createChannel(String channelName, NotificationManager notificatio
221
218
222
219
public void removeHangupNotification (ReactApplicationContext context ) {
223
220
NotificationManager notificationManager = (NotificationManager ) context .getSystemService (Context .NOTIFICATION_SERVICE );
224
- notificationManager .cancel (HANGUP_NOTIFICATION_ID );
221
+ notificationManager .cancel (Constants . HANGUP_NOTIFICATION_ID );
225
222
}
226
223
}
0 commit comments