Added synchronize all

pull/156/head
M66B 5 years ago
parent 5501318b79
commit 857bc5f409

@ -266,7 +266,7 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
ivSync.setImageResource(folder.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24); ivSync.setImageResource(folder.synchronize ? R.drawable.baseline_sync_24 : R.drawable.baseline_sync_disabled_24);
} }
ivSync.setImageTintList(ColorStateList.valueOf( ivSync.setImageTintList(ColorStateList.valueOf(
folder.synchronize && folder.initialize && !EntityFolder.OUTBOX.equals(folder.type) folder.synchronize && folder.initialize != 0 && !EntityFolder.OUTBOX.equals(folder.type)
? colorUnread : textColorSecondary)); ? colorUnread : textColorSecondary));
tvKeywords.setText(TextUtils.join(" ", folder.keywords)); tvKeywords.setText(TextUtils.join(" ", folder.keywords));
@ -347,40 +347,41 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view); PopupMenuLifecycle popupMenu = new PopupMenuLifecycle(context, powner, view);
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_now, 1, R.string.title_synchronize_now); popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_now, 1, R.string.title_synchronize_now);
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_all, 2, R.string.title_synchronize_all);
if (folder.account != null) { if (folder.account != null) {
popupMenu.getMenu().add(Menu.NONE, R.string.title_unified_folder, 2, R.string.title_unified_folder) popupMenu.getMenu().add(Menu.NONE, R.string.title_unified_folder, 3, R.string.title_unified_folder)
.setCheckable(true).setChecked(folder.unified); .setCheckable(true).setChecked(folder.unified);
popupMenu.getMenu().add(Menu.NONE, R.string.title_navigation_folder, 3, R.string.title_navigation_folder) popupMenu.getMenu().add(Menu.NONE, R.string.title_navigation_folder, 4, R.string.title_navigation_folder)
.setCheckable(true).setChecked(folder.navigation); .setCheckable(true).setChecked(folder.navigation);
popupMenu.getMenu().add(Menu.NONE, R.string.title_notify_folder, 4, R.string.title_notify_folder) popupMenu.getMenu().add(Menu.NONE, R.string.title_notify_folder, 5, R.string.title_notify_folder)
.setCheckable(true).setChecked(folder.notify); .setCheckable(true).setChecked(folder.notify);
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, 5, R.string.title_synchronize_enabled) popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_enabled, 6, R.string.title_synchronize_enabled)
.setCheckable(true).setChecked(folder.synchronize); .setCheckable(true).setChecked(folder.synchronize);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_local, 6, R.string.title_delete_local); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_local, 7, R.string.title_delete_local);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_browsed, 7, R.string.title_delete_browsed); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_browsed, 8, R.string.title_delete_browsed);
} }
if (EntityFolder.TRASH.equals(folder.type)) if (EntityFolder.TRASH.equals(folder.type))
popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_trash, 8, R.string.title_empty_trash); popupMenu.getMenu().add(Menu.NONE, R.string.title_empty_trash, 9, R.string.title_empty_trash);
if (folder.account != null) { if (folder.account != null) {
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 9, R.string.title_edit_rules); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_rules, 10, R.string.title_edit_rules);
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, 10, R.string.title_edit_properties); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_properties, 11, R.string.title_edit_properties);
if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (folder.notify && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
String channelId = EntityFolder.getNotificationChannelId(folder.id); String channelId = EntityFolder.getNotificationChannelId(folder.id);
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = nm.getNotificationChannel(channelId); NotificationChannel channel = nm.getNotificationChannel(channelId);
if (channel == null) if (channel == null)
popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 11, R.string.title_create_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_create_channel, 12, R.string.title_create_channel);
else { else {
popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 12, R.string.title_edit_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_edit_channel, 13, R.string.title_edit_channel);
popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 13, R.string.title_delete_channel); popupMenu.getMenu().add(Menu.NONE, R.string.title_delete_channel, 14, R.string.title_delete_channel);
} }
} }
} }
@ -390,7 +391,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
public boolean onMenuItemClick(MenuItem item) { public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.string.title_synchronize_now: case R.string.title_synchronize_now:
onActionSynchronizeNow(); onActionSynchronizeNow(false);
return true;
case R.string.title_synchronize_all:
onActionSynchronizeAll();
return true; return true;
case R.string.title_unified_folder: case R.string.title_unified_folder:
@ -440,13 +445,15 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
} }
} }
private void onActionSynchronizeNow() { private void onActionSynchronizeNow(boolean all) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putBoolean("all", all);
args.putLong("folder", folder.id); args.putLong("folder", folder.id);
new SimpleTask<Void>() { new SimpleTask<Void>() {
@Override @Override
protected Void onExecute(Context context, Bundle args) { protected Void onExecute(Context context, Bundle args) {
boolean all = args.getBoolean("all");
long fid = args.getLong("folder"); long fid = args.getLong("folder");
if (!ConnectionHelper.getNetworkState(context).isSuitable()) if (!ConnectionHelper.getNetworkState(context).isSuitable())
@ -462,6 +469,11 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
if (folder == null) if (folder == null)
return null; return null;
if (all) {
db.folder().setFolderInitialize(folder.id, Integer.MAX_VALUE);
db.folder().setFolderKeep(folder.id, Integer.MAX_VALUE);
}
EntityOperation.sync(context, folder.id, true); EntityOperation.sync(context, folder.id, true);
if (folder.account != null) { if (folder.account != null) {
@ -509,6 +521,24 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
}.execute(context, owner, args, "folder:sync"); }.execute(context, owner, args, "folder:sync");
} }
private void onActionSynchronizeAll() {
View dview = LayoutInflater.from(context).inflate(R.layout.dialog_message, null);
TextView tvMessage = dview.findViewById(R.id.tvMessage);
tvMessage.setText(context.getString(R.string.title_ask_sync_all, folder.getDisplayName(context)));
new DialogBuilderLifecycle(context, owner)
.setView(dview)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
onActionSynchronizeNow(true);
}
})
.setNegativeButton(android.R.string.cancel, null)
.show();
}
private void onActionProperty(int property, boolean enabled) { private void onActionProperty(int property, boolean enabled) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLong("id", folder.id); args.putLong("id", folder.id);

@ -808,7 +808,7 @@ class Core {
sync_folders = true; sync_folders = true;
} else { } else {
names.add(folder.name); names.add(folder.name);
if (folder.initialize) if (folder.initialize != 0)
sync_folders = true; sync_folders = true;
} }
Log.i("Local folder count=" + names.size()); Log.i("Local folder count=" + names.size());
@ -960,7 +960,7 @@ class Core {
boolean download = jargs.optBoolean(2, false); boolean download = jargs.optBoolean(2, false);
boolean auto_delete = jargs.optBoolean(3, false); boolean auto_delete = jargs.optBoolean(3, false);
if (keep_days == sync_days) if (keep_days == sync_days && keep_days != Integer.MAX_VALUE)
keep_days++; keep_days++;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
@ -1235,8 +1235,8 @@ class Core {
} }
if (state.running) { if (state.running) {
folder.initialize = false; folder.initialize = 0;
db.folder().setFolderInitialized(folder.id); db.folder().setFolderInitialize(folder.id, 0);
} }
db.folder().setFolderSync(folder.id, new Date().getTime()); db.folder().setFolderSync(folder.id, new Date().getTime());

@ -249,8 +249,11 @@ public interface DaoFolder {
@Query("UPDATE folder SET name = :name WHERE account = :account AND name = :old") @Query("UPDATE folder SET name = :name WHERE account = :account AND name = :old")
int renameFolder(long account, String old, String name); int renameFolder(long account, String old, String name);
@Query("UPDATE folder SET initialize = 0 WHERE id = :id") @Query("UPDATE folder SET initialize = :days WHERE id = :id")
int setFolderInitialized(long id); int setFolderInitialize(long id, int days);
@Query("UPDATE folder SET keep_days = :days WHERE id = :id")
int setFolderKeep(long id, int days);
@Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id") @Query("UPDATE folder SET last_sync = :last_sync WHERE id = :id")
int setFolderSync(long id, long last_sync); int setFolderSync(long id, long last_sync);

@ -99,7 +99,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
public String[] keywords; public String[] keywords;
@NonNull @NonNull
public Boolean initialize = true; public Integer initialize = DEFAULT_KEEP;
public Boolean tbc; // to be created public Boolean tbc; // to be created
public Boolean tbd; // to be deleted public Boolean tbd; // to be deleted
public String state; public String state;
@ -189,7 +189,7 @@ public class EntityFolder extends EntityOrder implements Serializable {
} }
JSONArray jargs = new JSONArray(); JSONArray jargs = new JSONArray();
jargs.put(initialize ? keep_days : days); jargs.put(initialize == 0 ? days : Math.max(keep_days, initialize));
jargs.put(keep_days); jargs.put(keep_days);
jargs.put(download); jargs.put(download);
jargs.put(auto_delete); jargs.put(auto_delete);

@ -341,6 +341,7 @@
<string name="title_pop3_support">POP3 is not supported, see also the FAQ</string> <string name="title_pop3_support">POP3 is not supported, see also the FAQ</string>
<string name="title_synchronize_now">Synchronize now</string> <string name="title_synchronize_now">Synchronize now</string>
<string name="title_synchronize_all">Synchronize all</string>
<string name="title_synchronize_enabled">Synchronize</string> <string name="title_synchronize_enabled">Synchronize</string>
<string name="title_delete_local">Delete local messages</string> <string name="title_delete_local">Delete local messages</string>
<string name="title_delete_browsed">Delete browsed/searched messages</string> <string name="title_delete_browsed">Delete browsed/searched messages</string>
@ -457,6 +458,7 @@
<string name="title_ask_show_html">Showing the original message can leak privacy sensitive information</string> <string name="title_ask_show_html">Showing the original message can leak privacy sensitive information</string>
<string name="title_ask_show_image">Showing images can leak privacy sensitive information</string> <string name="title_ask_show_image">Showing images can leak privacy sensitive information</string>
<string name="title_ask_edit_ref">Edit reformatted replied/forwarded message text?</string> <string name="title_ask_edit_ref">Edit reformatted replied/forwarded message text?</string>
<string name="title_ask_sync_all">Synchronize all messages in %1$s?</string>
<string name="title_ask_delete_local">Delete only local messages which are stored on the remote server too?</string> <string name="title_ask_delete_local">Delete only local messages which are stored on the remote server too?</string>
<string name="title_ask_help">Help improve FairEmail</string> <string name="title_ask_help">Help improve FairEmail</string>
<string name="title_ask_reporting">Send error reports?</string> <string name="title_ask_reporting">Send error reports?</string>

Loading…
Cancel
Save