From 23fe035085d31ee37dd4ea5b45aa8978165fc05b Mon Sep 17 00:00:00 2001 From: M66B Date: Sun, 17 Mar 2019 18:17:41 +0000 Subject: [PATCH] Refactoring --- app/src/main/java/eu/faircode/email/ActivitySetup.java | 4 ++-- app/src/main/java/eu/faircode/email/ApplicationEx.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/ActivitySetup.java b/app/src/main/java/eu/faircode/email/ActivitySetup.java index 092a8ab1ce..292fbf67c8 100644 --- a/app/src/main/java/eu/faircode/email/ActivitySetup.java +++ b/app/src/main/java/eu/faircode/email/ActivitySetup.java @@ -540,7 +540,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On jexport.put("answers", janswers); jexport.put("settings", jsettings); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) - jexport.put("channels", ((ApplicationEx) getApplication()).channelsToJSON()); + jexport.put("channels", ApplicationEx.channelsToJSON(context)); ContentResolver resolver = context.getContentResolver(); DocumentFile file = DocumentFile.fromSingleUri(context, uri); @@ -755,7 +755,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) if (jimport.has("channels")) { JSONArray jchannels = jimport.getJSONArray("channels"); - ((ApplicationEx) getApplication()).channelsFromJSON(jchannels); + ApplicationEx.channelsFromJSON(context, jchannels); } db.setTransactionSuccessful(); diff --git a/app/src/main/java/eu/faircode/email/ApplicationEx.java b/app/src/main/java/eu/faircode/email/ApplicationEx.java index 637a9bb730..2383ad6f78 100644 --- a/app/src/main/java/eu/faircode/email/ApplicationEx.java +++ b/app/src/main/java/eu/faircode/email/ApplicationEx.java @@ -127,10 +127,10 @@ public class ApplicationEx extends Application { } @RequiresApi(api = Build.VERSION_CODES.O) - public JSONArray channelsToJSON() throws JSONException { + static JSONArray channelsToJSON(Context context) throws JSONException { JSONArray jchannels = new JSONArray(); - NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); for (NotificationChannel channel : nm.getNotificationChannels()) if (!DEFAULT_CHANNEL_NAMES.contains(channel.getId())) { JSONObject jchannel = new JSONObject(); @@ -163,8 +163,8 @@ public class ApplicationEx extends Application { } @RequiresApi(api = Build.VERSION_CODES.O) - public void channelsFromJSON(JSONArray jchannels) throws JSONException { - NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); + static void channelsFromJSON(Context context, JSONArray jchannels) throws JSONException { + NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); for (int c = 0; c < jchannels.length(); c++) { JSONObject jchannel = (JSONObject) jchannels.get(c); @@ -189,7 +189,7 @@ public class ApplicationEx extends Application { if (jchannel.has("sound") && !jchannel.isNull("sound")) { Uri uri = Uri.parse(jchannel.getString("sound")); - Ringtone ringtone = RingtoneManager.getRingtone(this, uri); + Ringtone ringtone = RingtoneManager.getRingtone(context, uri); if (ringtone != null) channel.setSound(uri, Notification.AUDIO_ATTRIBUTES_DEFAULT); }