Added apply to all user folders

This commit is contained in:
M66B
2019-10-19 17:01:59 +02:00
parent c6ff0f3149
commit 4ce024991a
5 changed files with 168 additions and 0 deletions

View File

@@ -19,7 +19,9 @@ package eu.faircode.email;
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
@@ -32,11 +34,15 @@ import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentTransaction;
@@ -401,6 +407,8 @@ public class FragmentFolders extends FragmentBase {
public void onPrepareOptionsMenu(Menu menu) {
menu.findItem(R.id.menu_compact).setChecked(compact);
menu.findItem(R.id.menu_show_hidden).setChecked(show_hidden);
menu.findItem(R.id.menu_apply_all).setVisible(account >= 0);
super.onPrepareOptionsMenu(menu);
}
@@ -413,6 +421,9 @@ public class FragmentFolders extends FragmentBase {
case R.id.menu_show_hidden:
onMenuShowHidden();
return true;
case R.id.menu_apply_all:
onMenuApplyToAll();
return true;
default:
return super.onOptionsItemSelected(item);
}
@@ -434,6 +445,15 @@ public class FragmentFolders extends FragmentBase {
adapter.setShowHidden(show_hidden);
}
private void onMenuApplyToAll() {
Bundle args = new Bundle();
args.putLong("account", account);
FragmentDialogApply fragment = new FragmentDialogApply();
fragment.setArguments(args);
fragment.show(getParentFragmentManager(), "folders:apply");
}
@Override
public void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@@ -596,4 +616,62 @@ public class FragmentFolders extends FragmentBase {
}
}.execute(this, args, "folder:delete");
}
public static class FragmentDialogApply extends FragmentDialogBase {
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_folder_all, null);
final EditText etSyncDays = view.findViewById(R.id.etSyncDays);
final EditText etKeepDays = view.findViewById(R.id.etKeepDays);
final CheckBox cbKeepAll = view.findViewById(R.id.cbKeepAll);
cbKeepAll.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
etKeepDays.setEnabled(!isChecked);
}
});
return new AlertDialog.Builder(getContext())
.setView(view)
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Bundle args = getArguments();
args.putString("sync", etSyncDays.getText().toString());
args.putString("keep", cbKeepAll.isChecked()
? Integer.toString(Integer.MAX_VALUE)
: etKeepDays.getText().toString());
new SimpleTask<Void>() {
@Override
protected Void onExecute(Context context, Bundle args) throws Throwable {
long account = args.getLong("account");
String sync = args.getString("sync");
String keep = args.getString("keep");
if (TextUtils.isEmpty(sync))
sync = "7";
if (TextUtils.isEmpty(keep))
keep = "30";
DB db = DB.getInstance(context);
db.folder().setFolderProperties(
account, Integer.parseInt(sync), Integer.parseInt(keep));
return null;
}
@Override
protected void onException(Bundle args, Throwable ex) {
Helper.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(FragmentDialogApply.this, args, "folders:all");
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
}
}