mirror of https://github.com/M66B/FairEmail.git
Added enable/disable sync subfolders
This commit is contained in:
parent
a5ef19b46d
commit
83714160d3
|
@ -41,6 +41,7 @@ import android.util.TypedValue;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.view.SubMenu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
|
@ -495,8 +496,14 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||||
for (TupleFolderEx child : folder.child_refs)
|
for (TupleFolderEx child : folder.child_refs)
|
||||||
if (child.selectable)
|
if (child.selectable)
|
||||||
childs++;
|
childs++;
|
||||||
if (childs > 0)
|
if (childs > 0) {
|
||||||
popupMenu.getMenu().add(Menu.NONE, R.string.title_synchronize_childs, order++, R.string.title_synchronize_childs);
|
SubMenu submenu = popupMenu.getMenu()
|
||||||
|
.addSubMenu(Menu.NONE, Menu.NONE, order++, R.string.title_synchronize_childs);
|
||||||
|
|
||||||
|
submenu.add(Menu.FIRST, R.string.title_synchronize_now, 1, R.string.title_synchronize_now);
|
||||||
|
submenu.add(Menu.FIRST, R.string.title_enable, 2, R.string.title_enable);
|
||||||
|
submenu.add(Menu.FIRST, R.string.title_disable, 3, R.string.title_disable);
|
||||||
|
}
|
||||||
|
|
||||||
if (folder.selectable) {
|
if (folder.selectable) {
|
||||||
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
|
if (folder.account != null && folder.accountProtocol == EntityAccount.TYPE_IMAP) {
|
||||||
|
@ -566,13 +573,26 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||||
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
public boolean onMenuItemClick(MenuItem item) {
|
||||||
|
if (item.getGroupId() == Menu.FIRST) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.string.title_synchronize_now:
|
||||||
|
onActionSync(true);
|
||||||
|
return true;
|
||||||
|
case R.string.title_enable:
|
||||||
|
onActionEnable(true);
|
||||||
|
return true;
|
||||||
|
case R.string.title_disable:
|
||||||
|
onActionEnable(false);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.string.title_synchronize_now:
|
case R.string.title_synchronize_now:
|
||||||
onActionSync(false);
|
onActionSync(false);
|
||||||
return true;
|
return true;
|
||||||
case R.string.title_synchronize_childs:
|
|
||||||
onActionSync(true);
|
|
||||||
return true;
|
|
||||||
|
|
||||||
case R.string.title_synchronize_more:
|
case R.string.title_synchronize_more:
|
||||||
onActionSyncMore();
|
onActionSyncMore();
|
||||||
|
@ -652,6 +672,46 @@ public class AdapterFolder extends RecyclerView.Adapter<AdapterFolder.ViewHolder
|
||||||
parentFragment.onActivityResult(FragmentFolders.REQUEST_SYNC, RESULT_OK, data);
|
parentFragment.onActivityResult(FragmentFolders.REQUEST_SYNC, RESULT_OK, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void onActionEnable(boolean enabled) {
|
||||||
|
Bundle args = new Bundle();
|
||||||
|
args.putLong("id", folder.id);
|
||||||
|
args.putLong("account", folder.account);
|
||||||
|
args.putBoolean("enabled", enabled);
|
||||||
|
|
||||||
|
new SimpleTask<Void>() {
|
||||||
|
@Override
|
||||||
|
protected Void onExecute(Context context, Bundle args) throws Throwable {
|
||||||
|
long id = args.getLong("id");
|
||||||
|
long aid = args.getLong("account");
|
||||||
|
boolean enabled = args.getBoolean("enabled");
|
||||||
|
|
||||||
|
DB db = DB.getInstance(context);
|
||||||
|
try {
|
||||||
|
db.beginTransaction();
|
||||||
|
List<EntityFolder> childs = db.folder().getChildFolders(id);
|
||||||
|
if (childs == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
for (EntityFolder child : childs)
|
||||||
|
db.folder().setFolderSynchronize(child.id, enabled);
|
||||||
|
|
||||||
|
db.setTransactionSuccessful();
|
||||||
|
} finally {
|
||||||
|
db.endTransaction();
|
||||||
|
}
|
||||||
|
|
||||||
|
ServiceSynchronize.reload(context, aid, false, "child sync=" + enabled);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onException(Bundle args, Throwable ex) {
|
||||||
|
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
|
||||||
|
}
|
||||||
|
}.execute(context, owner, args, "enable");
|
||||||
|
}
|
||||||
|
|
||||||
private void onActionSyncMore() {
|
private void onActionSyncMore() {
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putLong("folder", folder.id);
|
args.putLong("folder", folder.id);
|
||||||
|
|
Loading…
Reference in New Issue