Fix profile image in push notiications

Signed-off-by: Brian Sztamfater <brian@status.im>
This commit is contained in:
Brian Sztamfater 2021-08-05 17:13:49 -03:00
parent 61878376a3
commit 0afbe80c36
No known key found for this signature in database
GPG Key ID: 59EB921E0706B48F
2 changed files with 41 additions and 5 deletions

View File

@ -19,6 +19,12 @@ import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Color; 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.AudioAttributes;
import android.media.RingtoneManager; import android.media.RingtoneManager;
import android.net.Uri; 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); notification.setLargeIcon(largeIconBitmap);
} }
@ -647,6 +660,29 @@ public class PushNotificationHelper {
return false; 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) { private Person getPerson(Bundle bundle) {
String base64Image = bundle.getString("icon").split(",")[1]; String base64Image = bundle.getString("icon").split(",")[1];
byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT); byte[] decodedString = Base64.decode(base64Image, Base64.DEFAULT);
@ -654,7 +690,7 @@ public class PushNotificationHelper {
String name = bundle.getString("name"); 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) { private StatusMessage createMessage(Bundle data) {

View File

@ -3,7 +3,7 @@
"_comment": "Instead use: scripts/update-status-go.sh <rev>", "_comment": "Instead use: scripts/update-status-go.sh <rev>",
"owner": "status-im", "owner": "status-im",
"repo": "status-go", "repo": "status-go",
"version": "v0.89.8", "version": "v0.89.9",
"commit-sha1": "e77371d7d2154128d84c9607895c13620b20b260", "commit-sha1": "4e33e4679593c93a8a183f8326a279343e29307d",
"src-sha256": "1w8m3391xdlv29spvzlavp3f47rzvi8syk6q9nklr028l67ib0qd" "src-sha256": "1286g2mn3vm7n2bmihr2jlkacvjrdyhppxd5mrkpdlj1asxwangj"
} }