Sync when account connected

This commit is contained in:
M66B 2019-04-11 17:47:58 +02:00
parent a0038c41da
commit 01c1d76a48
6 changed files with 53 additions and 6 deletions

View File

@ -432,11 +432,23 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (!Helper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
boolean now = true;
DB db = DB.getInstance(context);
try {
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();
@ -444,6 +456,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
db.endTransaction();
}
if (!now) {
ServiceSynchronize.reset(context);
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
}
return null;
}

View File

@ -2169,7 +2169,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
return null;
db.message().deleteMessage(id);
EntityOperation.sync(context, message.folder, true);
EntityOperation.sync(context, message.folder, false);
db.setTransactionSuccessful();
} finally {

View File

@ -252,7 +252,7 @@ public class FragmentFolder extends FragmentBase {
db.message().deleteMessagesBefore(id, keep_time);
EntityOperation.sync(context, folder.id, true);
EntityOperation.sync(context, folder.id, false);
}
db.setTransactionSuccessful();

View File

@ -317,6 +317,8 @@ public class FragmentFolders extends FragmentBase {
if (!Helper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
boolean now = true;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
@ -324,8 +326,15 @@ public class FragmentFolders extends FragmentBase {
if (aid < 0) {
// Unified inbox
List<EntityFolder> folders = db.folder().getFoldersSynchronizingUnified();
for (EntityFolder folder : folders)
for (EntityFolder folder : folders) {
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 {
// Folder list
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -341,6 +350,11 @@ public class FragmentFolders extends FragmentBase {
db.endTransaction();
}
if (!now) {
ServiceSynchronize.reset(context);
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
}
return null;
}

View File

@ -630,6 +630,8 @@ public class FragmentMessages extends FragmentBase {
if (!Helper.getNetworkState(context).isSuitable())
throw new IllegalArgumentException(context.getString(R.string.title_no_internet));
boolean now = true;
DB db = DB.getInstance(context);
try {
db.beginTransaction();
@ -642,14 +644,27 @@ public class FragmentMessages extends FragmentBase {
if (folder != null)
folders.add(folder);
}
for (EntityFolder folder : folders)
for (EntityFolder folder : folders) {
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();
} finally {
db.endTransaction();
}
if (!now) {
ServiceSynchronize.reset(context);
throw new IllegalArgumentException(context.getString(R.string.title_no_connection));
}
return null;
}
@ -1732,7 +1747,7 @@ public class FragmentMessages extends FragmentBase {
boolean refreshing = false;
for (TupleFolderEx folder : folders)
if (folder.sync_state != null) {
if (folder.sync_state != null && (folder.account == null || "connected".equals(folder.accountState))) {
refreshing = true;
break;
}

View File

@ -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_contacts">Contact picker not available</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_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>