From 0afbe80c3630202edefe41d9a384d96a18a81f1f Mon Sep 17 00:00:00 2001 From: Brian Sztamfater Date: Thu, 5 Aug 2021 17:13:49 -0300 Subject: [PATCH] Fix profile image in push notiications Signed-off-by: Brian Sztamfater --- .../PushNotificationHelper.java | 40 ++++++++++++++++++- status-go-version.json | 6 +-- 2 files changed, 41 insertions(+), 5 deletions(-) diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java index 73774060f2..20aa356054 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/pushnotifications/PushNotificationHelper.java @@ -19,6 +19,12 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Color; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.PorterDuff; +import android.graphics.PorterDuffXfermode; +import android.graphics.Rect; +import android.graphics.RectF; import android.media.AudioAttributes; import android.media.RingtoneManager; import android.net.Uri; @@ -354,7 +360,14 @@ public class PushNotificationHelper { } } - if (largeIconBitmap != null){ + Bundle author = bundle.getBundle("notificationAuthor"); + + if (largeIconBitmap == null && author != null) { + String base64Image = author.getString("icon").split(",")[1]; + byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT); + Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); + notification.setLargeIcon(getCircleBitmap(decodedByte)); + } else if (largeIconBitmap != null){ notification.setLargeIcon(largeIconBitmap); } @@ -647,6 +660,29 @@ public class PushNotificationHelper { return false; } + private Bitmap getCircleBitmap(Bitmap bitmap) { + final Bitmap output = Bitmap.createBitmap(bitmap.getWidth(), + bitmap.getHeight(), Bitmap.Config.ARGB_8888); + final Canvas canvas = new Canvas(output); + + final int color = Color.RED; + final Paint paint = new Paint(); + final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); + final RectF rectF = new RectF(rect); + + paint.setAntiAlias(true); + canvas.drawARGB(0, 0, 0, 0); + paint.setColor(color); + canvas.drawOval(rectF, paint); + + paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN)); + canvas.drawBitmap(bitmap, rect, rect, paint); + + bitmap.recycle(); + + return output; + } + private Person getPerson(Bundle bundle) { String base64Image = bundle.getString("icon").split(",")[1]; byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT); @@ -654,7 +690,7 @@ public class PushNotificationHelper { String name = bundle.getString("name"); - return new Person.Builder().setIcon(IconCompat.createWithBitmap(decodedByte)).setName(name).build(); + return new Person.Builder().setIcon(IconCompat.createWithBitmap(getCircleBitmap(decodedByte))).setName(name).build(); } private StatusMessage createMessage(Bundle data) { diff --git a/status-go-version.json b/status-go-version.json index 24d44c4c9a..42dcf664d3 100644 --- a/status-go-version.json +++ b/status-go-version.json @@ -3,7 +3,7 @@ "_comment": "Instead use: scripts/update-status-go.sh ", "owner": "status-im", "repo": "status-go", - "version": "v0.89.8", - "commit-sha1": "e77371d7d2154128d84c9607895c13620b20b260", - "src-sha256": "1w8m3391xdlv29spvzlavp3f47rzvi8syk6q9nklr028l67ib0qd" + "version": "v0.89.9", + "commit-sha1": "4e33e4679593c93a8a183f8326a279343e29307d", + "src-sha256": "1286g2mn3vm7n2bmihr2jlkacvjrdyhppxd5mrkpdlj1asxwangj" }