mirror of https://github.com/M66B/FairEmail.git
Sync when account connected
This commit is contained in:
parent
a0038c41da
commit
01c1d76a48
|
@ -432,11 +432,23 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||||
if (!Helper.getNetworkState(context).isSuitable())
|
if (!Helper.getNetworkState(context).isSuitable())
|
||||||
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
||||||
|
|
||||||
|
boolean now = true;
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
|
||||||
EntityOperation.sync(context, fid, true);
|
EntityFolder folder = db.folder().getFolder(fid);
|
||||||
|
if (folder == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
EntityOperation.sync(context, folder.id, true);
|
||||||
|
|
||||||
|
if (folder.account != null) {
|
||||||
|
EntityAccount account = db.account().getAccount(folder.account);
|
||||||
|
if (account != null && !"connected".equals(account.state))
|
||||||
|
now = false;
|
||||||
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
|
|
||||||
|
@ -444,6 +456,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!now) {
|
||||||
|
ServiceSynchronize.reset(context);
|
||||||
|
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2169,7 +2169,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
||||||
return null;
|
return null;
|
||||||
db.message().deleteMessage(id);
|
db.message().deleteMessage(id);
|
||||||
|
|
||||||
EntityOperation.sync(context, message.folder, true);
|
EntityOperation.sync(context, message.folder, false);
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class FragmentFolder extends FragmentBase {
|
||||||
|
|
||||||
db.message().deleteMessagesBefore(id, keep_time);
|
db.message().deleteMessagesBefore(id, keep_time);
|
||||||
|
|
||||||
EntityOperation.sync(context, folder.id, true);
|
EntityOperation.sync(context, folder.id, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
|
|
|
@ -317,6 +317,8 @@ public class FragmentFolders extends FragmentBase {
|
||||||
if (!Helper.getNetworkState(context).isSuitable())
|
if (!Helper.getNetworkState(context).isSuitable())
|
||||||
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
||||||
|
|
||||||
|
boolean now = true;
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
@ -324,8 +326,15 @@ public class FragmentFolders extends FragmentBase {
|
||||||
if (aid < 0) {
|
if (aid < 0) {
|
||||||
// Unified inbox
|
// Unified inbox
|
||||||
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified();
|
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified();
|
||||||
for (EntityFolder folder : folders)
|
for (EntityFolder folder : folders) {
|
||||||
EntityOperation.sync(context, folder.id, true);
|
EntityOperation.sync(context, folder.id, true);
|
||||||
|
|
||||||
|
if (folder.account != null) {
|
||||||
|
EntityAccount account = db.account().getAccount(folder.account);
|
||||||
|
if (account != null && !"connected".equals(account.state))
|
||||||
|
now = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Folder list
|
// Folder list
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
|
@ -341,6 +350,11 @@ public class FragmentFolders extends FragmentBase {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!now) {
|
||||||
|
ServiceSynchronize.reset(context);
|
||||||
|
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -630,6 +630,8 @@ public class FragmentMessages extends FragmentBase {
|
||||||
if (!Helper.getNetworkState(context).isSuitable())
|
if (!Helper.getNetworkState(context).isSuitable())
|
||||||
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
|
||||||
|
|
||||||
|
boolean now = true;
|
||||||
|
|
||||||
DB db = DB.getInstance(context);
|
DB db = DB.getInstance(context);
|
||||||
try {
|
try {
|
||||||
db.beginTransaction();
|
db.beginTransaction();
|
||||||
|
@ -642,14 +644,27 @@ public class FragmentMessages extends FragmentBase {
|
||||||
if (folder != null)
|
if (folder != null)
|
||||||
folders.add(folder);
|
folders.add(folder);
|
||||||
}
|
}
|
||||||
for (EntityFolder folder : folders)
|
|
||||||
|
for (EntityFolder folder : folders) {
|
||||||
EntityOperation.sync(context, folder.id, true);
|
EntityOperation.sync(context, folder.id, true);
|
||||||
|
|
||||||
|
if (folder.account != null) {
|
||||||
|
EntityAccount account = db.account().getAccount(folder.account);
|
||||||
|
if (account != null && !"connected".equals(account.state))
|
||||||
|
now = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
db.setTransactionSuccessful();
|
db.setTransactionSuccessful();
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction();
|
db.endTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!now) {
|
||||||
|
ServiceSynchronize.reset(context);
|
||||||
|
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1732,7 +1747,7 @@ public class FragmentMessages extends FragmentBase {
|
||||||
|
|
||||||
boolean refreshing = false;
|
boolean refreshing = false;
|
||||||
for (TupleFolderEx folder : folders)
|
for (TupleFolderEx folder : folders)
|
||||||
if (folder.sync_state != null) {
|
if (folder.sync_state != null && (folder.account == null || "connected".equals(folder.accountState))) {
|
||||||
refreshing = true;
|
refreshing = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -371,6 +371,7 @@
|
||||||
<string name="title_no_stream">An outdated app sent a file path instead of a file stream</string>
|
<string name="title_no_stream">An outdated app sent a file path instead of a file stream</string>
|
||||||
<string name="title_no_contacts">Contact picker not available</string>
|
<string name="title_no_contacts">Contact picker not available</string>
|
||||||
<string name="title_no_internet">No or no suitable internet connection</string>
|
<string name="title_no_internet">No or no suitable internet connection</string>
|
||||||
|
<string name="title_no_connection">Synchronization will be performed on next account connection</string>
|
||||||
<string name="title_no_folder">Folder does not exist</string>
|
<string name="title_no_folder">Folder does not exist</string>
|
||||||
<string name="title_accross_remark">Messages moved across accounts will be downloaded again resulting in extra data usage</string>
|
<string name="title_accross_remark">Messages moved across accounts will be downloaded again resulting in extra data usage</string>
|
||||||
<string name="title_raw_saved">Raw message saved</string>
|
<string name="title_raw_saved">Raw message saved</string>
|
||||||
|
|
Loading…
Reference in New Issue