Notification improvements

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

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

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

@ -37,10 +37,12 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Locale;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
import javax.mail.Address; import javax.mail.Address;
import javax.mail.internet.InternetAddress;
import static androidx.room.ForeignKey.CASCADE; import static androidx.room.ForeignKey.CASCADE;
import static androidx.room.ForeignKey.SET_NULL; import static androidx.room.ForeignKey.SET_NULL;
@ -201,6 +203,13 @@ public class EntityMessage implements Serializable {
return addresses.toArray(new Address[0]); 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) { static File getFile(Context context, Long id) {
File dir = new File(context.getFilesDir(), "messages"); File dir = new File(context.getFilesDir(), "messages");
if (!dir.exists()) if (!dir.exists())

Loading…
Cancel
Save