From 3313e944ed5e25ec102c41b445b3cb4697116574 Mon Sep 17 00:00:00 2001 From: M66B Date: Mon, 6 Aug 2018 10:02:47 +0000 Subject: [PATCH] Primary depends on synchronize --- .../eu/faircode/email/FragmentAccount.java | 19 ++++++++++++++----- .../eu/faircode/email/FragmentIdentity.java | 18 +++++++++++++----- app/src/main/res/layout/fragment_account.xml | 12 ++++++------ app/src/main/res/layout/fragment_identity.xml | 12 ++++++------ 4 files changed, 39 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index 08bb2771..6333d3b6 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -37,6 +37,7 @@ import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.Button; import android.widget.CheckBox; +import android.widget.CompoundButton; import android.widget.EditText; import android.widget.ProgressBar; import android.widget.Spinner; @@ -63,8 +64,8 @@ public class FragmentAccount extends FragmentEx { private EditText etPort; private EditText etUser; private TextInputLayout tilPassword; - private CheckBox cbPrimary; private CheckBox cbSynchronize; + private CheckBox cbPrimary; private Button btnOk; private ProgressBar pbCheck; // TODO: loading spinner @@ -99,8 +100,8 @@ public class FragmentAccount extends FragmentEx { etPort = view.findViewById(R.id.etPort); etUser = view.findViewById(R.id.etUser); tilPassword = view.findViewById(R.id.tilPassword); - cbPrimary = view.findViewById(R.id.cbPrimary); cbSynchronize = view.findViewById(R.id.cbSynchronize); + cbPrimary = view.findViewById(R.id.cbPrimary); btnOk = view.findViewById(R.id.btnOk); pbCheck = view.findViewById(R.id.pbCheck); @@ -128,6 +129,13 @@ public class FragmentAccount extends FragmentEx { pbCheck.setVisibility(View.GONE); + cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + cbPrimary.setEnabled(checked); + } + }); + btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -141,8 +149,8 @@ public class FragmentAccount extends FragmentEx { args.putString("port", etPort.getText().toString()); args.putString("user", etUser.getText().toString()); args.putString("password", tilPassword.getEditText().getText().toString()); - args.putBoolean("primary", cbPrimary.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked()); + args.putBoolean("primary", cbPrimary.isChecked()); getLoaderManager().restartLoader(ActivityView.LOADER_ACCOUNT_PUT, args, putLoaderCallbacks).forceLoad(); } @@ -156,8 +164,9 @@ public class FragmentAccount extends FragmentEx { etPort.setText(account == null ? null : Long.toString(account.port)); etUser.setText(account == null ? null : account.user); tilPassword.getEditText().setText(account == null ? null : account.password); - cbPrimary.setChecked(account == null ? true : account.primary); cbSynchronize.setChecked(account == null ? true : account.synchronize); + cbPrimary.setChecked(account == null ? true : account.primary); + cbPrimary.setEnabled(account == null ? true : account.synchronize); } }); @@ -198,8 +207,8 @@ public class FragmentAccount extends FragmentEx { account.port = Integer.parseInt(port); account.user = user; account.password = Objects.requireNonNull(args.getString("password")); - account.primary = args.getBoolean("primary"); account.synchronize = args.getBoolean("synchronize"); + account.primary = (account.synchronize && args.getBoolean("primary")); // Check IMAP server List folders = new ArrayList<>(); diff --git a/app/src/main/java/eu/faircode/email/FragmentIdentity.java b/app/src/main/java/eu/faircode/email/FragmentIdentity.java index ffb96e8c..624b10af 100644 --- a/app/src/main/java/eu/faircode/email/FragmentIdentity.java +++ b/app/src/main/java/eu/faircode/email/FragmentIdentity.java @@ -64,8 +64,8 @@ public class FragmentIdentity extends FragmentEx { private EditText etPort; private EditText etUser; private TextInputLayout tilPassword; - private CheckBox cbPrimary; private CheckBox cbSynchronize; + private CheckBox cbPrimary; private Button btnOk; private ProgressBar pbCheck; // TODO: loading spinner @@ -95,8 +95,8 @@ public class FragmentIdentity extends FragmentEx { etPort = view.findViewById(R.id.etPort); etUser = view.findViewById(R.id.etUser); tilPassword = view.findViewById(R.id.tilPassword); - cbPrimary = view.findViewById(R.id.cbPrimary); cbSynchronize = view.findViewById(R.id.cbSynchronize); + cbPrimary = view.findViewById(R.id.cbPrimary); btnOk = view.findViewById(R.id.btnOk); pbCheck = view.findViewById(R.id.pbCheck); @@ -146,6 +146,13 @@ public class FragmentIdentity extends FragmentEx { pbCheck.setVisibility(View.GONE); + cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + cbPrimary.setEnabled(checked); + } + }); + btnOk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -162,8 +169,8 @@ public class FragmentIdentity extends FragmentEx { args.putString("port", etPort.getText().toString()); args.putString("user", etUser.getText().toString()); args.putString("password", tilPassword.getEditText().getText().toString()); - args.putBoolean("primary", cbPrimary.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked()); + args.putBoolean("primary", cbPrimary.isChecked()); getLoaderManager().restartLoader(ActivityView.LOADER_IDENTITY_PUT, args, putLoaderCallbacks).forceLoad(); } @@ -180,8 +187,9 @@ public class FragmentIdentity extends FragmentEx { etPort.setText(identity == null ? null : Long.toString(identity.port)); etUser.setText(identity == null ? null : identity.user); tilPassword.getEditText().setText(identity == null ? null : identity.password); - cbPrimary.setChecked(identity == null ? true : identity.primary); cbSynchronize.setChecked(identity == null ? true : identity.synchronize); + cbPrimary.setChecked(identity == null ? true : identity.primary); + cbPrimary.setEnabled(identity == null ? true : identity.synchronize); } }); @@ -226,8 +234,8 @@ public class FragmentIdentity extends FragmentEx { identity.starttls = starttls; identity.user = Objects.requireNonNull(args.getString("user")); identity.password = Objects.requireNonNull(args.getString("password")); - identity.primary = args.getBoolean("primary"); identity.synchronize = args.getBoolean("synchronize"); + identity.primary = (identity.synchronize && args.getBoolean("primary")); if (TextUtils.isEmpty(identity.name)) throw new IllegalArgumentException(getContext().getString(R.string.title_no_name)); diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 9b659957..93aea183 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -159,22 +159,22 @@ + app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />