Skip to content

Commit

Permalink
Add client::notification.bigImageUrl extra
Browse files Browse the repository at this point in the history
closes #185
  • Loading branch information
ngruychev authored and jmattheis committed Dec 2, 2021
1 parent 802e30f commit f598875
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
10 changes: 6 additions & 4 deletions app/src/main/java/com/github/gotify/picasso/PicassoHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,18 @@ private Picasso makePicasso() {
.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);
}
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/github/gotify/service/WebSocketService.java
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,19 @@ private void showNotification(
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());
Expand Down

0 comments on commit f598875

Please sign in to comment.