Browse Source

Simplified account setup

Refs #52
main
M66B 6 years ago
parent
commit
a5d77946ce
3 changed files with 115 additions and 133 deletions
  1. +79
    -72
      app/src/main/java/eu/faircode/email/FragmentAccount.java
  2. +35
    -59
      app/src/main/res/layout/fragment_account.xml
  3. +1
    -2
      app/src/main/res/values/strings.xml

+ 79
- 72
app/src/main/java/eu/faircode/email/FragmentAccount.java View File

@ -33,10 +33,8 @@ import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -51,7 +49,6 @@ import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
@ -82,17 +79,16 @@ import static android.accounts.AccountManager.newChooseAccountIntent;
public class FragmentAccount extends FragmentEx {
private ViewGroup view;
private EditText etName;
private Spinner spProvider;
private EditText etHost;
private EditText etPort;
private Button btnAuthorize;
private EditText etUser;
private TextInputLayout tilPassword;
private TextView tvLink;
private Button btnAdvanced;
private EditText etName;
private CheckBox cbSynchronize;
private CheckBox cbPrimary;
private EditText etInterval;
private Button btnCheck;
private ProgressBar pbCheck;
private Spinner spDrafts;
@ -104,8 +100,9 @@ public class FragmentAccount extends FragmentEx {
private ProgressBar pbSave;
private ImageButton ibDelete;
private ProgressBar pbWait;
private Group grpInstructions;
private Group grpInterval;
private Group grpServer;
private Group grpAuthorize;
private Group grpAdvanced;
private Group grpFolders;
private long id = -1;
@ -129,29 +126,37 @@ public class FragmentAccount extends FragmentEx {
// Get controls
spProvider = view.findViewById(R.id.spProvider);
etName = view.findViewById(R.id.etName);
etHost = view.findViewById(R.id.etHost);
btnAuthorize = view.findViewById(R.id.btnAuthorize);
etPort = view.findViewById(R.id.etPort);
btnAuthorize = view.findViewById(R.id.btnAuthorize);
etUser = view.findViewById(R.id.etUser);
tilPassword = view.findViewById(R.id.tilPassword);
tvLink = view.findViewById(R.id.tvLink);
btnAdvanced = view.findViewById(R.id.btnAdvanced);
etName = view.findViewById(R.id.etName);
cbSynchronize = view.findViewById(R.id.cbSynchronize);
cbPrimary = view.findViewById(R.id.cbPrimary);
etInterval = view.findViewById(R.id.etInterval);
btnCheck = view.findViewById(R.id.btnCheck);
pbCheck = view.findViewById(R.id.pbCheck);
spDrafts = view.findViewById(R.id.spDrafts);
spSent = view.findViewById(R.id.spSent);
spAll = view.findViewById(R.id.spAll);
spTrash = view.findViewById(R.id.spTrash);
spJunk = view.findViewById(R.id.spJunk);
btnSave = view.findViewById(R.id.btnSave);
pbSave = view.findViewById(R.id.pbSave);
ibDelete = view.findViewById(R.id.ibDelete);
pbWait = view.findViewById(R.id.pbWait);
grpInstructions = view.findViewById(R.id.grpInstructions);
grpInterval = view.findViewById(R.id.grpInterval);
grpServer = view.findViewById(R.id.grpServer);
grpAuthorize = view.findViewById(R.id.grpAuthorize);
grpAdvanced = view.findViewById(R.id.grpAdvanced);
grpFolders = view.findViewById(R.id.grpFolders);
// Wire controls
@ -159,27 +164,32 @@ public class FragmentAccount extends FragmentEx {
spProvider.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long id) {
Integer tag = (Integer) adapterView.getTag();
if (tag != null && tag.equals(position))
return;
adapterView.setTag(position);
Provider provider = (Provider) adapterView.getSelectedItem();
etName.setText(provider.name);
grpServer.setVisibility(position == 1 ? View.VISIBLE : View.GONE);
grpAuthorize.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
btnAuthorize.setVisibility(provider.type == null ? View.GONE : View.VISIBLE);
if (authorized != null) {
authorized = null;
etUser.setText(null);
tilPassword.getEditText().setText(null);
}
btnAdvanced.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
if (position == 0)
grpAdvanced.setVisibility(View.GONE);
btnCheck.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
Object tag = adapterView.getTag();
if (tag != null && (Integer) tag == position)
return;
adapterView.setTag(position);
etHost.setText(provider.imap_host);
etPort.setText(position == 0 ? null : Integer.toString(provider.imap_port));
etPort.setText(provider.imap_host == null ? null : Integer.toString(provider.imap_port));
etUser.setText(null);
tilPassword.getEditText().setText(null);
tvLink.setText(Html.fromHtml("<a href=\"" + provider.link + "\">" + provider.link + "</a>"));
grpInstructions.setVisibility(provider.link == null ? View.GONE : View.VISIBLE);
etName.setText(position > 1 ? provider.name : null);
}
@Override
@ -216,12 +226,25 @@ public class FragmentAccount extends FragmentEx {
}
});
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, btnCheck.getBottom());
}
});
}
});
cbSynchronize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
cbPrimary.setEnabled(checked);
btnCheck.setVisibility(checked ? View.VISIBLE : View.GONE);
btnSave.setVisibility(checked ? View.GONE : View.VISIBLE);
}
});
@ -232,21 +255,18 @@ public class FragmentAccount extends FragmentEx {
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
pbCheck.setVisibility(View.VISIBLE);
btnSave.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
Provider provider = (Provider) spProvider.getSelectedItem();
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", etName.getText().toString());
args.putString("host", etHost.getText().toString());
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.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
new SimpleTask<List<EntityFolder>>() {
@Override
@ -454,15 +474,14 @@ public class FragmentAccount extends FragmentEx {
Bundle args = new Bundle();
args.putLong("id", id);
args.putString("name", etName.getText().toString());
args.putString("host", etHost.getText().toString());
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.putBoolean("synchronize", cbSynchronize.isChecked());
args.putBoolean("primary", cbPrimary.isChecked());
args.putString("poll_interval", etInterval.getText().toString());
args.putParcelable("drafts", drafts);
args.putParcelable("sent", sent);
args.putParcelable("all", all);
@ -472,15 +491,14 @@ public class FragmentAccount extends FragmentEx {
new SimpleTask<Void>() {
@Override
protected Void onLoad(Context context, Bundle args) throws Throwable {
String name = args.getString("name");
String host = args.getString("host");
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");
boolean synchronize = args.getBoolean("synchronize");
boolean primary = args.getBoolean("primary");
String poll_interval = args.getString("poll_interval");
EntityFolder drafts = args.getParcelable("drafts");
EntityFolder sent = args.getParcelable("sent");
EntityFolder all = args.getParcelable("all");
@ -498,9 +516,6 @@ public class FragmentAccount extends FragmentEx {
if (synchronize && drafts == null)
throw new Throwable(getContext().getString(R.string.title_no_drafts));
if (TextUtils.isEmpty(poll_interval))
poll_interval = "9";
// Check IMAP server
if (synchronize) {
Session isession = Session.getInstance(MessageHelper.getSessionProperties(context, auth_type), null);
@ -529,16 +544,16 @@ public class FragmentAccount extends FragmentEx {
boolean update = (account != null);
if (account == null)
account = new EntityAccount();
account.name = name;
account.host = host;
account.port = Integer.parseInt(port);
account.user = user;
account.password = password;
account.auth_type = auth_type;
account.name = name;
account.synchronize = synchronize;
account.primary = (account.synchronize && primary);
account.store_sent = false;
account.poll_interval = Integer.parseInt(poll_interval);
account.poll_interval = 9;
if (!synchronize)
account.error = null;
@ -671,17 +686,22 @@ public class FragmentAccount extends FragmentEx {
Helper.setViewsEnabled(view, false);
btnAuthorize.setVisibility(View.GONE);
tilPassword.setPasswordVisibilityToggleEnabled(id < 0);
tvLink.setMovementMethod(LinkMovementMethod.getInstance());
btnAuthorize.setEnabled(false);
grpInstructions.setVisibility(View.GONE);
grpInterval.setVisibility(View.GONE);
btnCheck.setEnabled(false);
btnAdvanced.setVisibility(View.GONE);
btnCheck.setVisibility(View.GONE);
pbCheck.setVisibility(View.GONE);
btnSave.setVisibility(View.GONE);
pbSave.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
ibDelete.setVisibility(View.GONE);
grpServer.setVisibility(View.GONE);
grpAuthorize.setVisibility(View.GONE);
grpAdvanced.setVisibility(View.GONE);
grpFolders.setVisibility(View.GONE);
return view;
}
@ -691,6 +711,7 @@ public class FragmentAccount extends FragmentEx {
outState.putInt("provider", spProvider.getSelectedItemPosition());
outState.putString("authorized", authorized);
outState.putString("password", tilPassword.getEditText().getText().toString());
outState.putInt("advanced", grpAdvanced.getVisibility());
}
@Override
@ -705,7 +726,8 @@ public class FragmentAccount extends FragmentEx {
public void onChanged(@Nullable EntityAccount account) {
// Get providers
List<Provider> providers = Provider.loadProfiles(getContext());
providers.add(0, new Provider(getString(R.string.title_custom)));
providers.add(0, new Provider(getString(R.string.title_select)));
providers.add(1, new Provider(getString(R.string.title_custom)));
ArrayAdapter<Provider> padapter = new ArrayAdapter<>(getContext(), R.layout.spinner_item, providers);
padapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
@ -716,29 +738,25 @@ public class FragmentAccount extends FragmentEx {
return;
once = true;
spProvider.setTag(0);
spProvider.setSelection(0);
if (account != null) {
for (int pos = 1; pos < providers.size(); pos++)
for (int pos = 2; pos < providers.size(); pos++)
if (providers.get(pos).imap_host.equals(account.host)) {
spProvider.setTag(pos);
spProvider.setSelection(pos);
break;
}
etHost.setText(account.host);
etPort.setText(Long.toString(account.port));
}
etName.setText(account == null ? null : account.name);
etHost.setText(account == null ? null : account.host);
etPort.setText(account == null ? null : Long.toString(account.port));
authorized = (account != null && account.auth_type != Helper.AUTH_TYPE_PASSWORD ? account.password : null);
etUser.setText(account == null ? null : account.user);
tilPassword.getEditText().setText(account == null ? null : account.password);
etName.setText(account == null ? null : account.name);
cbSynchronize.setChecked(account == null ? true : account.synchronize);
cbPrimary.setChecked(account == null ? true : account.primary);
etInterval.setText(account == null ? "9" : Integer.toString(account.poll_interval));
} else {
int provider = savedInstanceState.getInt("provider");
spProvider.setTag(provider);
@ -746,26 +764,15 @@ public class FragmentAccount extends FragmentEx {
authorized = savedInstanceState.getString("authorized");
tilPassword.getEditText().setText(savedInstanceState.getString("password"));
grpAdvanced.setVisibility(savedInstanceState.getInt("advanced"));
}
Helper.setViewsEnabled(view, true);
Provider provider = (Provider) spProvider.getSelectedItem();
btnAuthorize.setVisibility(provider.getAuthType() == Helper.AUTH_TYPE_PASSWORD ? View.GONE : View.VISIBLE);
tvLink.setText(Html.fromHtml("<a href=\"" + provider.link + "\">" + provider.link + "</a>"));
grpInstructions.setVisibility(provider.link == null ? View.GONE : View.VISIBLE);
cbPrimary.setEnabled(cbSynchronize.isChecked());
grpInterval.setVisibility(BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
btnCheck.setVisibility(cbSynchronize.isChecked() ? View.VISIBLE : View.GONE);
btnSave.setVisibility(cbSynchronize.isChecked() ? View.GONE : View.VISIBLE);
// Consider previous check/save/delete as cancelled
ibDelete.setVisibility(account == null ? View.GONE : View.VISIBLE);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
pbWait.setVisibility(View.GONE);
}
});


+ 35
- 59
app/src/main/res/layout/fragment_account.xml View File

@ -30,28 +30,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvProvider" />
<!-- name -->
<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_account_name"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/spProvider" />
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_account_name_hint"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
<!-- IMAP -->
<TextView
@ -62,7 +40,7 @@
android:text="@string/title_imap"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
app:layout_constraintTop_toBottomOf="@id/spProvider" />
<!-- host -->
@ -167,27 +145,39 @@
android:inputType="textPassword" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/tvInstructions"
<!-- name -->
<Button
android:id="@+id/btnAdvanced"
style="@style/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:freezesText="true"
android:text="@string/title_instructions"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:minHeight="0dp"
android:minWidth="0dp"
android:text="@string/title_setup_advanced"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tilPassword" />
<TextView
android:id="@+id/tvLink"
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:freezesText="true"
android:text="link"
android:text="@string/title_account_name"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInstructions" />
app:layout_constraintTop_toBottomOf="@id/btnAdvanced" />
<EditText
android:id="@+id/etName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/title_account_name_hint"
android:inputType="text"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvName" />
<CheckBox
android:id="@+id/cbSynchronize"
@ -196,7 +186,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_synchronize_account"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvLink" />
app:layout_constraintTop_toBottomOf="@id/etName" />
<CheckBox
android:id="@+id/cbPrimary"
@ -207,26 +197,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbSynchronize" />
<TextView
android:id="@+id/tvInterval"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_interval"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<EditText
android:id="@+id/etInterval"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:text="9"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInterval" />
<!-- check -->
<Button
@ -236,7 +206,7 @@
android:layout_marginTop="12dp"
android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etInterval" />
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<ProgressBar
android:id="@+id/pbCheck"
@ -256,7 +226,7 @@
android:layout_marginTop="12dp"
android:src="@drawable/baseline_delete_24"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/etInterval" />
app:layout_constraintTop_toBottomOf="@id/cbPrimary" />
<TextView
android:id="@+id/tvDrafts"
@ -392,16 +362,22 @@
app:layout_constraintTop_toTopOf="parent" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpInterval"
android:id="@+id/grpServer"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvImap,tvHost,etHost,tvPort,etPort" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpAuthorize"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvInterval,etInterval" />
app:constraint_referenced_ids="tvUser,etUser,tvPassword,tilPassword" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpInstructions"
android:id="@+id/grpAdvanced"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="tvInstructions,tvLink" />
app:constraint_referenced_ids="tvName,etName,cbSynchronize,cbPrimary" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpFolders"


+ 1
- 2
app/src/main/res/values/strings.xml View File

@ -95,9 +95,8 @@
<string name="title_password">Password</string>
<string name="title_authorize">Select account</string>
<string name="title_authorizing">Authorizing account &#8230;</string>
<string name="title_instructions">Instructions</string>
<string name="title_setup_advanced">Advanced</string>
<string name="title_store_sent">Store sent messages (enable if needed only)</string>
<string name="title_interval">Keep-alive interval (minutes)</string>
<string name="title_synchronize_account">Synchronize (receive messages)</string>
<string name="title_synchronize_identity">Synchronize (send messages)</string>
<string name="title_primary_account">Primary (default account)</string>


Loading…
Cancel
Save