mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-25 17:27:00 +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) {
|
} else if (version < 1124) {
|
||||||
editor.remove("experiments");
|
editor.remove("experiments");
|
||||||
} else if (version < 1181) {
|
} 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");
|
editor.remove("background_service");
|
||||||
} else if (version < 1195)
|
} else if (version < 1195)
|
||||||
editor.remove("auto_optimize");
|
editor.remove("auto_optimize");
|
||||||
|
@ -351,7 +351,7 @@ public class ApplicationEx extends Application implements SharedPreferences.OnSh
|
||||||
editor.putBoolean("beige", false);
|
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");
|
editor.remove("background_service");
|
||||||
|
|
||||||
if (version < BuildConfig.VERSION_CODE)
|
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);
|
EntityLog.log(this, "Service create version=" + BuildConfig.VERSION_NAME);
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
|
||||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
if (isBackgroundService(this))
|
||||||
boolean background_service = prefs.getBoolean("background_service", false);
|
|
||||||
if (background_service)
|
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
else
|
else
|
||||||
startForeground(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(null, null).build());
|
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)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
|
||||||
registerReceiver(idleModeChangedReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
|
registerReceiver(idleModeChangedReceiver, new IntentFilter(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED));
|
||||||
|
|
||||||
|
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
|
|
||||||
DB db = DB.getInstance(this);
|
DB db = DB.getInstance(this);
|
||||||
|
|
||||||
db.account().liveAccountState().observe(this, new Observer<List<TupleAccountState>>() {
|
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);
|
super.onStartCommand(intent, flags, startId);
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
if (isBackgroundService(this))
|
||||||
boolean background_service = prefs.getBoolean("background_service", false);
|
|
||||||
if (background_service)
|
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
else
|
else
|
||||||
startForeground(Helper.NOTIFICATION_SYNCHRONIZE, getNotificationService(null, null).build());
|
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) {
|
private static void start(Context context, Intent intent) {
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
if (isBackgroundService(context))
|
||||||
boolean background_service = prefs.getBoolean("background_service", false);
|
|
||||||
if (background_service)
|
|
||||||
context.startService(intent);
|
context.startService(intent);
|
||||||
else
|
else
|
||||||
ContextCompat.startForegroundService(context, intent);
|
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