mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 13:24:52 +02:00
Refactoring
This commit is contained in:
@@ -20,17 +20,12 @@ package eu.faircode.email;
|
||||
*/
|
||||
|
||||
import android.app.Application;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -130,7 +125,8 @@ public class ApplicationEx extends Application implements SharedPreferences.OnSh
|
||||
|
||||
upgrade(this);
|
||||
|
||||
createNotificationChannels();
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
|
||||
NotificationHelper.createNotificationChannels(this);
|
||||
|
||||
DB.setupViewInvalidation(this);
|
||||
|
||||
@@ -362,86 +358,6 @@ public class ApplicationEx extends Application implements SharedPreferences.OnSh
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
private void createNotificationChannels() {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
|
||||
// https://issuetracker.google.com/issues/65108694
|
||||
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
// Sync
|
||||
NotificationChannel service = new NotificationChannel(
|
||||
"service", getString(R.string.channel_service),
|
||||
NotificationManager.IMPORTANCE_MIN);
|
||||
service.setDescription(getString(R.string.channel_service_description));
|
||||
service.setSound(null, null);
|
||||
service.enableVibration(false);
|
||||
service.enableLights(false);
|
||||
service.setShowBadge(false);
|
||||
service.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
|
||||
nm.createNotificationChannel(service);
|
||||
|
||||
// Send
|
||||
NotificationChannel send = new NotificationChannel(
|
||||
"send", getString(R.string.channel_send),
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
send.setDescription(getString(R.string.channel_send_description));
|
||||
send.setSound(null, null);
|
||||
send.enableVibration(false);
|
||||
send.enableLights(false);
|
||||
send.setShowBadge(false);
|
||||
send.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(send);
|
||||
|
||||
// Notify
|
||||
NotificationChannel notification = new NotificationChannel(
|
||||
"notification", getString(R.string.channel_notification),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
notification.setDescription(getString(R.string.channel_notification_description));
|
||||
notification.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
notification.enableLights(true);
|
||||
notification.setLightColor(Color.YELLOW);
|
||||
nm.createNotificationChannel(notification);
|
||||
|
||||
// Update
|
||||
if (!Helper.isPlayStoreInstall()) {
|
||||
NotificationChannel update = new NotificationChannel(
|
||||
"update", getString(R.string.channel_update),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
update.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
||||
update.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(update);
|
||||
}
|
||||
|
||||
// Warnings
|
||||
NotificationChannel warning = new NotificationChannel(
|
||||
"warning", getString(R.string.channel_warning),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
warning.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(warning);
|
||||
|
||||
// Errors
|
||||
NotificationChannel error = new NotificationChannel(
|
||||
"error",
|
||||
getString(R.string.channel_error),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
error.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(error);
|
||||
|
||||
// Server alerts
|
||||
NotificationChannel alerts = new NotificationChannel(
|
||||
"alerts",
|
||||
getString(R.string.channel_alert),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
alerts.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(alerts);
|
||||
|
||||
// Contacts grouping
|
||||
NotificationChannelGroup group = new NotificationChannelGroup(
|
||||
"contacts",
|
||||
getString(R.string.channel_group_contacts));
|
||||
nm.createNotificationChannelGroup(group);
|
||||
}
|
||||
}
|
||||
|
||||
private BroadcastReceiver onScreenOff = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
||||
@@ -21,7 +21,10 @@ package eu.faircode.email;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
@@ -34,6 +37,85 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
class NotificationHelper {
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
static void createNotificationChannels(Context context) {
|
||||
// https://issuetracker.google.com/issues/65108694
|
||||
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
|
||||
// Sync
|
||||
NotificationChannel service = new NotificationChannel(
|
||||
"service", context.getString(R.string.channel_service),
|
||||
NotificationManager.IMPORTANCE_MIN);
|
||||
service.setDescription(context.getString(R.string.channel_service_description));
|
||||
service.setSound(null, null);
|
||||
service.enableVibration(false);
|
||||
service.enableLights(false);
|
||||
service.setShowBadge(false);
|
||||
service.setLockscreenVisibility(Notification.VISIBILITY_SECRET);
|
||||
nm.createNotificationChannel(service);
|
||||
|
||||
// Send
|
||||
NotificationChannel send = new NotificationChannel(
|
||||
"send", context.getString(R.string.channel_send),
|
||||
NotificationManager.IMPORTANCE_DEFAULT);
|
||||
send.setDescription(context.getString(R.string.channel_send_description));
|
||||
send.setSound(null, null);
|
||||
send.enableVibration(false);
|
||||
send.enableLights(false);
|
||||
send.setShowBadge(false);
|
||||
send.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(send);
|
||||
|
||||
// Notify
|
||||
NotificationChannel notification = new NotificationChannel(
|
||||
"notification", context.getString(R.string.channel_notification),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
notification.setDescription(context.getString(R.string.channel_notification_description));
|
||||
notification.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
notification.enableLights(true);
|
||||
notification.setLightColor(Color.YELLOW);
|
||||
nm.createNotificationChannel(notification);
|
||||
|
||||
// Update
|
||||
if (!Helper.isPlayStoreInstall()) {
|
||||
NotificationChannel update = new NotificationChannel(
|
||||
"update", context.getString(R.string.channel_update),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
update.setSound(null, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
||||
update.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(update);
|
||||
}
|
||||
|
||||
// Warnings
|
||||
NotificationChannel warning = new NotificationChannel(
|
||||
"warning", context.getString(R.string.channel_warning),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
warning.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(warning);
|
||||
|
||||
// Errors
|
||||
NotificationChannel error = new NotificationChannel(
|
||||
"error",
|
||||
context.getString(R.string.channel_error),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
error.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(error);
|
||||
|
||||
// Server alerts
|
||||
NotificationChannel alerts = new NotificationChannel(
|
||||
"alerts",
|
||||
context.getString(R.string.channel_alert),
|
||||
NotificationManager.IMPORTANCE_HIGH);
|
||||
alerts.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
nm.createNotificationChannel(alerts);
|
||||
|
||||
// Contacts grouping
|
||||
NotificationChannelGroup group = new NotificationChannelGroup(
|
||||
"contacts",
|
||||
context.getString(R.string.channel_group_contacts));
|
||||
nm.createNotificationChannelGroup(group);
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
static JSONObject channelToJSON(NotificationChannel channel) throws JSONException {
|
||||
JSONObject jchannel = new JSONObject();
|
||||
|
||||
Reference in New Issue
Block a user