mirror of https://github.com/M66B/FairEmail.git
Support for notification channel per folder
This commit is contained in:
parent
aba421c470
commit
84a27c7d7a
2
FAQ.md
2
FAQ.md
|
@ -37,7 +37,7 @@ For authorizing:
|
|||
* ~~Semi-automatic encryption~~
|
||||
* ~~Copy message~~
|
||||
* ~~Colored stars~~
|
||||
* Notification settings per folder
|
||||
* ~~Notification settings per folder~~
|
||||
* Select local images for signatures
|
||||
|
||||
Anything on this list is in random order and *might* be added in the near future.
|
||||
|
|
|
@ -19,6 +19,9 @@ package eu.faircode.email;
|
|||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
|
@ -29,7 +32,9 @@ import android.graphics.Color;
|
|||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.text.TextUtils;
|
||||
import android.util.TypedValue;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -115,8 +120,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
private final static int action_delete_local = 3;
|
||||
private final static int action_delete_browsed = 4;
|
||||
private final static int action_empty_trash = 5;
|
||||
private final static int action_edit_properties = 6;
|
||||
private final static int action_edit_rules = 7;
|
||||
private final static int action_edit_rules = 6;
|
||||
private final static int action_edit_properties = 7;
|
||||
private final static int action_create_channel = 8;
|
||||
private final static int action_edit_channel = 9;
|
||||
private final static int action_delete_channel = 10;
|
||||
|
||||
ViewHolder(View itemView) {
|
||||
super(itemView);
|
||||
|
@ -402,6 +410,18 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
if (folder.account != null) {
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_rules, 6, R.string.title_edit_rules);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_properties, 7, R.string.title_edit_properties);
|
||||
|
||||
if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
String channelId = EntityFolder.getNotificationChannelId(folder.id);
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = nm.getNotificationChannel(channelId);
|
||||
if (channel == null)
|
||||
popupMenu.getMenu().add(Menu.NONE, action_create_channel, 6, R.string.title_create_channel);
|
||||
else {
|
||||
popupMenu.getMenu().add(Menu.NONE, action_edit_channel, 7, R.string.title_edit_channel);
|
||||
popupMenu.getMenu().add(Menu.NONE, action_delete_channel, 8, R.string.title_delete_channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||
|
@ -436,6 +456,18 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
onActionEditProperties();
|
||||
return true;
|
||||
|
||||
case action_create_channel:
|
||||
onActionCreateChannel();
|
||||
return true;
|
||||
|
||||
case action_edit_channel:
|
||||
onActionEditChannel();
|
||||
return true;
|
||||
|
||||
case action_delete_channel:
|
||||
onActionDeleteChannel();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
@ -619,6 +651,23 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
|||
new Intent(ActivityView.ACTION_EDIT_FOLDER)
|
||||
.putExtra("id", folder.id));
|
||||
}
|
||||
|
||||
private void onActionCreateChannel() {
|
||||
folder.createNotificationChannel(context);
|
||||
onActionEditChannel();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.O)
|
||||
private void onActionEditChannel() {
|
||||
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS)
|
||||
.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName())
|
||||
.putExtra(Settings.EXTRA_CHANNEL_ID, EntityFolder.getNotificationChannelId(folder.id));
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
private void onActionDeleteChannel() {
|
||||
folder.deleteNotificationChannel(context);
|
||||
}
|
||||
});
|
||||
|
||||
popupMenu.show();
|
||||
|
|
|
@ -1892,10 +1892,17 @@ class Core {
|
|||
|
||||
// Get channel name
|
||||
String channelName = null;
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O &&
|
||||
message.from != null && message.from.length > 0) {
|
||||
InternetAddress from = (InternetAddress) message.from[0];
|
||||
NotificationChannel channel = nm.getNotificationChannel("notification." + from.getAddress().toLowerCase());
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
NotificationChannel channel = null;
|
||||
|
||||
if (message.from != null && message.from.length > 0) {
|
||||
InternetAddress from = (InternetAddress) message.from[0];
|
||||
channel = nm.getNotificationChannel("notification." + from.getAddress().toLowerCase());
|
||||
}
|
||||
|
||||
if (channel == null)
|
||||
channel = nm.getNotificationChannel(EntityFolder.getNotificationChannelId(message.folder));
|
||||
|
||||
if (channel != null)
|
||||
channelName = channel.getId();
|
||||
}
|
||||
|
|
|
@ -179,6 +179,10 @@ public class EntityFolder extends EntityOrder implements Serializable {
|
|||
public EntityFolder() {
|
||||
}
|
||||
|
||||
static String getNotificationChannelId(long id) {
|
||||
return "notification.folder." + id;
|
||||
}
|
||||
|
||||
JSONArray getSyncArgs() {
|
||||
int days = sync_days;
|
||||
if (last_sync != null) {
|
||||
|
|
|
@ -19,6 +19,9 @@ package eu.faircode.email;
|
|||
Copyright 2018-2019 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
@ -55,6 +58,24 @@ public class TupleFolderEx extends EntityFolder implements Serializable {
|
|||
return false;
|
||||
}
|
||||
|
||||
void createNotificationChannel(Context context) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
getNotificationChannelId(id), accountName + "/" + getDisplayName(context),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
channel.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
|
||||
void deleteNotificationChannel(Context context) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
nm.deleteNotificationChannel(getNotificationChannelId(id));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
Comparator getComparator(final Context context) {
|
||||
final Collator collator = Collator.getInstance(Locale.getDefault());
|
||||
|
|
|
@ -331,6 +331,9 @@
|
|||
<string name="title_empty_trash">Empty trash</string>
|
||||
<string name="title_edit_properties">Edit properties</string>
|
||||
<string name="title_edit_rules">Edit rules</string>
|
||||
<string name="title_create_channel">Create notification channel</string>
|
||||
<string name="title_edit_channel">Edit notification channel</string>
|
||||
<string name="title_delete_channel">Delete notification channel</string>
|
||||
|
||||
<string name="title_empty_trash_ask">Delete all trashed messages permanently?</string>
|
||||
<string name="title_delete_operation">Delete operations with an error message?</string>
|
||||
|
|
Loading…
Reference in New Issue