mirror of https://github.com/M66B/FairEmail.git
Removed per account on demand sync
This commit is contained in:
parent
c268a83df7
commit
a54ae08fbc
|
@ -49,7 +49,7 @@ public class ActivityMain extends AppCompatActivity implements FragmentManager.O
|
|||
new SimpleTask<List<EntityAccount>>() {
|
||||
@Override
|
||||
protected List<EntityAccount> onExecute(Context context, Bundle args) {
|
||||
return DB.getInstance(context).account().getSynchronizingAccounts(true);
|
||||
return DB.getInstance(context).account().getSynchronizingAccounts();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,10 +32,8 @@ public interface DaoAccount {
|
|||
@Query("SELECT * FROM account")
|
||||
List<EntityAccount> getAccounts();
|
||||
|
||||
@Query("SELECT * FROM account" +
|
||||
" WHERE synchronize" +
|
||||
" AND (:all OR NOT ondemand)")
|
||||
List<EntityAccount> getSynchronizingAccounts(boolean all);
|
||||
@Query("SELECT * FROM account WHERE synchronize")
|
||||
List<EntityAccount> getSynchronizingAccounts();
|
||||
|
||||
@Query("SELECT * FROM account WHERE tbd = 1")
|
||||
List<EntityAccount> getAccountsTbd();
|
||||
|
@ -43,9 +41,7 @@ public interface DaoAccount {
|
|||
@Query("SELECT * FROM account")
|
||||
LiveData<List<EntityAccount>> liveAccounts();
|
||||
|
||||
@Query("SELECT * FROM account" +
|
||||
" WHERE synchronize")
|
||||
// including on demand
|
||||
@Query("SELECT * FROM account WHERE synchronize")
|
||||
LiveData<List<EntityAccount>> liveSynchronizingAccounts();
|
||||
|
||||
@Query("SELECT *" +
|
||||
|
@ -78,12 +74,11 @@ public interface DaoAccount {
|
|||
@Query("SELECT" +
|
||||
" (SELECT COUNT(account.id) FROM account" +
|
||||
" WHERE synchronize" +
|
||||
" AND NOT ondemand" +
|
||||
" AND state = 'connected') AS accounts" +
|
||||
", (SELECT COUNT(operation.id) FROM operation" +
|
||||
" JOIN folder ON folder.id = operation.folder" +
|
||||
" JOIN account ON account.id = folder.account" + // not outbox
|
||||
" WHERE account.synchronize) AS operations") // including on demand
|
||||
" WHERE account.synchronize) AS operations")
|
||||
LiveData<TupleAccountStats> liveStats();
|
||||
|
||||
@Query("SELECT account.id, swipe_left, l.type AS left_type, swipe_right, r.type AS right_type" +
|
||||
|
|
|
@ -36,8 +36,8 @@ public interface DaoFolder {
|
|||
@Query("SELECT folder.* FROM folder" +
|
||||
" JOIN account ON account.id = folder.account" +
|
||||
" WHERE folder.synchronize" +
|
||||
" AND (account.synchronize AND NOT account.ondemand)")
|
||||
List<EntityFolder> getFoldersAutoSync();
|
||||
" AND account.synchronize")
|
||||
List<EntityFolder> getSynchronizingFolders();
|
||||
|
||||
@Query("SELECT folder.* FROM folder" +
|
||||
" JOIN account ON account.id = folder.account" +
|
||||
|
@ -52,8 +52,7 @@ public interface DaoFolder {
|
|||
EntityFolder getBrowsableFolder(long folder, boolean search);
|
||||
|
||||
@Query("SELECT folder.*" +
|
||||
", account.name AS accountName, account.color AS accountColor" +
|
||||
", account.state AS accountState, account.ondemand AS accountOnDemand" +
|
||||
", account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
@ -68,8 +67,7 @@ public interface DaoFolder {
|
|||
LiveData<List<TupleFolderEx>> liveFolders(Long account);
|
||||
|
||||
@Query("SELECT folder.*" +
|
||||
", account.name AS accountName, account.color AS accountColor" +
|
||||
", account.state AS accountState, account.ondemand AS accountOnDemand" +
|
||||
", account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
@ -87,8 +85,7 @@ public interface DaoFolder {
|
|||
LiveData<EntityFolder> livePrimaryDrafts();
|
||||
|
||||
@Query("SELECT folder.*" +
|
||||
", account.name AS accountName, account.color AS accountColor" +
|
||||
", account.state AS accountState, account.ondemand AS accountOnDemand" +
|
||||
", account.name AS accountName, account.color AS accountColor, account.state AS accountState" +
|
||||
", COUNT(message.id) AS messages" +
|
||||
", SUM(CASE WHEN message.content = 1 THEN 1 ELSE 0 END) AS content" +
|
||||
", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
|
||||
|
|
|
@ -29,7 +29,7 @@ import androidx.room.Query;
|
|||
@Dao
|
||||
public interface DaoOperation {
|
||||
@Query("SELECT operation.*, account.name AS accountName, folder.name AS folderName" +
|
||||
" ,((account.synchronize IS NULL OR account.synchronize)" + // including on demand
|
||||
" ,((account.synchronize IS NULL OR account.synchronize)" +
|
||||
" AND (NOT folder.account IS NULL OR identity.synchronize IS NULL OR identity.synchronize)) AS synchronize" +
|
||||
" FROM operation" +
|
||||
" JOIN folder ON folder.id = operation.folder" +
|
||||
|
@ -50,7 +50,7 @@ public interface DaoOperation {
|
|||
" LEFT JOIN account ON account.id = message.account" +
|
||||
" LEFT JOIN identity ON identity.id = message.identity" +
|
||||
" WHERE operation.folder = :folder" +
|
||||
" AND (account.synchronize IS NULL OR account.synchronize)" + // including on demand
|
||||
" AND (account.synchronize IS NULL OR account.synchronize)" +
|
||||
" AND (NOT folder.account IS NULL OR identity.synchronize IS NULL OR identity.synchronize)" +
|
||||
" ORDER BY" +
|
||||
" CASE WHEN operation.name = '" + EntityOperation.SYNC + "' THEN" +
|
||||
|
|
|
@ -72,7 +72,7 @@ public class EntityAccount implements Serializable {
|
|||
@NonNull
|
||||
public Boolean synchronize;
|
||||
@NonNull
|
||||
public Boolean ondemand = false;
|
||||
public Boolean ondemand = false; // obsolete
|
||||
@NonNull
|
||||
public Boolean primary;
|
||||
@NonNull
|
||||
|
@ -131,7 +131,6 @@ public class EntityAccount implements Serializable {
|
|||
json.put("color", color);
|
||||
|
||||
json.put("synchronize", synchronize);
|
||||
json.put("ondemand", ondemand);
|
||||
json.put("primary", primary);
|
||||
json.put("notify", notify);
|
||||
json.put("browse", browse);
|
||||
|
@ -167,8 +166,6 @@ public class EntityAccount implements Serializable {
|
|||
account.color = json.getInt("color");
|
||||
|
||||
account.synchronize = json.getBoolean("synchronize");
|
||||
if (json.has("ondemand"))
|
||||
account.ondemand = json.getBoolean("ondemand");
|
||||
account.primary = json.getBoolean("primary");
|
||||
if (json.has("notify"))
|
||||
account.notify = json.getBoolean("notify");
|
||||
|
|
|
@ -115,7 +115,7 @@ public class EntityOperation {
|
|||
operation.created = new Date().getTime();
|
||||
operation.id = db.operation().insertOperation(operation);
|
||||
|
||||
if (account != null && (account.ondemand || !"connected".equals(account.state))) {
|
||||
if (account != null && !"connected".equals(account.state)) {
|
||||
db.folder().setFolderState(fid, "waiting");
|
||||
db.folder().setFolderSyncState(fid, "manual");
|
||||
} else
|
||||
|
@ -123,7 +123,7 @@ public class EntityOperation {
|
|||
|
||||
if (account == null) // Outbox
|
||||
ServiceSend.start(context);
|
||||
else if (account.ondemand || !"connected".equals(account.state))
|
||||
else if (!"connected".equals(account.state))
|
||||
ServiceUI.process(context, fid);
|
||||
|
||||
Log.i("Queued sync folder=" + folder);
|
||||
|
@ -255,7 +255,7 @@ public class EntityOperation {
|
|||
ServiceSend.start(context);
|
||||
else {
|
||||
EntityAccount account = db.account().getAccount(message.account);
|
||||
if (account.ondemand)
|
||||
if (account != null && !"connected".equals(account.state))
|
||||
ServiceUI.process(context, operation.folder);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,7 +109,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
|
||||
private Button btnAdvanced;
|
||||
private CheckBox cbSynchronize;
|
||||
private CheckBox cbOnDemand;
|
||||
private CheckBox cbPrimary;
|
||||
private CheckBox cbNotify;
|
||||
private CheckBox cbBrowse;
|
||||
|
@ -188,7 +187,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
|
||||
btnAdvanced = view.findViewById(R.id.btnAdvanced);
|
||||
cbSynchronize = view.findViewById(R.id.cbSynchronize);
|
||||
cbOnDemand = view.findViewById(R.id.cbOnDemand);
|
||||
cbPrimary = view.findViewById(R.id.cbPrimary);
|
||||
cbNotify = view.findViewById(R.id.cbNotify);
|
||||
cbBrowse = view.findViewById(R.id.cbBrowse);
|
||||
|
@ -390,7 +388,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
cbOnDemand.setEnabled(checked);
|
||||
cbPrimary.setEnabled(checked);
|
||||
}
|
||||
});
|
||||
|
@ -762,7 +759,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
args.putInt("color", color);
|
||||
|
||||
args.putBoolean("synchronize", cbSynchronize.isChecked());
|
||||
args.putBoolean("ondemand", cbOnDemand.isChecked());
|
||||
args.putBoolean("primary", cbPrimary.isChecked());
|
||||
args.putBoolean("notify", cbNotify.isChecked());
|
||||
args.putBoolean("browse", cbBrowse.isChecked());
|
||||
|
@ -812,7 +808,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
Integer color = args.getInt("color");
|
||||
|
||||
boolean synchronize = args.getBoolean("synchronize");
|
||||
boolean ondemand = args.getBoolean("ondemand");
|
||||
boolean primary = args.getBoolean("primary");
|
||||
boolean notify = args.getBoolean("notify");
|
||||
boolean browse = args.getBoolean("browse");
|
||||
|
@ -862,7 +857,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
boolean reload = (check || account == null ||
|
||||
!Objects.equals(account.prefix, prefix) ||
|
||||
account.synchronize != synchronize ||
|
||||
account.ondemand != ondemand ||
|
||||
!account.poll_interval.equals(Integer.parseInt(interval)));
|
||||
|
||||
Long last_connected = null;
|
||||
|
@ -934,7 +928,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
account.color = color;
|
||||
|
||||
account.synchronize = synchronize;
|
||||
account.ondemand = ondemand;
|
||||
account.primary = (account.synchronize && primary);
|
||||
account.notify = notify;
|
||||
account.browse = browse;
|
||||
|
@ -1157,7 +1150,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
cbNotify.setChecked(account == null ? false : account.notify);
|
||||
|
||||
cbSynchronize.setChecked(account == null ? true : account.synchronize);
|
||||
cbOnDemand.setChecked(account == null ? false : account.ondemand);
|
||||
cbPrimary.setChecked(account == null ? false : account.primary);
|
||||
cbBrowse.setChecked(account == null ? true : account.browse);
|
||||
etInterval.setText(account == null ? "" : Long.toString(account.poll_interval));
|
||||
|
@ -1198,7 +1190,6 @@ public class FragmentAccount extends FragmentBase {
|
|||
etRealm.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
|
||||
|
||||
setColor(color);
|
||||
cbOnDemand.setEnabled(cbSynchronize.isChecked());
|
||||
cbPrimary.setEnabled(cbSynchronize.isChecked());
|
||||
|
||||
// Consider previous check/save/delete as cancelled
|
||||
|
|
|
@ -303,7 +303,7 @@ public class FragmentFolders extends FragmentBase {
|
|||
} else {
|
||||
// Folder list
|
||||
EntityAccount account = db.account().getAccount(aid);
|
||||
if (account.ondemand)
|
||||
if (account != null && !"connected".equals(account.state))
|
||||
ServiceUI.fsync(context, aid);
|
||||
else
|
||||
ServiceSynchronize.reload(getContext(), "refresh folders");
|
||||
|
|
|
@ -966,7 +966,7 @@ public class FragmentMessages extends FragmentBase {
|
|||
if (result.hasTrash == null) result.hasTrash = false;
|
||||
if (result.hasJunk == null) result.hasJunk = false;
|
||||
|
||||
result.accounts = db.account().getSynchronizingAccounts(true);
|
||||
result.accounts = db.account().getSynchronizingAccounts();
|
||||
|
||||
final Collator collator = Collator.getInstance(Locale.getDefault());
|
||||
collator.setStrength(Collator.SECONDARY); // Case insensitive, process accents etc
|
||||
|
|
|
@ -267,7 +267,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
List<EntityFolder> folders = db.folder().getFoldersAutoSync();
|
||||
List<EntityFolder> folders = db.folder().getSynchronizingFolders();
|
||||
for (EntityFolder folder : folders)
|
||||
EntityOperation.sync(context, folder.id);
|
||||
return null;
|
||||
|
|
|
@ -405,7 +405,7 @@ public class FragmentSetup extends FragmentBase {
|
|||
@Override
|
||||
protected Void onExecute(Context context, Bundle args) {
|
||||
DB db = DB.getInstance(context);
|
||||
for (EntityFolder folder : db.folder().getFoldersAutoSync())
|
||||
for (EntityFolder folder : db.folder().getSynchronizingFolders())
|
||||
EntityOperation.sync(context, folder.id);
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -936,11 +936,6 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
return prefs.getBoolean("enabled", true);
|
||||
}
|
||||
|
||||
private boolean hasWork() {
|
||||
DB db = DB.getInstance(ServiceSynchronize.this);
|
||||
return (db.account().getSynchronizingAccounts(false).size() > 0);
|
||||
}
|
||||
|
||||
private void service_init() {
|
||||
EntityLog.log(ServiceSynchronize.this, "Service init");
|
||||
// Network events will manage the service
|
||||
|
@ -998,7 +993,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
}
|
||||
|
||||
// Start monitoring accounts
|
||||
List<EntityAccount> accounts = db.account().getSynchronizingAccounts(false);
|
||||
List<EntityAccount> accounts = db.account().getSynchronizingAccounts();
|
||||
for (final EntityAccount account : accounts) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O)
|
||||
if (account.notify)
|
||||
|
@ -1114,12 +1109,12 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
queued--;
|
||||
EntityLog.log(ServiceSynchronize.this, "Reload done queued=" + queued);
|
||||
|
||||
if (queued == 0 && !(isEnabled() && hasWork())) {
|
||||
if (queued == 0 && !isEnabled()) {
|
||||
try {
|
||||
Thread.sleep(STOP_DELAY);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
if (queued == 0 && !(isEnabled() && hasWork())) {
|
||||
if (queued == 0 && !isEnabled()) {
|
||||
EntityLog.log(ServiceSynchronize.this, "Service stop");
|
||||
stopSelf();
|
||||
}
|
||||
|
@ -1207,7 +1202,7 @@ public class ServiceSynchronize extends LifecycleService {
|
|||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean enabled = prefs.getBoolean("enabled", true);
|
||||
|
||||
int accounts = db.account().getSynchronizingAccounts(false).size();
|
||||
int accounts = db.account().getSynchronizingAccounts().size();
|
||||
|
||||
if (enabled && accounts > 0)
|
||||
ContextCompat.startForegroundService(context,
|
||||
|
|
|
@ -25,7 +25,6 @@ public class TupleFolderEx extends EntityFolder {
|
|||
public String accountName;
|
||||
public Integer accountColor;
|
||||
public String accountState;
|
||||
public Boolean accountOnDemand;
|
||||
public int messages;
|
||||
public int content;
|
||||
public int unseen;
|
||||
|
@ -45,7 +44,6 @@ public class TupleFolderEx extends EntityFolder {
|
|||
Objects.equals(accountName, other.accountName) &&
|
||||
Objects.equals(this.accountColor, other.accountColor) &&
|
||||
Objects.equals(accountState, other.accountState) &&
|
||||
Objects.equals(this.accountOnDemand, other.accountOnDemand) &&
|
||||
this.messages == other.messages &&
|
||||
this.content == other.content &&
|
||||
this.unseen == other.unseen);
|
||||
|
|
|
@ -331,15 +331,6 @@
|
|||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/btnAdvanced" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbOnDemand"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_synchronize_ondemand"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -347,7 +338,7 @@
|
|||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_primary_account"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/cbOnDemand" />
|
||||
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/cbNotify"
|
||||
|
@ -733,7 +724,7 @@
|
|||
android:layout_height="0dp"
|
||||
app:constraint_referenced_ids="
|
||||
tvPrefix,tvPrefixRemark,etPrefix,cbNotify,
|
||||
cbSynchronize,cbOnDemand,cbPrimary,
|
||||
cbSynchronize,cbPrimary,
|
||||
cbBrowse,tvBrowseHint,
|
||||
tvInterval,etInterval" />
|
||||
|
||||
|
|
|
@ -236,7 +236,6 @@
|
|||
<string name="title_authorizing">Authorizing account …</string>
|
||||
<string name="title_setup_advanced">Advanced</string>
|
||||
<string name="title_synchronize_account">Synchronize (receive messages)</string>
|
||||
<string name="title_synchronize_ondemand">Synchronize on demand (manual)</string>
|
||||
<string name="title_synchronize_identity">Synchronize (send messages)</string>
|
||||
<string name="title_primary_account">Primary (default account)</string>
|
||||
<string name="title_primary_identity">Primary (default identity)</string>
|
||||
|
|
Loading…
Reference in New Issue