Cleanup
This commit is contained in:
parent
864b868f45
commit
da851a985b
@ -170,6 +170,7 @@ class MyHomePage extends StatelessWidget {
|
|||||||
title: 'Test conversation',
|
title: 'Test conversation',
|
||||||
messages: messages,
|
messages: messages,
|
||||||
channelId: channelId,
|
channelId: channelId,
|
||||||
|
jid: 'testjid',
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
@ -335,6 +335,20 @@ public class Api {
|
|||||||
this.channelId = setterArg;
|
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. */
|
/** Messages to show. */
|
||||||
private @NonNull List<NotificationMessage> messages;
|
private @NonNull List<NotificationMessage> messages;
|
||||||
|
|
||||||
@ -375,6 +389,13 @@ public class Api {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @Nullable String jid;
|
||||||
|
|
||||||
|
public @NonNull Builder setJid(@NonNull String setterArg) {
|
||||||
|
this.jid = setterArg;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
private @Nullable List<NotificationMessage> messages;
|
private @Nullable List<NotificationMessage> messages;
|
||||||
|
|
||||||
public @NonNull Builder setMessages(@NonNull List<NotificationMessage> setterArg) {
|
public @NonNull Builder setMessages(@NonNull List<NotificationMessage> setterArg) {
|
||||||
@ -387,6 +408,7 @@ public class Api {
|
|||||||
pigeonReturn.setTitle(title);
|
pigeonReturn.setTitle(title);
|
||||||
pigeonReturn.setId(id);
|
pigeonReturn.setId(id);
|
||||||
pigeonReturn.setChannelId(channelId);
|
pigeonReturn.setChannelId(channelId);
|
||||||
|
pigeonReturn.setJid(jid);
|
||||||
pigeonReturn.setMessages(messages);
|
pigeonReturn.setMessages(messages);
|
||||||
return pigeonReturn;
|
return pigeonReturn;
|
||||||
}
|
}
|
||||||
@ -394,10 +416,11 @@ public class Api {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
ArrayList<Object> toList() {
|
ArrayList<Object> toList() {
|
||||||
ArrayList<Object> toListResult = new ArrayList<Object>(4);
|
ArrayList<Object> toListResult = new ArrayList<Object>(5);
|
||||||
toListResult.add(title);
|
toListResult.add(title);
|
||||||
toListResult.add(id);
|
toListResult.add(id);
|
||||||
toListResult.add(channelId);
|
toListResult.add(channelId);
|
||||||
|
toListResult.add(jid);
|
||||||
toListResult.add(messages);
|
toListResult.add(messages);
|
||||||
return toListResult;
|
return toListResult;
|
||||||
}
|
}
|
||||||
@ -410,7 +433,9 @@ public class Api {
|
|||||||
pigeonResult.setId((id == null) ? null : ((id instanceof Integer) ? (Integer) id : (Long) id));
|
pigeonResult.setId((id == null) ? null : ((id instanceof Integer) ? (Integer) id : (Long) id));
|
||||||
Object channelId = list.get(2);
|
Object channelId = list.get(2);
|
||||||
pigeonResult.setChannelId((String) channelId);
|
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);
|
pigeonResult.setMessages((List<NotificationMessage>) messages);
|
||||||
return pigeonResult;
|
return pigeonResult;
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@ class NotificationReceiver : BroadcastReceiver() {
|
|||||||
// send a notification to the app.
|
// send a notification to the app.
|
||||||
// TODO: Notify app
|
// TODO: Notify app
|
||||||
if (intent.action == MARK_AS_READ_ACTION) {
|
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())
|
NotificationManagerCompat.from(context).cancel(intent.getLongExtra(MARK_AS_READ_ID_KEY, -1).toInt())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
|
|||||||
val markAsReadIntent = Intent(context, NotificationReceiver::class.java).apply {
|
val markAsReadIntent = Intent(context, NotificationReceiver::class.java).apply {
|
||||||
action = MARK_AS_READ_ACTION
|
action = MARK_AS_READ_ACTION
|
||||||
// TODO: Put the JID here
|
// TODO: Put the JID here
|
||||||
putExtra("title", notification.title)
|
putExtra("jid", notification.jid)
|
||||||
}
|
}
|
||||||
val markAsReadPendingIntent = PendingIntent.getBroadcast(
|
val markAsReadPendingIntent = PendingIntent.getBroadcast(
|
||||||
context.applicationContext,
|
context.applicationContext,
|
||||||
@ -50,6 +50,19 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
|
|||||||
0,
|
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
|
// Build the notification
|
||||||
// TODO: Use a person
|
// TODO: Use a person
|
||||||
// TODO: i18n
|
// TODO: i18n
|
||||||
@ -97,6 +110,10 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
|
|||||||
// TODO: I think this is wrong
|
// TODO: I think this is wrong
|
||||||
setSmallIcon(R.drawable.ic_service_icon)
|
setSmallIcon(R.drawable.ic_service_icon)
|
||||||
|
|
||||||
|
// Tap action
|
||||||
|
setContentIntent(tapPendingIntent)
|
||||||
|
|
||||||
|
// Notification actions
|
||||||
addAction(replyAction)
|
addAction(replyAction)
|
||||||
addAction(
|
addAction(
|
||||||
// TODO: Wrong icon
|
// TODO: Wrong icon
|
||||||
|
@ -92,6 +92,7 @@ class MessagingNotification {
|
|||||||
required this.title,
|
required this.title,
|
||||||
required this.id,
|
required this.id,
|
||||||
required this.channelId,
|
required this.channelId,
|
||||||
|
required this.jid,
|
||||||
required this.messages,
|
required this.messages,
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -104,6 +105,9 @@ class MessagingNotification {
|
|||||||
/// The id of the notification channel the notification should appear on.
|
/// The id of the notification channel the notification should appear on.
|
||||||
String channelId;
|
String channelId;
|
||||||
|
|
||||||
|
/// The JID of the chat in which the notifications happen.
|
||||||
|
String jid;
|
||||||
|
|
||||||
/// Messages to show.
|
/// Messages to show.
|
||||||
List<NotificationMessage?> messages;
|
List<NotificationMessage?> messages;
|
||||||
|
|
||||||
@ -112,6 +116,7 @@ class MessagingNotification {
|
|||||||
title,
|
title,
|
||||||
id,
|
id,
|
||||||
channelId,
|
channelId,
|
||||||
|
jid,
|
||||||
messages,
|
messages,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -122,7 +127,8 @@ class MessagingNotification {
|
|||||||
title: result[0]! as String,
|
title: result[0]! as String,
|
||||||
id: result[1]! as int,
|
id: result[1]! as int,
|
||||||
channelId: result[2]! as String,
|
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 {
|
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.
|
/// The title of the conversation.
|
||||||
final String title;
|
final String title;
|
||||||
@ -65,6 +65,9 @@ class MessagingNotification {
|
|||||||
/// The id of the notification channel the notification should appear on.
|
/// The id of the notification channel the notification should appear on.
|
||||||
final String channelId;
|
final String channelId;
|
||||||
|
|
||||||
|
/// The JID of the chat in which the notifications happen.
|
||||||
|
final String jid;
|
||||||
|
|
||||||
/// Messages to show.
|
/// Messages to show.
|
||||||
final List<NotificationMessage?> messages;
|
final List<NotificationMessage?> messages;
|
||||||
}
|
}
|
Reference in New Issue
Block a user