From b5b805672df0f1c265ebb6f7fdbd0d57bbd5da04 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 26 Dec 2018 11:34:05 +0000 Subject: [PATCH] Revise account layout --- .../java/eu/faircode/email/EntityAccount.java | 20 ++- .../eu/faircode/email/FragmentAccount.java | 148 ++++++++++-------- app/src/main/res/layout/fragment_account.xml | 106 ++++++------- 3 files changed, 147 insertions(+), 127 deletions(-) diff --git a/app/src/main/java/eu/faircode/email/EntityAccount.java b/app/src/main/java/eu/faircode/email/EntityAccount.java index 9e12029b4c..8b759fd32d 100644 --- a/app/src/main/java/eu/faircode/email/EntityAccount.java +++ b/app/src/main/java/eu/faircode/email/EntityAccount.java @@ -43,9 +43,9 @@ public class EntityAccount { @PrimaryKey(autoGenerate = true) public Long id; - public String name; - public String signature; // obsolete - public String prefix; // namespace + + @NonNull + public Integer auth_type; @NonNull public String host; // IMAP @NonNull @@ -58,19 +58,23 @@ public class EntityAccount { public String user; @NonNull public String password; - @NonNull - public Integer auth_type; + + public String name; + public String signature; // obsolete + public Integer color; + @NonNull public Boolean synchronize; @NonNull public Boolean primary; @NonNull - public Boolean browse; - public Integer color; - @NonNull public Boolean notify; @NonNull + public Boolean browse; + @NonNull public Integer poll_interval; // keep-alive interval + public String prefix; // namespace + public Long created; public Boolean tbd; public String state; diff --git a/app/src/main/java/eu/faircode/email/FragmentAccount.java b/app/src/main/java/eu/faircode/email/FragmentAccount.java index aada8ec540..0c1efa3d16 100644 --- a/app/src/main/java/eu/faircode/email/FragmentAccount.java +++ b/app/src/main/java/eu/faircode/email/FragmentAccount.java @@ -95,6 +95,7 @@ public class FragmentAccount extends FragmentEx { private EditText etDomain; private Button btnAutoConfig; + private Button btnAuthorize; private EditText etHost; private CheckBox cbStartTls; private CheckBox cbInsecure; @@ -102,26 +103,22 @@ public class FragmentAccount extends FragmentEx { private EditText etUser; private TextInputLayout tilPassword; - private Button btnAuthorize; - - private Button btnAdvanced; - private TextView tvName; private EditText etName; - private EditText etPrefix; private Button btnColor; private View vwColor; private ImageView ibColorDefault; - private CheckBox cbNotify; + private Button btnAdvanced; private CheckBox cbSynchronize; private CheckBox cbPrimary; + private CheckBox cbNotify; private CheckBox cbBrowse; private EditText etInterval; + private EditText etPrefix; private Button btnCheck; private ProgressBar pbCheck; - private TextView tvIdle; private ArrayAdapter adapter; @@ -170,6 +167,7 @@ public class FragmentAccount extends FragmentEx { etDomain = view.findViewById(R.id.etDomain); btnAutoConfig = view.findViewById(R.id.btnAutoConfig); + btnAuthorize = view.findViewById(R.id.btnAuthorize); etHost = view.findViewById(R.id.etHost); etPort = view.findViewById(R.id.etPort); cbStartTls = view.findViewById(R.id.cbStartTls); @@ -177,22 +175,19 @@ public class FragmentAccount extends FragmentEx { etUser = view.findViewById(R.id.etUser); tilPassword = view.findViewById(R.id.tilPassword); - btnAuthorize = view.findViewById(R.id.btnAuthorize); - - btnAdvanced = view.findViewById(R.id.btnAdvanced); - etName = view.findViewById(R.id.etName); tvName = view.findViewById(R.id.tvName); - etPrefix = view.findViewById(R.id.etPrefix); btnColor = view.findViewById(R.id.btnColor); vwColor = view.findViewById(R.id.vwColor); ibColorDefault = view.findViewById(R.id.ibColorDefault); - cbNotify = view.findViewById(R.id.cbNotify); + btnAdvanced = view.findViewById(R.id.btnAdvanced); cbSynchronize = view.findViewById(R.id.cbSynchronize); cbPrimary = view.findViewById(R.id.cbPrimary); + cbNotify = view.findViewById(R.id.cbNotify); cbBrowse = view.findViewById(R.id.cbBrowse); etInterval = view.findViewById(R.id.etInterval); + etPrefix = view.findViewById(R.id.etPrefix); btnCheck = view.findViewById(R.id.btnCheck); pbCheck = view.findViewById(R.id.pbCheck); @@ -259,6 +254,23 @@ public class FragmentAccount extends FragmentEx { } }); + etDomain.addTextChangedListener(new TextWatcher() { + @Override + public void beforeTextChanged(CharSequence s, int start, int count, int after) { + } + + @Override + public void onTextChanged(CharSequence text, int start, int before, int count) { + btnAutoConfig.setEnabled(text.length() > 0); + } + + @Override + public void afterTextChanged(Editable s) { + } + }); + + btnAutoConfig.setEnabled(false); + btnAutoConfig.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -271,8 +283,10 @@ public class FragmentAccount extends FragmentEx { new SimpleTask() { @Override protected SRVRecord onLoad(Context context, Bundle args) throws Throwable { - String domain = args.getString("domain"); - Record[] records = new Lookup("_imaps._tcp." + domain, Type.SRV).run(); + String dns = "_imaps._tcp." + args.getString("domain"); + Log.i("Lookup dns=" + dns); + Record[] records = new Lookup(dns, Type.SRV).run(); + Log.i("Found dns=" + (records == null ? -1 : records.length)); if (records != null) for (int i = 0; i < records.length; i++) { SRVRecord srv = (SRVRecord) records[i]; @@ -330,39 +344,6 @@ public class FragmentAccount extends FragmentEx { } }); - btnAuthorize.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Provider provider = (Provider) spProvider.getSelectedItem(); - Log.i("Authorize " + provider); - - if ("com.google".equals(provider.type)) { - String permission = Manifest.permission.GET_ACCOUNTS; - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && - ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) { - Log.i("Requesting " + permission); - requestPermissions(new String[]{permission}, ActivitySetup.REQUEST_PERMISSION); - } else - selectAccount(); - } - } - }); - - btnAdvanced.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - int visibility = (grpAdvanced.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); - grpAdvanced.setVisibility(visibility); - if (visibility == View.VISIBLE) - new Handler().post(new Runnable() { - @Override - public void run() { - ((ScrollView) view).smoothScrollTo(0, tvName.getTop()); - } - }); - } - }); - vwColor.setBackgroundColor(color); btnColor.setOnClickListener(new View.OnClickListener() { @Override @@ -394,6 +375,46 @@ public class FragmentAccount extends FragmentEx { } }); + btnAuthorize.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Provider provider = (Provider) spProvider.getSelectedItem(); + Log.i("Authorize " + provider); + + if ("com.google".equals(provider.type)) { + String permission = Manifest.permission.GET_ACCOUNTS; + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && + ContextCompat.checkSelfPermission(getContext(), permission) != PackageManager.PERMISSION_GRANTED) { + Log.i("Requesting " + permission); + requestPermissions(new String[]{permission}, ActivitySetup.REQUEST_PERMISSION); + } else + selectAccount(); + } + } + }); + + btnAdvanced.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + int visibility = (grpAdvanced.getVisibility() == View.VISIBLE ? View.GONE : View.VISIBLE); + grpAdvanced.setVisibility(visibility); + if (visibility == View.VISIBLE) + new Handler().post(new Runnable() { + @Override + public void run() { + ((ScrollView) view).smoothScrollTo(0, cbPrimary.getTop()); + } + }); + } + }); + + cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { + cbPrimary.setEnabled(checked); + } + }); + cbNotify.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { @@ -408,13 +429,6 @@ public class FragmentAccount extends FragmentEx { } }); - cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton compoundButton, boolean checked) { - cbPrimary.setEnabled(checked); - } - }); - btnCheck.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { @@ -594,23 +608,24 @@ public class FragmentAccount extends FragmentEx { Bundle args = new Bundle(); args.putLong("id", id); + + args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType()); args.putString("host", etHost.getText().toString()); args.putBoolean("starttls", cbStartTls.isChecked()); args.putBoolean("insecure", cbInsecure.isChecked()); args.putString("port", etPort.getText().toString()); args.putString("user", etUser.getText().toString()); args.putString("password", tilPassword.getEditText().getText().toString()); - args.putInt("auth_type", authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType()); args.putString("name", etName.getText().toString()); - args.putString("prefix", etPrefix.getText().toString()); args.putInt("color", color); - args.putBoolean("notify", cbNotify.isChecked()); args.putBoolean("synchronize", cbSynchronize.isChecked()); args.putBoolean("primary", cbPrimary.isChecked()); + args.putBoolean("notify", cbNotify.isChecked()); args.putBoolean("browse", cbBrowse.isChecked()); args.putString("interval", etInterval.getText().toString()); + args.putString("prefix", etPrefix.getText().toString()); args.putSerializable("drafts", drafts); args.putSerializable("sent", sent); @@ -622,23 +637,24 @@ public class FragmentAccount extends FragmentEx { @Override protected Void onLoad(Context context, Bundle args) throws Throwable { long id = args.getLong("id"); + + int auth_type = args.getInt("auth_type"); String host = args.getString("host"); boolean starttls = args.getBoolean("starttls"); boolean insecure = args.getBoolean("insecure"); String port = args.getString("port"); String user = args.getString("user"); String password = args.getString("password"); - int auth_type = args.getInt("auth_type"); String name = args.getString("name"); - String prefix = args.getString("prefix"); Integer color = args.getInt("color"); - boolean notify = args.getBoolean("notify"); boolean synchronize = args.getBoolean("synchronize"); boolean primary = args.getBoolean("primary"); + boolean notify = args.getBoolean("notify"); boolean browse = args.getBoolean("browse"); String interval = args.getString("interval"); + String prefix = args.getString("prefix"); EntityFolder drafts = (EntityFolder) args.getSerializable("drafts"); EntityFolder sent = (EntityFolder) args.getSerializable("sent"); @@ -659,10 +675,10 @@ public class FragmentAccount extends FragmentEx { if (synchronize && drafts == null) throw new Throwable(context.getString(R.string.title_no_drafts)); - if (TextUtils.isEmpty(prefix)) - prefix = null; if (Color.TRANSPARENT == color) color = null; + if (TextUtils.isEmpty(prefix)) + prefix = null; long now = new Date().getTime(); Character separator = null; @@ -713,23 +729,23 @@ public class FragmentAccount extends FragmentEx { if (account == null) account = new EntityAccount(); + account.auth_type = auth_type; account.host = host; account.starttls = starttls; account.insecure = insecure; account.port = Integer.parseInt(port); account.user = user; account.password = password; - account.auth_type = auth_type; account.name = name; - account.prefix = prefix; account.color = color; - account.notify = notify; account.synchronize = synchronize; account.primary = (account.synchronize && primary); + account.notify = notify; account.browse = browse; account.poll_interval = Integer.parseInt(interval); + account.prefix = prefix; if (!update) account.created = now; diff --git a/app/src/main/res/layout/fragment_account.xml b/app/src/main/res/layout/fragment_account.xml index 0b54e46ba9..2b3bd0fc19 100644 --- a/app/src/main/res/layout/fragment_account.xml +++ b/app/src/main/res/layout/fragment_account.xml @@ -212,18 +212,6 @@ android:inputType="textPassword" /> -