mirror of https://github.com/M66B/FairEmail.git
Refactoring
This commit is contained in:
parent
11a79c9e41
commit
acbc601b56
|
@ -24,10 +24,12 @@ import android.app.NotificationChannel;
|
|||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
@ -149,6 +151,13 @@ public class EntityAccount extends EntityOrder implements Serializable {
|
|||
return "imap.gmail.com".equalsIgnoreCase(host);
|
||||
}
|
||||
|
||||
boolean isTransient(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean enabled = prefs.getBoolean("enabled", true);
|
||||
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
|
||||
return (!enabled || this.ondemand || (pollInterval > 0 && !this.poll_exempted));
|
||||
}
|
||||
|
||||
String getProtocol() {
|
||||
switch (protocol) {
|
||||
case TYPE_IMAP:
|
||||
|
|
|
@ -391,8 +391,7 @@ public class FragmentAccounts extends FragmentBase {
|
|||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
now = false;
|
||||
if (enabled && !account.ondemand &&
|
||||
(pollInterval == 0 || account.poll_exempted))
|
||||
if (!account.isTransient(context))
|
||||
force = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -398,8 +398,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
now = false;
|
||||
if (enabled && !account.ondemand &&
|
||||
(pollInterval == 0 || account.poll_exempted))
|
||||
if (!account.isTransient(context))
|
||||
force = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1483,8 +1483,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
|
|||
EntityAccount account = db.account().getAccount(folder.account);
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
now = false;
|
||||
if (enabled && !account.ondemand && folder.synchronize &&
|
||||
(pollInterval == 0 || account.poll_exempted))
|
||||
if (!account.isTransient(context))
|
||||
force = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -234,7 +234,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
Log.d("### evaluating " + current);
|
||||
if (current.accountState.shouldRun(current.enabled))
|
||||
runService = true;
|
||||
if (!isTransient(current.accountState) &&
|
||||
if (!current.accountState.isTransient(ServiceSynchronize.this) &&
|
||||
("connected".equals(current.accountState.state) || current.accountState.backoff_until != null))
|
||||
accounts++;
|
||||
if (current.accountState.synchronize)
|
||||
|
@ -973,7 +973,8 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
if (e.getMessageType() == StoreEvent.NOTICE) {
|
||||
EntityLog.log(ServiceSynchronize.this, account.name + " notice: " + message);
|
||||
|
||||
if ("Still here".equals(message) && !isTransient(account)) {
|
||||
if ("Still here".equals(message) &&
|
||||
!account.isTransient(ServiceSynchronize.this)) {
|
||||
long now = new Date().getTime();
|
||||
if (now - start < STILL_THERE_THRESHOLD)
|
||||
optimizeAccount(account, message);
|
||||
|
@ -1892,7 +1893,7 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
} else {
|
||||
// Cancel transient sync operations
|
||||
if (isTransient(account)) {
|
||||
if (account.isTransient(this)) {
|
||||
List<EntityOperation> syncs = db.operation().getOperations(account.id, EntityOperation.SYNC);
|
||||
if (syncs != null) {
|
||||
for (EntityOperation op : syncs) {
|
||||
|
@ -1943,13 +1944,6 @@ public class ServiceSynchronize extends ServiceBase implements SharedPreferences
|
|||
}
|
||||
}
|
||||
|
||||
private boolean isTransient(EntityAccount account) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean enabled = prefs.getBoolean("enabled", true);
|
||||
int pollInterval = prefs.getInt("poll_interval", DEFAULT_POLL_INTERVAL);
|
||||
return (!enabled || account.ondemand || (pollInterval > 0 && !account.poll_exempted));
|
||||
}
|
||||
|
||||
private void optimizeAccount(EntityAccount account, String reason) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
boolean auto_optimize = prefs.getBoolean("auto_optimize", false);
|
||||
|
|
Loading…
Reference in New Issue