mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-24 16:53:37 +00:00
Refactoring
This commit is contained in:
parent
676fb4ff5e
commit
cdb86d2446
2 changed files with 15 additions and 11 deletions
|
@ -321,7 +321,7 @@ public class ApplicationEx extends Application implements SharedPreferences.OnSh
|
|||
} else if (version < 1124) {
|
||||
editor.remove("experiments");
|
||||
} else if (version < 1181) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
editor.remove("background_service");
|
||||
} else if (version < 1195)
|
||||
editor.remove("auto_optimize");
|
||||
|
@ -351,7 +351,7 @@ public class ApplicationEx extends Application implements SharedPreferences.OnSh
|
|||
editor.putBoolean("beige", false);
|
||||
}
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !BuildConfig.DEBUG)
|
||||
editor.remove("background_service");
|
||||
|
||||
if (version < BuildConfig.VERSION_CODE)
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue