Notification improvements

pull/168/head
M66B 5 years ago
parent 3951e656cc
commit e883ef4cd5

@ -737,6 +737,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
account.deleteNotificationChannel(context);
if (account.notify)
if (jaccount.has("channel")) {
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
@ -789,12 +790,15 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
account.move_to = folder.id;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = EntityFolder.getNotificationChannelId(folder.id);
nm.deleteNotificationChannel(channelId);
if (jfolder.has("channel")) {
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
nm.createNotificationChannelGroup(group);
JSONObject jchannel = (JSONObject) jfolder.get("channel");
jchannel.put("id", EntityFolder.getNotificationChannelId(folder.id));
jchannel.put("id", channelId);
jchannel.put("group", group.getId());
nm.createNotificationChannel(channelFromJSON(context, jchannel));
@ -928,6 +932,10 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
JSONArray jchannels = jimport.getJSONArray("channels");
for (int i = 0; i < jchannels.length(); i++) {
JSONObject jchannel = (JSONObject) jchannels.get(i);
String channelId = jchannel.getString("id");
nm.deleteNotificationChannel(channelId);
nm.createNotificationChannel(channelFromJSON(context, jchannel));
Log.i("Imported contact channel=" + jchannel);

@ -2318,8 +2318,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
@TargetApi(Build.VERSION_CODES.O)
private void onNotifyContact(final TupleMessageEx message) {
final NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
final InternetAddress from = (InternetAddress) message.from[0];
final String channelId = "notification." + from.getAddress().toLowerCase(Locale.ROOT);
final String channelId = message.getNotificationChannelId();
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, ibAddContact);
NotificationChannel channel = nm.getNotificationChannel(channelId);
@ -2358,6 +2357,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return;
}
InternetAddress from = (InternetAddress) message.from[0];
NotificationChannel channel = new NotificationChannel(
channelId, from.getAddress(),
NotificationManager.IMPORTANCE_HIGH);

@ -82,7 +82,6 @@ import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
@ -2638,13 +2637,13 @@ class Core {
// Current
for (TupleMessageEx message : messages) {
// Check if notification channel enabled
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O &&
message.notifying == 0 && message.from != null && message.from.length > 0) {
InternetAddress from = (InternetAddress) message.from[0];
NotificationChannel channel = nm.getNotificationChannel(
"notification." + from.getAddress().toLowerCase(Locale.ROOT));
if (channel != null && channel.getImportance() == NotificationManager.IMPORTANCE_NONE)
continue;
if (message.notifying == 0 && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && pro) {
String channelId = message.getNotificationChannelId();
if (channelId != null) {
NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel != null && channel.getImportance() == NotificationManager.IMPORTANCE_NONE)
continue;
}
}
long group = (pro && message.accountNotify ? message.account : 0);
@ -2911,25 +2910,23 @@ class Core {
PendingIntent piIgnore = PendingIntent.getService(context, ServiceUI.PI_IGNORED, ignore, PendingIntent.FLAG_UPDATE_CURRENT);
// Get channel name
String channelName = null;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
String channelName = EntityAccount.getNotificationChannelId(0);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && pro) {
NotificationChannel channel = null;
if (message.from != null && message.from.length > 0) {
InternetAddress from = (InternetAddress) message.from[0];
channel = nm.getNotificationChannel(
"notification." + from.getAddress().toLowerCase(Locale.ROOT));
}
String channelId = message.getNotificationChannelId();
if (channelId != null)
channel = nm.getNotificationChannel(channelId);
if (channel == null)
channel = nm.getNotificationChannel(EntityFolder.getNotificationChannelId(message.folder));
if (channel != null)
if (channel == null) {
if (message.accountNotify)
channelName = EntityAccount.getNotificationChannelId(message.account);
} else
channelName = channel.getId();
}
if (channelName == null)
channelName = EntityAccount.getNotificationChannelId(
pro && message.accountNotify ? message.account : 0);
NotificationCompat.Builder mbuilder =
new NotificationCompat.Builder(context, channelName)

@ -37,10 +37,12 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.UUID;
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
import static androidx.room.ForeignKey.CASCADE;
import static androidx.room.ForeignKey.SET_NULL;
@ -201,6 +203,13 @@ public class EntityMessage implements Serializable {
return addresses.toArray(new Address[0]);
}
String getNotificationChannelId() {
if (from == null || from.length == 0)
return null;
InternetAddress sender = (InternetAddress) from[0];
return "notification." + sender.getAddress().toLowerCase(Locale.ROOT);
}
static File getFile(Context context, Long id) {
File dir = new File(context.getFilesDir(), "messages");
if (!dir.exists())

Loading…
Cancel
Save