Cleanup
This commit is contained in:
@@ -335,6 +335,20 @@ public class Api {
|
||||
this.channelId = setterArg;
|
||||
}
|
||||
|
||||
/** The JID of the chat in which the notifications happen. */
|
||||
private @NonNull String jid;
|
||||
|
||||
public @NonNull String getJid() {
|
||||
return jid;
|
||||
}
|
||||
|
||||
public void setJid(@NonNull String setterArg) {
|
||||
if (setterArg == null) {
|
||||
throw new IllegalStateException("Nonnull field \"jid\" is null.");
|
||||
}
|
||||
this.jid = setterArg;
|
||||
}
|
||||
|
||||
/** Messages to show. */
|
||||
private @NonNull List<NotificationMessage> messages;
|
||||
|
||||
@@ -375,6 +389,13 @@ public class Api {
|
||||
return this;
|
||||
}
|
||||
|
||||
private @Nullable String jid;
|
||||
|
||||
public @NonNull Builder setJid(@NonNull String setterArg) {
|
||||
this.jid = setterArg;
|
||||
return this;
|
||||
}
|
||||
|
||||
private @Nullable List<NotificationMessage> messages;
|
||||
|
||||
public @NonNull Builder setMessages(@NonNull List<NotificationMessage> setterArg) {
|
||||
@@ -387,6 +408,7 @@ public class Api {
|
||||
pigeonReturn.setTitle(title);
|
||||
pigeonReturn.setId(id);
|
||||
pigeonReturn.setChannelId(channelId);
|
||||
pigeonReturn.setJid(jid);
|
||||
pigeonReturn.setMessages(messages);
|
||||
return pigeonReturn;
|
||||
}
|
||||
@@ -394,10 +416,11 @@ public class Api {
|
||||
|
||||
@NonNull
|
||||
ArrayList<Object> toList() {
|
||||
ArrayList<Object> toListResult = new ArrayList<Object>(4);
|
||||
ArrayList<Object> toListResult = new ArrayList<Object>(5);
|
||||
toListResult.add(title);
|
||||
toListResult.add(id);
|
||||
toListResult.add(channelId);
|
||||
toListResult.add(jid);
|
||||
toListResult.add(messages);
|
||||
return toListResult;
|
||||
}
|
||||
@@ -410,7 +433,9 @@ public class Api {
|
||||
pigeonResult.setId((id == null) ? null : ((id instanceof Integer) ? (Integer) id : (Long) id));
|
||||
Object channelId = list.get(2);
|
||||
pigeonResult.setChannelId((String) channelId);
|
||||
Object messages = list.get(3);
|
||||
Object jid = list.get(3);
|
||||
pigeonResult.setJid((String) jid);
|
||||
Object messages = list.get(4);
|
||||
pigeonResult.setMessages((List<NotificationMessage>) messages);
|
||||
return pigeonResult;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
||||
// send a notification to the app.
|
||||
// TODO: Notify app
|
||||
if (intent.action == MARK_AS_READ_ACTION) {
|
||||
Log.d("NotificationReceiver", "Marking ${intent.getStringExtra("title")} as read")
|
||||
Log.d("NotificationReceiver", "Marking ${intent.getStringExtra("jid")} as read")
|
||||
NotificationManagerCompat.from(context).cancel(intent.getLongExtra(MARK_AS_READ_ID_KEY, -1).toInt())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
|
||||
val markAsReadIntent = Intent(context, NotificationReceiver::class.java).apply {
|
||||
action = MARK_AS_READ_ACTION
|
||||
// TODO: Put the JID here
|
||||
putExtra("title", notification.title)
|
||||
putExtra("jid", notification.jid)
|
||||
}
|
||||
val markAsReadPendingIntent = PendingIntent.getBroadcast(
|
||||
context.applicationContext,
|
||||
@@ -50,6 +50,19 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
|
||||
0,
|
||||
)
|
||||
|
||||
// -> Tap action
|
||||
// Thanks https://github.com/MaikuB/flutter_local_notifications/blob/master/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L246
|
||||
// TODO: Copy the interface of awesome_notifications
|
||||
val tapIntent = context.packageManager.getLaunchIntentForPackage(context.packageName)!!.apply {
|
||||
putExtra("jid", notification.jid)
|
||||
}
|
||||
val tapPendingIntent = PendingIntent.getActivity(
|
||||
context,
|
||||
notification.id.toInt(),
|
||||
tapIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
|
||||
// Build the notification
|
||||
// TODO: Use a person
|
||||
// TODO: i18n
|
||||
@@ -97,6 +110,10 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
|
||||
// TODO: I think this is wrong
|
||||
setSmallIcon(R.drawable.ic_service_icon)
|
||||
|
||||
// Tap action
|
||||
setContentIntent(tapPendingIntent)
|
||||
|
||||
// Notification actions
|
||||
addAction(replyAction)
|
||||
addAction(
|
||||
// TODO: Wrong icon
|
||||
|
||||
Reference in New Issue
Block a user