Added fail-safe for channel import

This commit is contained in:
M66B 2022-08-30 21:11:13 +02:00
parent c9201c2da4
commit 0ac2ec0bad
1 changed files with 36 additions and 25 deletions

View File

@ -1120,17 +1120,22 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
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); try {
nm.createNotificationChannelGroup(group); NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
nm.createNotificationChannelGroup(group);
JSONObject jchannel = (JSONObject) jaccount.get("channel"); JSONObject jchannel = (JSONObject) jaccount.get("channel");
jchannel.put("id", EntityAccount.getNotificationChannelId(account.id)); jchannel.put("id", EntityAccount.getNotificationChannelId(account.id));
jchannel.put("group", group.getId()); jchannel.put("group", group.getId());
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel)); nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
Log.i("Imported account channel=" + jchannel); Log.i("Imported account channel=" + jchannel);
} else } catch (Throwable ex) {
Log.e(ex);
account.createNotificationChannel(context);
}
else
account.createNotificationChannel(context); account.createNotificationChannel(context);
} }
@ -1172,17 +1177,20 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
String channelId = EntityFolder.getNotificationChannelId(folder.id); String channelId = EntityFolder.getNotificationChannelId(folder.id);
nm.deleteNotificationChannel(channelId); nm.deleteNotificationChannel(channelId);
if (jfolder.has("channel")) { if (jfolder.has("channel"))
NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name); try {
nm.createNotificationChannelGroup(group); NotificationChannelGroup group = new NotificationChannelGroup("group." + account.id, account.name);
nm.createNotificationChannelGroup(group);
JSONObject jchannel = (JSONObject) jfolder.get("channel"); JSONObject jchannel = (JSONObject) jfolder.get("channel");
jchannel.put("id", channelId); jchannel.put("id", channelId);
jchannel.put("group", group.getId()); jchannel.put("group", group.getId());
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel)); nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
Log.i("Imported folder channel=" + jchannel); Log.i("Imported folder channel=" + jchannel);
} } catch (Throwable ex) {
Log.e(ex);
}
} }
if (jfolder.has("rules")) { if (jfolder.has("rules")) {
@ -1397,16 +1405,19 @@ 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) {
if (jimport.has("channels")) { if (jimport.has("channels")) {
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); try {
JSONObject jchannel = (JSONObject) jchannels.get(i);
String channelId = jchannel.getString("id"); String channelId = jchannel.getString("id");
nm.deleteNotificationChannel(channelId); nm.deleteNotificationChannel(channelId);
nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel)); nm.createNotificationChannel(NotificationHelper.channelFromJSON(context, jchannel));
Log.i("Imported contact channel=" + jchannel); Log.i("Imported contact channel=" + jchannel);
} } catch (Throwable ex) {
Log.e(ex);
}
} }
} }
} }