feat: Color in the notification silhouette

This commit is contained in:
2023-07-29 12:34:40 +02:00
parent daf40aed0b
commit 8f93821617
11 changed files with 107 additions and 30 deletions

View File

@@ -703,12 +703,14 @@ public class Api {
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
public interface MoxplatformApi {
void createNotificationChannel(@NonNull String title, @NonNull String id, @NonNull Boolean urgent, @NonNull NotificationI18nData i18n);
void createNotificationChannel(@NonNull String title, @NonNull String id, @NonNull Boolean urgent);
void showMessagingNotification(@NonNull MessagingNotification notification);
void setNotificationSelfAvatar(@NonNull String path);
void setNotificationI18n(@NonNull NotificationI18nData data);
@NonNull
String getPersistentDataPath();
@@ -735,9 +737,8 @@ public class Api {
String titleArg = (String) args.get(0);
String idArg = (String) args.get(1);
Boolean urgentArg = (Boolean) args.get(2);
NotificationI18nData i18nArg = (NotificationI18nData) args.get(3);
try {
api.createNotificationChannel(titleArg, idArg, urgentArg, i18nArg);
api.createNotificationChannel(titleArg, idArg, urgentArg);
wrapped.add(0, null);
}
catch (Throwable exception) {
@@ -788,6 +789,30 @@ public class Api {
api.setNotificationSelfAvatar(pathArg);
wrapped.add(0, null);
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;
}
reply.reply(wrapped);
});
} else {
channel.setMessageHandler(null);
}
}
{
BasicMessageChannel<Object> channel =
new BasicMessageChannel<>(
binaryMessenger, "dev.flutter.pigeon.moxplatform_platform_interface.MoxplatformApi.setNotificationI18n", getCodec());
if (api != null) {
channel.setMessageHandler(
(message, reply) -> {
ArrayList<Object> wrapped = new ArrayList<Object>();
ArrayList<Object> args = (ArrayList<Object>) message;
NotificationI18nData dataArg = (NotificationI18nData) args.get(0);
try {
api.setNotificationI18n(dataArg);
wrapped.add(0, null);
}
catch (Throwable exception) {
ArrayList<Object> wrappedError = wrapError(exception);
wrapped = wrappedError;

View File

@@ -288,7 +288,7 @@ import kotlin.jvm.functions.Function1;
}
@Override
public void createNotificationChannel(@NonNull String title, @NonNull String id, @NonNull Boolean urgent, @NonNull NotificationI18nData i18n) {
public void createNotificationChannel(@NonNull String title, @NonNull String id, @NonNull Boolean urgent) {
final NotificationChannel channel = new NotificationChannel(
id,
title,
@@ -298,11 +298,6 @@ import kotlin.jvm.functions.Function1;
channel.enableLights(true);
final NotificationManager manager = getSystemService(context, NotificationManager.class);
manager.createNotificationChannel(channel);
// Configure i18n
NotificationDataManager.INSTANCE.setYou(i18n.getYou());
NotificationDataManager.INSTANCE.setReply(i18n.getReply());
NotificationDataManager.INSTANCE.setMarkAsRead(i18n.getMarkAsRead());
}
@Override
@@ -315,6 +310,14 @@ import kotlin.jvm.functions.Function1;
NotificationDataManager.INSTANCE.setAvatarPath(path);
}
@Override
public void setNotificationI18n(@NonNull NotificationI18nData data) {
// Configure i18n
NotificationDataManager.INSTANCE.setYou(data.getYou());
NotificationDataManager.INSTANCE.setReply(data.getReply());
NotificationDataManager.INSTANCE.setMarkAsRead(data.getMarkAsRead());
}
@NonNull
@Override
public String getPersistentDataPath() {

View File

@@ -1,9 +1,11 @@
package me.polynom.moxplatform_android
import android.app.Notification
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import android.graphics.BitmapFactory
import android.graphics.Color
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import androidx.core.app.Person
@@ -38,8 +40,7 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
PendingIntent.FLAG_UPDATE_CURRENT,
)
val replyAction = NotificationCompat.Action.Builder(
// TODO: Wrong icon?
R.drawable.ic_service_icon,
R.drawable.reply,
NotificationDataManager.reply,
replyPendingIntent,
).apply {
@@ -60,8 +61,7 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
PendingIntent.FLAG_UPDATE_CURRENT,
)
val markAsReadAction = NotificationCompat.Action.Builder(
// TODO: Wrong icon
R.drawable.ic_service_icon,
R.drawable.mark_as_read,
NotificationDataManager.markAsRead,
markAsReadPendingIntent,
).build()
@@ -141,8 +141,11 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
// Assemble the notification
val finalNotification = NotificationCompat.Builder(context, notification.channelId).apply {
setStyle(style)
// TODO: I think this is wrong
// NOTE: It's okay to use the service icon here as I cannot get Android to display the
// actual logo. So we'll have to make do with the silhouette and the color purple.
setSmallIcon(R.drawable.ic_service_icon)
color = Color.argb(255, 207, 74, 255)
setColorized(true)
// Tap action
setContentIntent(tapPendingIntent)
@@ -151,6 +154,9 @@ fun showMessagingNotification(context: Context, notification: Api.MessagingNotif
addAction(replyAction)
addAction(markAsReadAction)
setAllowSystemGeneratedContextualActions(true)
setCategory(Notification.CATEGORY_MESSAGE)
// Prevent no notification when we replied before
setOnlyAlertOnce(false)
}.build()

View File

@@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#FFFFFF"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M17.34,20l-3.54,-3.54l1.41,-1.41l2.12,2.12l4.24,-4.24L23,14.34L17.34,20zM12,17c0,-3.87 3.13,-7 7,-7c1.08,0 2.09,0.25 3,0.68V4c0,-1.1 -0.9,-2 -2,-2H4C2.9,2 2,2.9 2,4v18l4,-4h6v0c0,-0.17 0.01,-0.33 0.03,-0.5C12.01,17.34 12,17.17 12,17z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector android:autoMirrored="true" android:height="24dp"
android:tint="#FFFFFF" android:viewportHeight="24"
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M10,9V5l-7,7 7,7v-4.1c5,0 8.5,1.6 11,5.1 -1,-5 -4,-10 -11,-11z"/>
</vector>

View File

@@ -13,9 +13,8 @@ class AndroidNotificationsImplementation extends NotificationsImplementation {
String title,
String id,
bool urgent,
NotificationI18nData i18n,
) async {
return _api.createNotificationChannel(title, id, urgent, i18n);
return _api.createNotificationChannel(title, id, urgent);
}
@override
@@ -28,7 +27,12 @@ class AndroidNotificationsImplementation extends NotificationsImplementation {
@override
Future<void> setNotificationSelfAvatar(String path) async {
return _api.setNotificationSelfAvatar(path);
}
}
@override
Future<void> setI18n(NotificationI18nData data) {
return _api.setNotificationI18n(data);
}
@override
Stream<NotificationEvent> getEventStream() => _channel