Skip to content

Commit ab20bec

Browse files
committed
feat: add share and open actions
1 parent 7fd8ee0 commit ab20bec

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

app/src/main/java/com/github/gotify/service/WebSocketService.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,30 @@ private void showNotification(
323323
.setColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary))
324324
.setContentIntent(contentIntent);
325325

326+
String actionOpen =
327+
Extras.getNestedValue(String.class, extras, "client::notification", "actions", "open");
328+
329+
if (actionOpen != null) {
330+
Intent actionOpenIntent = new Intent();
331+
actionOpenIntent.setAction(Intent.ACTION_VIEW);
332+
actionOpenIntent.setData(Uri.parse(actionOpen));
333+
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 123, actionOpenIntent, PendingIntent.FLAG_IMMUTABLE);
334+
b.addAction(new NotificationCompat.Action.Builder(null, "open", pendingIntent).build());
335+
}
336+
337+
String actionShare =
338+
Extras.getNestedValue(String.class, extras, "client::notification", "actions", "share");
339+
340+
if (actionShare != null) {
341+
Intent sendIntent = new Intent();
342+
sendIntent.setAction(Intent.ACTION_SEND);
343+
sendIntent.putExtra(Intent.EXTRA_TEXT, Uri.parse(actionShare));
344+
sendIntent.setType("text/plain");
345+
Intent shareIntent = Intent.createChooser(sendIntent, null);
346+
PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 124, shareIntent, PendingIntent.FLAG_IMMUTABLE);
347+
b.addAction(new NotificationCompat.Action.Builder(null, "share", pendingIntent).build());
348+
}
349+
326350
CharSequence formattedMessage = message;
327351
if (Extras.useMarkdown(extras)) {
328352
formattedMessage = markwon.toMarkdown(message);

client/build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,11 @@ ext {
100100
junit_version = "4.13"
101101
threetenbp_version = "1.4.4"
102102
json_fire_version = "1.8.4"
103+
javax_annotation_version = "1.3.2"
103104
}
104105

105106
dependencies {
107+
compile "javax.annotation:javax.annotation-api:$javax_annotation_version"
106108
compile "com.squareup.retrofit2:retrofit:$retrofit_version"
107109
compile "com.squareup.retrofit2:converter-scalars:$retrofit_version"
108110
compile "com.squareup.retrofit2:converter-gson:$retrofit_version"

0 commit comments

Comments
 (0)