Skip to content

Commit

Permalink
feat: add share and open actions
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrinux committed Jun 16, 2022
1 parent 7fd8ee0 commit 865b33b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
24 changes: 24 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 @@ -323,6 +323,30 @@ private void showNotification(
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
.setContentIntent(contentIntent);

String actionOpen =
Extras.getNestedValue(String.class, extras, "client::notification", "actions", "open");

if (actionOpen != null) {
Intent actionOpenIntent = new Intent();
actionOpenIntent.setAction(Intent.ACTION_VIEW);
actionOpenIntent.setData(Uri.parse(actionOpen));
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 123, actionOpenIntent, PendingIntent.FLAG_IMMUTABLE);
b.addAction(new NotificationCompat.Action.Builder(null, "open", pendingIntent).build());
}

String actionShare =
Extras.getNestedValue(String.class, extras, "client::notification", "actions", "share");

if (actionShare != null) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, actionShare);
sendIntent.setType("text/plain");
Intent shareIntent = Intent.createChooser(sendIntent, null);
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 124, shareIntent, PendingIntent.FLAG_IMMUTABLE);
b.addAction(new NotificationCompat.Action.Builder(null, "share", pendingIntent).build());
}

CharSequence formattedMessage = message;
if (Extras.useMarkdown(extras)) {
formattedMessage = markwon.toMarkdown(message);
Expand Down
2 changes: 2 additions & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,11 @@ ext {
junit_version = "4.13"
threetenbp_version = "1.4.4"
json_fire_version = "1.8.4"
javax_annotation_version = "1.3.2"
}

dependencies {
compile "javax.annotation:javax.annotation-api:$javax_annotation_version"
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
compile "com.squareup.retrofit2:converter-scalars:$retrofit_version"
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"
Expand Down

0 comments on commit 865b33b

Please sign in to comment.