mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-06 00:53:26 +02:00
Refactoring
This commit is contained in:
@@ -142,9 +142,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
EntityLog.log(this, "Service create version=" + BuildConfig.VERSION_NAME);
|
||||
super.onCreate();
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean background_service = prefs.getBoolean("background_service", false);
|
||||
if (background_service)
|
||||
if (isBackgroundService(this))
|
||||
stopForeground(true);
|
||||
else
|
||||
startForeground(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(null, null).build());
|
||||
@@ -165,6 +163,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||
registerReceiver(idleModeChangedReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
|
||||
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
DB db = DB.getInstance(this);
|
||||
|
||||
db.account().liveAccountState().observe(this, new Observer<List<TupleAccountState>>() {
|
||||
@@ -705,9 +705,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean background_service = prefs.getBoolean("background_service", false);
|
||||
if (background_service)
|
||||
if (isBackgroundService(this))
|
||||
stopForeground(true);
|
||||
else
|
||||
startForeground(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(null, null).build());
|
||||
@@ -2254,11 +2252,17 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
||||
}
|
||||
|
||||
private static void start(Context context, Intent intent) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean background_service = prefs.getBoolean("background_service", false);
|
||||
if (background_service)
|
||||
if (isBackgroundService(context))
|
||||
context.startService(intent);
|
||||
else
|
||||
ContextCompat.startForegroundService(context, intent);
|
||||
}
|
||||
|
||||
private static boolean isBackgroundService(Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
return false;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return prefs.getBoolean("background_service", false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user