Skip to content

Commit ac78b0d

Browse files
author
Arief Nur Putranto
committed
update code in chatUI for fix PN not working
1 parent 255d079 commit ac78b0d

File tree

3 files changed

+65
-61
lines changed

3 files changed

+65
-61
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@
3030
</intent-filter>
3131
</service>
3232

33+
<meta-data android:name="com.google.firebase.messaging.default_notification_icon" android:resource="@mipmap/ic_launcher" />
34+
35+
<meta-data
36+
android:name="com.google.firebase.messaging.default_notification_channel_id"
37+
android:value="com.qiscus.dragonfly"/>
38+
3339
<meta-data
3440
android:name="com.google.android.geo.API_KEY"
3541
android:value="@string/qiscus_key_google_apis_android"/>
Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1-
package com.qiscus.sdk.util;public class NotificationClickReceiver {
1+
package com.qiscus.sdk.util;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.widget.Toast;
7+
8+
import com.qiscus.sdk.chat.core.QiscusCore;
9+
import com.qiscus.sdk.chat.core.data.model.QiscusChatRoom;
10+
import com.qiscus.sdk.chat.core.data.model.QiscusComment;
11+
import com.qiscus.sdk.chat.core.data.remote.QiscusApi;
12+
import com.qiscus.sdk.ui.QiscusChatActivity;
13+
import com.qiscus.sdk.ui.QiscusGroupChatActivity;
14+
15+
import rx.android.schedulers.AndroidSchedulers;
16+
import rx.schedulers.Schedulers;
17+
18+
public class NotificationClickReceiver extends BroadcastReceiver {
19+
20+
@Override
21+
public void onReceive(Context context, Intent intent) {
22+
QiscusComment qiscusComment = intent.getParcelableExtra("data");
23+
QiscusApi.getInstance()
24+
.getChatRoom(qiscusComment.getRoomId())
25+
.subscribeOn(Schedulers.io())
26+
.observeOn(AndroidSchedulers.mainThread())
27+
.doOnNext(qiscusChatRoom -> QiscusCore.getDataStore().addOrUpdate(qiscusChatRoom))
28+
.map(qiscusChatRoom -> getChatRoomActivity(context, qiscusChatRoom))
29+
.subscribe(newIntent -> start(context, newIntent), throwable ->
30+
Toast.makeText(context, throwable.getLocalizedMessage(), Toast.LENGTH_SHORT).show());
31+
}
32+
33+
private Intent getChatRoomActivity(Context context, QiscusChatRoom qiscusChatRoom) {
34+
return qiscusChatRoom.isGroup() ? QiscusGroupChatActivity.generateIntent(context, qiscusChatRoom) :
35+
QiscusChatActivity.generateIntent(context, qiscusChatRoom);
36+
}
37+
38+
private void start(Context context, Intent newIntent) {
39+
context.startActivity(newIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK));
40+
}
241
}

chat/src/main/java/com/qiscus/sdk/util/QiscusPushNotificationUtil.java

Lines changed: 19 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.qiscus.nirmana.Nirmana;
4343
import com.qiscus.sdk.Qiscus;
4444
import com.qiscus.sdk.R;
45+
import com.qiscus.sdk.chat.core.QiscusCore;
4546
import com.qiscus.sdk.chat.core.data.local.QiscusCacheManager;
4647
import com.qiscus.sdk.chat.core.data.model.QiscusChatRoom;
4748
import com.qiscus.sdk.chat.core.data.model.QiscusComment;
@@ -215,10 +216,10 @@ private static void showPushNotification(Context context, QiscusComment comment)
215216
new QiscusPushNotificationMessage(comment.getId(), messageText);
216217
pushNotificationMessage.setRoomName(comment.getRoomName());
217218
pushNotificationMessage.setRoomAvatar(comment.getRoomAvatar());
218-
if (!QiscusCacheManager.getInstance()
219-
.addMessageNotifItem(pushNotificationMessage, comment.getRoomId())) {
220-
return;
221-
}
219+
// if (!QiscusCacheManager.getInstance()
220+
// .addMessageNotifItem(pushNotificationMessage, comment.getRoomId())) {
221+
// return;
222+
// }
222223

223224
if (Qiscus.getChatConfig().isEnableAvatarAsNotificationIcon()) {
224225
QiscusAndroidUtil.runOnUIThread(() -> loadAvatar(context, comment, pushNotificationMessage));
@@ -259,7 +260,13 @@ public void onLoadFailed(@Nullable Drawable errorDrawable) {
259260
private static void pushNotification(Context context, QiscusComment comment,
260261
QiscusPushNotificationMessage pushNotificationMessage, Bitmap largeIcon) {
261262

262-
String notificationChannelId = Qiscus.getApps().getPackageName() + ".qiscus.sdk.notification.channel";
263+
// if (QiscusCore.getDataStore().isContains(comment)) {
264+
// return;
265+
// }
266+
267+
QiscusCore.getDataStore().addOrUpdate(comment);
268+
269+
String notificationChannelId = QiscusCore.getApps().getPackageName() + ".qiscus.sdk.notification.channel";
263270
if (BuildVersionUtil.isOreoOrHigher()) {
264271
NotificationChannel notificationChannel =
265272
new NotificationChannel(notificationChannelId, "Chat", NotificationManager.IMPORTANCE_HIGH);
@@ -270,9 +277,8 @@ private static void pushNotification(Context context, QiscusComment comment,
270277
}
271278

272279
PendingIntent pendingIntent;
273-
Intent openIntent = new Intent(context, QiscusPushNotificationClickReceiver.class);
280+
Intent openIntent = new Intent(context, NotificationClickReceiver.class);
274281
openIntent.putExtra("data", comment);
275-
276282
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
277283
pendingIntent = PendingIntent.getBroadcast(context, QiscusNumberUtil.convertToInt(comment.getRoomId()),
278284
openIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_CANCEL_CURRENT);
@@ -282,66 +288,19 @@ private static void pushNotification(Context context, QiscusComment comment,
282288
}
283289

284290
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, notificationChannelId);
285-
notificationBuilder.setContentTitle(pushNotificationMessage.getRoomName())
291+
notificationBuilder.setContentTitle(comment.getSender())
286292
.setContentIntent(pendingIntent)
287-
.setContentText(pushNotificationMessage.getMessage())
288-
.setTicker(pushNotificationMessage.getMessage())
289-
.setSmallIcon(Qiscus.getChatConfig().getNotificationSmallIcon())
290-
.setLargeIcon(largeIcon)
291-
.setColor(ContextCompat.getColor(context, Qiscus.getChatConfig().getInlineReplyColor()))
293+
.setContentText(comment.getMessage())
294+
.setTicker(comment.getMessage())
295+
.setSmallIcon(R.drawable.ic_qiscus_notif_app)
296+
.setColor(ContextCompat.getColor(context, R.color.colorAccent))
292297
.setGroup("CHAT_NOTIF_" + comment.getRoomId())
293298
.setAutoCancel(true)
294299
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
295300

296-
if (Qiscus.getChatConfig().isEnableReplyNotification() && isNougatOrHigher()) {
297-
String getRepliedTo = pushNotificationMessage.getRoomName();
298-
RemoteInput remoteInput = new RemoteInput.Builder(KEY_NOTIFICATION_REPLY)
299-
.setLabel(QiscusTextUtil.getString(R.string.qiscus_reply_to, getRepliedTo.toUpperCase()))
300-
.build();
301-
302-
NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(android.R.drawable.ic_menu_send,
303-
QiscusTextUtil.getString(R.string.qiscus_reply_to, getRepliedTo.toUpperCase()), pendingIntent)
304-
.addRemoteInput(remoteInput)
305-
.build();
306-
notificationBuilder.addAction(replyAction);
307-
}
308-
309-
boolean cancel = false;
310-
if (Qiscus.getChatConfig().getNotificationBuilderInterceptor() != null) {
311-
cancel = !Qiscus.getChatConfig().getNotificationBuilderInterceptor()
312-
.intercept(notificationBuilder, comment);
313-
}
314-
315-
if (cancel) {
316-
return;
317-
}
318-
319-
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
320-
List<QiscusPushNotificationMessage> notifItems = QiscusCacheManager.getInstance()
321-
.getMessageNotifItems(comment.getRoomId());
322-
if (notifItems == null) {
323-
notifItems = new ArrayList<>();
324-
}
325-
int notifSize = 5;
326-
if (notifItems.size() < notifSize) {
327-
notifSize = notifItems.size();
328-
}
329-
if (notifItems.size() > notifSize) {
330-
inboxStyle.addLine(".......");
331-
}
332-
int start = notifItems.size() - notifSize;
333-
for (int i = start; i < notifItems.size(); i++) {
334-
inboxStyle.addLine(notifItems.get(i).getMessage());
335-
}
336-
inboxStyle.setSummaryText(QiscusTextUtil.getString(R.string.qiscus_notif_count, notifItems.size()));
337-
notificationBuilder.setStyle(inboxStyle);
338-
339-
if (notifSize <= 3) {
340-
notificationBuilder.setPriority(Notification.PRIORITY_HIGH);
341-
}
342-
343301
QiscusAndroidUtil.runOnUIThread(() -> NotificationManagerCompat.from(context)
344302
.notify(QiscusNumberUtil.convertToInt(comment.getRoomId()), notificationBuilder.build()));
303+
345304
}
346305

347306
private static void handleDeletedComment(Context context, List<QiscusComment> comments, boolean hardDelete) {

0 commit comments

Comments
 (0)