mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-07 17:43:18 +02:00
Added notification channel debug info
This commit is contained in:
@@ -22,7 +22,6 @@ package eu.faircode.email;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.app.Dialog;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
@@ -37,8 +36,6 @@ import android.content.res.AssetFileDescriptor;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
@@ -51,7 +48,6 @@ import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
@@ -534,7 +530,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
NotificationChannel channel = nm.getNotificationChannel(
|
||||
EntityAccount.getNotificationChannelId(account.id));
|
||||
if (channel != null && channel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
|
||||
JSONObject jchannel = channelToJSON(channel);
|
||||
JSONObject jchannel = NotificationHelper.channelToJSON(channel);
|
||||
jaccount.put("channel", jchannel);
|
||||
Log.i("Exported account channel=" + jchannel);
|
||||
}
|
||||
@@ -556,7 +552,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
NotificationChannel channel = nm.getNotificationChannel(
|
||||
EntityFolder.getNotificationChannelId(folder.id));
|
||||
if (channel != null && channel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
|
||||
JSONObject jchannel = channelToJSON(channel);
|
||||
JSONObject jchannel = NotificationHelper.channelToJSON(channel);
|
||||
jfolder.put("channel", jchannel);
|
||||
Log.i("Exported folder channel=" + jchannel);
|
||||
}
|
||||
@@ -626,7 +622,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
String id = channel.getId();
|
||||
if (id.startsWith("notification.") && id.contains("@") &&
|
||||
channel.getImportance() != NotificationManager.IMPORTANCE_NONE) {
|
||||
JSONObject jchannel = channelToJSON(channel);
|
||||
JSONObject jchannel = NotificationHelper.channelToJSON(channel);
|
||||
jchannels.put(jchannel);
|
||||
Log.i("Exported contact channel=" + jchannel);
|
||||
}
|
||||
@@ -817,7 +813,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
JSONObject jchannel = (JSONObject) jaccount.get("channel");
|
||||
jchannel.put("id", EntityAccount.getNotificationChannelId(account.id));
|
||||
jchannel.put("group", group.getId());
|
||||
nm.createNotificationChannel(channelFromJSON(context, jchannel));
|
||||
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
||||
|
||||
Log.i("Imported account channel=" + jchannel);
|
||||
} else
|
||||
@@ -867,7 +863,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
JSONObject jchannel = (JSONObject) jfolder.get("channel");
|
||||
jchannel.put("id", channelId);
|
||||
jchannel.put("group", group.getId());
|
||||
nm.createNotificationChannel(channelFromJSON(context, jchannel));
|
||||
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
||||
|
||||
Log.i("Imported folder channel=" + jchannel);
|
||||
}
|
||||
@@ -1016,7 +1012,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
String channelId = jchannel.getString("id");
|
||||
nm.deleteNotificationChannel(channelId);
|
||||
|
||||
nm.createNotificationChannel(channelFromJSON(context, jchannel));
|
||||
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
|
||||
|
||||
Log.i("Imported contact channel=" + jchannel);
|
||||
}
|
||||
@@ -1130,65 +1126,6 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private JSONObject channelToJSON(NotificationChannel channel) throws JSONException {
|
||||
JSONObject jchannel = new JSONObject();
|
||||
|
||||
jchannel.put("id", channel.getId());
|
||||
jchannel.put("group", channel.getGroup());
|
||||
jchannel.put("name", channel.getName());
|
||||
jchannel.put("description", channel.getDescription());
|
||||
|
||||
jchannel.put("importance", channel.getImportance());
|
||||
jchannel.put("dnd", channel.canBypassDnd());
|
||||
jchannel.put("visibility", channel.getLockscreenVisibility());
|
||||
jchannel.put("badge", channel.canShowBadge());
|
||||
|
||||
Uri sound = channel.getSound();
|
||||
if (sound != null)
|
||||
jchannel.put("sound", sound.toString());
|
||||
// audio attributes
|
||||
|
||||
jchannel.put("light", channel.shouldShowLights());
|
||||
// color
|
||||
|
||||
jchannel.put("vibrate", channel.shouldVibrate());
|
||||
// pattern
|
||||
|
||||
return jchannel;
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
static NotificationChannel channelFromJSON(Context context, JSONObject jchannel) throws JSONException {
|
||||
NotificationChannel channel = new NotificationChannel(
|
||||
jchannel.getString("id"),
|
||||
jchannel.getString("name"),
|
||||
jchannel.getInt("importance"));
|
||||
|
||||
String group = jchannel.optString("group");
|
||||
if (!TextUtils.isEmpty(group))
|
||||
channel.setGroup(group);
|
||||
|
||||
if (jchannel.has("description") && !jchannel.isNull("description"))
|
||||
channel.setDescription(jchannel.getString("description"));
|
||||
|
||||
channel.setBypassDnd(jchannel.getBoolean("dnd"));
|
||||
channel.setLockscreenVisibility(jchannel.getInt("visibility"));
|
||||
channel.setShowBadge(jchannel.getBoolean("badge"));
|
||||
|
||||
if (jchannel.has("sound") && !jchannel.isNull("sound")) {
|
||||
Uri uri = Uri.parse(jchannel.getString("sound"));
|
||||
Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
|
||||
if (ringtone != null)
|
||||
channel.setSound(uri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
|
||||
}
|
||||
|
||||
channel.enableLights(jchannel.getBoolean("light"));
|
||||
channel.enableVibration(jchannel.getBoolean("vibrate"));
|
||||
|
||||
return channel;
|
||||
}
|
||||
|
||||
private void onGmail(Intent intent) {
|
||||
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, new FragmentGmail()).addToBackStack("quick");
|
||||
|
||||
Reference in New Issue
Block a user