From ef25812bfe4d8d99f5ee38ab1f476ec6eb491b50 Mon Sep 17 00:00:00 2001 From: M66B Date: Sat, 28 May 2022 10:46:22 +0200 Subject: [PATCH] Edit account primacy --- .../email/FragmentDialogEditName.java | 11 +++++++++-- .../eu/faircode/email/FragmentFolders.java | 19 ++++++++++++++++++- app/src/main/res/layout/dialog_edit_name.xml | 11 +++++++++++ 3 files changed, 38 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentDialogEditName.java b/app/src/main/java/eu/faircode/email/FragmentDialogEditName.java index c6ea8398fc..219affa894 100644 --- a/app/src/main/java/eu/faircode/email/FragmentDialogEditName.java +++ b/app/src/main/java/eu/faircode/email/FragmentDialogEditName.java @@ -26,6 +26,7 @@ import android.content.DialogInterface; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; +import android.widget.CheckBox; import android.widget.EditText; import androidx.annotation.NonNull; @@ -38,14 +39,20 @@ public class FragmentDialogEditName extends FragmentDialogBase { public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { View view = LayoutInflater.from(getContext()).inflate(R.layout.dialog_edit_name, null); final EditText etName = view.findViewById(R.id.etName); - etName.setText(getArguments().getString("name")); + final CheckBox cbPrimary = view.findViewById(R.id.cbPrimary); + + Bundle args = getArguments(); + etName.setText(args.getString("name")); + cbPrimary.setChecked(args.getBoolean("primary")); + cbPrimary.setVisibility(args.containsKey("primary") ? View.VISIBLE : View.GONE); return new AlertDialog.Builder(getContext()) .setView(view) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - getArguments().putString("name", etName.getText().toString()); + args.putString("name", etName.getText().toString()); + args.putBoolean("primary", cbPrimary.isChecked()); sendResult(RESULT_OK); } }) diff --git a/app/src/main/java/eu/faircode/email/FragmentFolders.java b/app/src/main/java/eu/faircode/email/FragmentFolders.java index ac6a0da44e..c1e12d6862 100644 --- a/app/src/main/java/eu/faircode/email/FragmentFolders.java +++ b/app/src/main/java/eu/faircode/email/FragmentFolders.java @@ -862,6 +862,7 @@ public class FragmentFolders extends FragmentBase { return; args.putString("name", account.name); + args.putBoolean("primary", account.primary); FragmentDialogEditName fragment = new FragmentDialogEditName(); fragment.setArguments(args); @@ -1352,12 +1353,28 @@ public class FragmentFolders extends FragmentBase { protected Void onExecute(Context context, Bundle args) { long id = args.getLong("id"); String name = args.getString("name"); + boolean primary = args.getBoolean("primary"); if (TextUtils.isEmpty(name)) return null; DB db = DB.getInstance(context); - db.account().setAccountName(id, name); + try { + db.beginTransaction(); + + EntityAccount account = db.account().getAccount(id); + if (account == null) + return null; + + db.account().setAccountName(account.id, name); + if (primary) + db.account().resetPrimary(); + db.account().setAccountPrimary(account.id, primary); + + db.setTransactionSuccessful(); + } finally { + db.endTransaction(); + } return null; } diff --git a/app/src/main/res/layout/dialog_edit_name.xml b/app/src/main/res/layout/dialog_edit_name.xml index 34df7528c8..395691177a 100644 --- a/app/src/main/res/layout/dialog_edit_name.xml +++ b/app/src/main/res/layout/dialog_edit_name.xml @@ -32,4 +32,15 @@ + + + \ No newline at end of file