Add client::notification.bigImageUrl extra

closes #185
This commit is contained in:
Nikolay Gruychev
2021-11-24 16:05:13 +02:00
committed by Jannis Mattheis
parent 802e30fd36
commit f5988754fa
2 changed files with 19 additions and 4 deletions

View File

@@ -56,16 +56,18 @@ public class PicassoHandler {
.build();
}
public Bitmap getImageFromUrl(String url) throws IOException {
return picasso.load(url).get();
}
public Bitmap getIcon(Long appId) {
if (appId == -1) {
return BitmapFactory.decodeResource(context.getResources(), R.drawable.gotify);
}
try {
return picasso.load(
Utils.resolveAbsoluteUrl(
settings.url() + "/", appIdToAppImage.get(appId)))
.get();
return getImageFromUrl(
Utils.resolveAbsoluteUrl(settings.url() + "/", appIdToAppImage.get(appId)));
} catch (IOException e) {
Log.e("Could not load image for notification", e);
}

View File

@@ -314,6 +314,19 @@ public class WebSocketService extends Service {
b.setContentText(message);
b.setStyle(new NotificationCompat.BigTextStyle().bigText(formattedMessage));
String notificationImageUrl =
Extras.getNestedValue(String.class, extras, "client::notification", "bigImageUrl");
if (notificationImageUrl != null) {
try {
b.setStyle(
new NotificationCompat.BigPictureStyle()
.bigPicture(picassoHandler.getImageFromUrl(notificationImageUrl)));
} catch (Exception e) {
Log.e("Error loading bigImageUrl", e);
}
}
NotificationManager notificationManager =
(NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(Utils.longToInt(id), b.build());