Refactoring

pull/153/head
M66B 6 years ago
parent 872984b33c
commit 23fe035085

@ -540,7 +540,7 @@ public class ActivitySetup extends ActivityBilling implements FragmentManager.On
jexport.put("answers", janswers); jexport.put("answers", janswers);
jexport.put("settings", jsettings); jexport.put("settings", jsettings);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) 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(); ContentResolver resolver = context.getContentResolver();
DocumentFile file = DocumentFile.fromSingleUri(context, uri); 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 (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");
((ApplicationEx) getApplication()).channelsFromJSON(jchannels); ApplicationEx.channelsFromJSON(context, jchannels);
} }
db.setTransactionSuccessful(); db.setTransactionSuccessful();

@ -127,10 +127,10 @@ public class ApplicationEx extends Application {
} }
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public JSONArray channelsToJSON() throws JSONException { static JSONArray channelsToJSON(Context context) throws JSONException {
JSONArray jchannels = new JSONArray(); JSONArray jchannels = new JSONArray();
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
for (NotificationChannel channel : nm.getNotificationChannels()) for (NotificationChannel channel : nm.getNotificationChannels())
if (!DEFAULT_CHANNEL_NAMES.contains(channel.getId())) { if (!DEFAULT_CHANNEL_NAMES.contains(channel.getId())) {
JSONObject jchannel = new JSONObject(); JSONObject jchannel = new JSONObject();
@ -163,8 +163,8 @@ public class ApplicationEx extends Application {
} }
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public void channelsFromJSON(JSONArray jchannels) throws JSONException { static void channelsFromJSON(Context context, JSONArray jchannels) throws JSONException {
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
for (int c = 0; c < jchannels.length(); c++) { for (int c = 0; c < jchannels.length(); c++) {
JSONObject jchannel = (JSONObject) jchannels.get(c); JSONObject jchannel = (JSONObject) jchannels.get(c);
@ -189,7 +189,7 @@ public class ApplicationEx extends Application {
if (jchannel.has("sound") && !jchannel.isNull("sound")) { if (jchannel.has("sound") && !jchannel.isNull("sound")) {
Uri uri = Uri.parse(jchannel.getString("sound")); Uri uri = Uri.parse(jchannel.getString("sound"));
Ringtone ringtone = RingtoneManager.getRingtone(this, uri); Ringtone ringtone = RingtoneManager.getRingtone(context, uri);
if (ringtone != null) if (ringtone != null)
channel.setSound(uri, Notification.AUDIO_ATTRIBUTES_DEFAULT); channel.setSound(uri, Notification.AUDIO_ATTRIBUTES_DEFAULT);
} }

Loading…
Cancel
Save