Notifications fixes
This commit is contained in:
@@ -6,6 +6,7 @@ import android.app.PendingIntent;
|
|||||||
import android.app.RemoteInput;
|
import android.app.RemoteInput;
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
import android.os.IBinder;
|
||||||
import android.service.notification.StatusBarNotification;
|
import android.service.notification.StatusBarNotification;
|
||||||
|
|
||||||
@@ -46,7 +47,12 @@ public class NotificationActionHandlerService extends Service{
|
|||||||
NotificationManager nm=getSystemService(NotificationManager.class);
|
NotificationManager nm=getSystemService(NotificationManager.class);
|
||||||
StatusBarNotification notification=findNotification(notificationTag);
|
StatusBarNotification notification=findNotification(notificationTag);
|
||||||
if("reply".equals(action)){
|
if("reply".equals(action)){
|
||||||
CharSequence replyText=RemoteInput.getResultsFromIntent(intent).getCharSequence("replyText");
|
Bundle remoteInputResults=RemoteInput.getResultsFromIntent(intent);
|
||||||
|
if(remoteInputResults==null){
|
||||||
|
maybeStopSelf();
|
||||||
|
return START_NOT_STICKY;
|
||||||
|
}
|
||||||
|
CharSequence replyText=remoteInputResults.getCharSequence("replyText");
|
||||||
if(replyText==null){
|
if(replyText==null){
|
||||||
maybeStopSelf();
|
maybeStopSelf();
|
||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
|
|||||||
@@ -178,6 +178,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
}
|
}
|
||||||
String replyPrefix=mentions.isEmpty() ? "" : TextUtils.join(" ", mentions)+" ";
|
String replyPrefix=mentions.isEmpty() ? "" : TextUtils.join(" ", mentions)+" ";
|
||||||
|
|
||||||
|
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
|
||||||
Intent replyIntent=new Intent(context, NotificationActionHandlerService.class);
|
Intent replyIntent=new Intent(context, NotificationActionHandlerService.class);
|
||||||
replyIntent.putExtra("action", "reply");
|
replyIntent.putExtra("action", "reply");
|
||||||
replyIntent.putExtra("account", accountID);
|
replyIntent.putExtra("account", accountID);
|
||||||
@@ -186,9 +187,10 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
replyIntent.putExtra("visibility", notification.status.visibility.toString());
|
replyIntent.putExtra("visibility", notification.status.visibility.toString());
|
||||||
replyIntent.putExtra("replyPrefix", replyPrefix);
|
replyIntent.putExtra("replyPrefix", replyPrefix);
|
||||||
builder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.ic_reply_24px),
|
builder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.ic_reply_24px),
|
||||||
context.getString(R.string.button_reply), PendingIntent.getService(context, (accountID+pn.notificationId+"reply").hashCode(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT))
|
context.getString(R.string.button_reply), PendingIntent.getService(context, (accountID+pn.notificationId+"reply").hashCode(), replyIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE))
|
||||||
.addRemoteInput(new RemoteInput.Builder("replyText").build())
|
.addRemoteInput(new RemoteInput.Builder("replyText").setLabel(context.getString(R.string.button_reply)).build())
|
||||||
.build());
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
Intent favIntent=new Intent(context, NotificationActionHandlerService.class);
|
Intent favIntent=new Intent(context, NotificationActionHandlerService.class);
|
||||||
favIntent.putExtra("action", "favorite");
|
favIntent.putExtra("action", "favorite");
|
||||||
@@ -196,7 +198,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
favIntent.putExtra("post", notification.status.id);
|
favIntent.putExtra("post", notification.status.id);
|
||||||
favIntent.putExtra("notificationTag", notificationTag);
|
favIntent.putExtra("notificationTag", notificationTag);
|
||||||
builder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.ic_star_24px),
|
builder.addAction(new Notification.Action.Builder(Icon.createWithResource(context, R.drawable.ic_star_24px),
|
||||||
context.getString(R.string.button_favorite), PendingIntent.getService(context, (accountID+pn.notificationId+"favorite").hashCode(), favIntent, PendingIntent.FLAG_UPDATE_CURRENT)).build());
|
context.getString(R.string.button_favorite), PendingIntent.getService(context, (accountID+pn.notificationId+"favorite").hashCode(), favIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE)).build());
|
||||||
|
|
||||||
PendingIntent boostActionIntent;
|
PendingIntent boostActionIntent;
|
||||||
if(notification.status.visibility!=StatusPrivacy.DIRECT){
|
if(notification.status.visibility!=StatusPrivacy.DIRECT){
|
||||||
@@ -205,7 +207,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
boostIntent.putExtra("account", accountID);
|
boostIntent.putExtra("account", accountID);
|
||||||
boostIntent.putExtra("post", notification.status.id);
|
boostIntent.putExtra("post", notification.status.id);
|
||||||
boostIntent.putExtra("notificationTag", notificationTag);
|
boostIntent.putExtra("notificationTag", notificationTag);
|
||||||
boostActionIntent=PendingIntent.getService(context, (accountID+pn.notificationId+"boost").hashCode(), boostIntent, PendingIntent.FLAG_UPDATE_CURRENT);
|
boostActionIntent=PendingIntent.getService(context, (accountID+pn.notificationId+"boost").hashCode(), boostIntent, PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_IMMUTABLE);
|
||||||
}else{
|
}else{
|
||||||
boostActionIntent=null;
|
boostActionIntent=null;
|
||||||
}
|
}
|
||||||
@@ -216,13 +218,15 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
|
|
||||||
StatusBarNotification[] activeNotifications=nm.getActiveNotifications();
|
StatusBarNotification[] activeNotifications=nm.getActiveNotifications();
|
||||||
ArrayList<String> summaryLines=new ArrayList<>();
|
ArrayList<String> summaryLines=new ArrayList<>();
|
||||||
|
int notificationCount=0;
|
||||||
for(StatusBarNotification sbn:activeNotifications){
|
for(StatusBarNotification sbn:activeNotifications){
|
||||||
String tag=sbn.getTag();
|
String tag=sbn.getTag();
|
||||||
if(tag!=null && tag.startsWith(accountID+"_")){
|
if(tag!=null && tag.startsWith(accountID+"_")){
|
||||||
if((sbn.getNotification().flags & Notification.FLAG_GROUP_SUMMARY)==0){
|
if((sbn.getNotification().flags & Notification.FLAG_GROUP_SUMMARY)==0){
|
||||||
|
if(summaryLines.size()<5){
|
||||||
summaryLines.add(sbn.getNotification().extras.getString("android.title"));
|
summaryLines.add(sbn.getNotification().extras.getString("android.title"));
|
||||||
if(summaryLines.size()==5)
|
}
|
||||||
break;
|
notificationCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -239,8 +243,8 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
|||||||
for(String line:summaryLines){
|
for(String line:summaryLines){
|
||||||
inboxStyle.addLine(line);
|
inboxStyle.addLine(line);
|
||||||
}
|
}
|
||||||
summaryBuilder.setContentTitle("content title")
|
summaryBuilder.setContentTitle(context.getString(R.string.app_name))
|
||||||
.setContentText("content text")
|
.setContentText(context.getResources().getQuantityString(R.plurals.x_new_notifications, notificationCount, notificationCount))
|
||||||
.setSmallIcon(R.drawable.ic_ntf_logo)
|
.setSmallIcon(R.drawable.ic_ntf_logo)
|
||||||
.setColor(context.getColor(R.color.primary_700))
|
.setColor(context.getColor(R.color.primary_700))
|
||||||
.setContentIntent(PendingIntent.getActivity(context, accountID.hashCode() & 0xFFFF, contentIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT))
|
.setContentIntent(PendingIntent.getActivity(context, accountID.hashCode() & 0xFFFF, contentIntent, PendingIntent.FLAG_IMMUTABLE | PendingIntent.FLAG_UPDATE_CURRENT))
|
||||||
|
|||||||
@@ -762,4 +762,8 @@
|
|||||||
<string name="signup_username_taken">This username is taken. Try a different one or <a>pick a different server</a>.</string>
|
<string name="signup_username_taken">This username is taken. Try a different one or <a>pick a different server</a>.</string>
|
||||||
<string name="signup_email_invalid">That doesn’t look like a valid email address.</string>
|
<string name="signup_email_invalid">That doesn’t look like a valid email address.</string>
|
||||||
<string name="signup_email_taken">Email address is already in use. Did you <a>forget your password</a>?</string>
|
<string name="signup_email_taken">Email address is already in use. Did you <a>forget your password</a>?</string>
|
||||||
|
<plurals name="x_new_notifications">
|
||||||
|
<item quantity="one">%,d new notification</item>
|
||||||
|
<item quantity="other">%,d new notifications</item>
|
||||||
|
</plurals>
|
||||||
</resources>
|
</resources>
|
||||||
Reference in New Issue
Block a user