Cleanup
This commit is contained in:
parent
864b868f45
commit
da851a985b
@ -170,6 +170,7 @@ class MyHomePage extends StatelessWidget {
|
||||
title: 'Test conversation',
|
||||
messages: messages,
|
||||
channelId: channelId,
|
||||
jid: 'testjid',
|
||||
),
|
||||
);
|
||||
},
|
||||
|
@ -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
|
||||
|
@ -92,6 +92,7 @@ class MessagingNotification {
|
||||
required this.title,
|
||||
required this.id,
|
||||
required this.channelId,
|
||||
required this.jid,
|
||||
required this.messages,
|
||||
});
|
||||
|
||||
@ -104,6 +105,9 @@ class MessagingNotification {
|
||||
/// The id of the notification channel the notification should appear on.
|
||||
String channelId;
|
||||
|
||||
/// The JID of the chat in which the notifications happen.
|
||||
String jid;
|
||||
|
||||
/// Messages to show.
|
||||
List<NotificationMessage?> messages;
|
||||
|
||||
@ -112,6 +116,7 @@ class MessagingNotification {
|
||||
title,
|
||||
id,
|
||||
channelId,
|
||||
jid,
|
||||
messages,
|
||||
];
|
||||
}
|
||||
@ -122,7 +127,8 @@ class MessagingNotification {
|
||||
title: result[0]! as String,
|
||||
id: result[1]! as int,
|
||||
channelId: result[2]! as String,
|
||||
messages: (result[3] as List<Object?>?)!.cast<NotificationMessage?>(),
|
||||
jid: result[3]! as String,
|
||||
messages: (result[4] as List<Object?>?)!.cast<NotificationMessage?>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class NotificationMessage {
|
||||
}
|
||||
|
||||
class MessagingNotification {
|
||||
const MessagingNotification(this.title, this.id, this.messages, this.channelId);
|
||||
const MessagingNotification(this.title, this.id, this.jid, this.messages, this.channelId);
|
||||
|
||||
/// The title of the conversation.
|
||||
final String title;
|
||||
@ -65,6 +65,9 @@ class MessagingNotification {
|
||||
/// The id of the notification channel the notification should appear on.
|
||||
final String channelId;
|
||||
|
||||
/// The JID of the chat in which the notifications happen.
|
||||
final String jid;
|
||||
|
||||
/// Messages to show.
|
||||
final List<NotificationMessage?> messages;
|
||||
}
|
Reference in New Issue
Block a user