Review quick setup configuration

pull/148/head
M66B 6 years ago
parent 459f084890
commit d575de0353

@ -308,6 +308,7 @@ public class FragmentAccount extends FragmentBase {
auth_type = Helper.AUTH_TYPE_PASSWORD; auth_type = Helper.AUTH_TYPE_PASSWORD;
tilPassword.getEditText().setText(null); tilPassword.getEditText().setText(null);
tilPassword.setEnabled(true); tilPassword.setEnabled(true);
tilPassword.setPasswordVisibilityToggleEnabled(true);
etRealm.setEnabled(true); etRealm.setEnabled(true);
} }
} }
@ -1362,6 +1363,7 @@ public class FragmentAccount extends FragmentBase {
btnAuthorize.setEnabled(true); btnAuthorize.setEnabled(true);
etUser.setEnabled(true); etUser.setEnabled(true);
tilPassword.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD); tilPassword.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
tilPassword.setPasswordVisibilityToggleEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
etRealm.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD); etRealm.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
btnCheck.setEnabled(true); btnCheck.setEnabled(true);
btnSave.setEnabled(true); btnSave.setEnabled(true);

@ -62,6 +62,7 @@ import javax.mail.Transport;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import static android.accounts.AccountManager.newChooseAccountIntent; import static android.accounts.AccountManager.newChooseAccountIntent;
import static android.app.Activity.RESULT_OK; import static android.app.Activity.RESULT_OK;
@ -74,9 +75,15 @@ public class FragmentQuickSetup extends FragmentBase {
private Button btnAuthorize; private Button btnAuthorize;
private TextInputLayout tilPassword; private TextInputLayout tilPassword;
private Button btnCheck; private Button btnCheck;
private TextView tvError; private TextView tvError;
private TextView tvInstructions; private TextView tvInstructions;
private TextView tvImap;
private TextView tvSmtp;
private Button btnSave;
private Group grpSetup;
private int auth_type = Helper.AUTH_TYPE_PASSWORD; private int auth_type = Helper.AUTH_TYPE_PASSWORD;
@Override @Override
@ -92,9 +99,15 @@ public class FragmentQuickSetup extends FragmentBase {
etEmail = view.findViewById(R.id.etEmail); etEmail = view.findViewById(R.id.etEmail);
tilPassword = view.findViewById(R.id.tilPassword); tilPassword = view.findViewById(R.id.tilPassword);
btnCheck = view.findViewById(R.id.btnCheck); btnCheck = view.findViewById(R.id.btnCheck);
tvError = view.findViewById(R.id.tvError); tvError = view.findViewById(R.id.tvError);
tvInstructions = view.findViewById(R.id.tvInstructions); tvInstructions = view.findViewById(R.id.tvInstructions);
tvImap = view.findViewById(R.id.tvImap);
tvSmtp = view.findViewById(R.id.tvSmtp);
btnSave = view.findViewById(R.id.btnSave);
grpSetup = view.findViewById(R.id.grpSetup);
// Wire controls // Wire controls
btnAuthorize.setOnClickListener(new View.OnClickListener() { btnAuthorize.setOnClickListener(new View.OnClickListener() {
@ -110,30 +123,39 @@ public class FragmentQuickSetup extends FragmentBase {
} }
}); });
TextWatcher credentialsWatcher = new TextWatcher() { etEmail.addTextChangedListener(new TextWatcher() {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
@Override @Override
public void onTextChanged(CharSequence s, int start, int before, int count) { public void onTextChanged(CharSequence s, int start, int before, int count) {
auth_type = Helper.AUTH_TYPE_PASSWORD; if (auth_type != Helper.AUTH_TYPE_PASSWORD) {
auth_type = Helper.AUTH_TYPE_PASSWORD;
tilPassword.getEditText().setText(null);
tilPassword.setEnabled(true);
tilPassword.setPasswordVisibilityToggleEnabled(true);
}
} }
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
} }
}; });
etEmail.addTextChangedListener(credentialsWatcher);
tilPassword.getEditText().addTextChangedListener(credentialsWatcher);
tilPassword.setHintEnabled(false); tilPassword.setHintEnabled(false);
btnCheck.setOnClickListener(new View.OnClickListener() { btnCheck.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
onCheck(); onSave(true);
}
});
btnSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onSave(false);
} }
}); });
@ -141,44 +163,42 @@ public class FragmentQuickSetup extends FragmentBase {
tvError.setVisibility(View.GONE); tvError.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE); tvInstructions.setVisibility(View.GONE);
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance()); tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
grpSetup.setVisibility(View.GONE);
return view; return view;
} }
private void onCheck() { private void onSave(boolean check) {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString("name", etName.getText().toString()); args.putString("name", etName.getText().toString());
args.putString("email", etEmail.getText().toString().trim()); args.putString("email", etEmail.getText().toString().trim());
args.putString("password", tilPassword.getEditText().getText().toString()); args.putString("password", tilPassword.getEditText().getText().toString());
args.putInt("auth_type", auth_type); args.putInt("auth_type", auth_type);
args.putBoolean("check", check);
new SimpleTask<Void>() { new SimpleTask<EmailProvider>() {
@Override @Override
protected void onPreExecute(Bundle args) { protected void onPreExecute(Bundle args) {
etName.setEnabled(false); boolean check = args.getBoolean("check");
etEmail.setEnabled(false);
tilPassword.setEnabled(false); Helper.setViewsEnabled(view, false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
tvError.setVisibility(View.GONE); tvError.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE); tvInstructions.setVisibility(View.GONE);
grpSetup.setVisibility(check ? View.GONE : View.VISIBLE);
} }
@Override @Override
protected void onPostExecute(Bundle args) { protected void onPostExecute(Bundle args) {
etName.setEnabled(true); Helper.setViewsEnabled(view, true);
etEmail.setEnabled(true);
tilPassword.setEnabled(true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
} }
@Override @Override
protected Void onExecute(Context context, Bundle args) throws Throwable { protected EmailProvider onExecute(Context context, Bundle args) throws Throwable {
String name = args.getString("name"); String name = args.getString("name");
String email = args.getString("email"); String email = args.getString("email");
String password = args.getString("password"); String password = args.getString("password");
int auth_type = args.getInt("auth_type"); int auth_type = args.getInt("auth_type");
boolean check = args.getBoolean("check");
if (TextUtils.isEmpty(name)) if (TextUtils.isEmpty(name))
throw new IllegalArgumentException(context.getString(R.string.title_no_name)); throw new IllegalArgumentException(context.getString(R.string.title_no_name));
@ -196,9 +216,8 @@ public class FragmentQuickSetup extends FragmentBase {
String user = (provider.user == EmailProvider.UserType.EMAIL ? email : dparts[0]); String user = (provider.user == EmailProvider.UserType.EMAIL ? email : dparts[0]);
Character separator; Character separator;
long now = new Date().getTime();
List<EntityFolder> folders = new ArrayList<>(); List<EntityFolder> folders = new ArrayList<>();
long now = new Date().getTime();
{ {
Properties props = MessageHelper.getSessionProperties(auth_type, null, false); Properties props = MessageHelper.getSessionProperties(auth_type, null, false);
@ -262,6 +281,9 @@ public class FragmentQuickSetup extends FragmentBase {
} }
} }
if (check)
return provider;
DB db = DB.getInstance(context); DB db = DB.getInstance(context);
try { try {
db.beginTransaction(); db.beginTransaction();
@ -354,22 +376,24 @@ public class FragmentQuickSetup extends FragmentBase {
} }
@Override @Override
protected void onExecuted(Bundle args, Void data) { protected void onExecuted(Bundle args, EmailProvider result) {
etName.setText(null); boolean check = args.getBoolean("check");
etEmail.setText(null); if (check) {
tilPassword.getEditText().setText(null); tvImap.setText(result == null ? null : result.imap_host + ":" + result.imap_port);
tvSmtp.setText(result == null ? null : result.smtp_host + ":" + result.smtp_port);
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner()) grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE);
.setMessage(R.string.title_setup_quick_success) } else
.setPositiveButton(android.R.string.ok, null) new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setOnDismissListener(new DialogInterface.OnDismissListener() { .setMessage(R.string.title_setup_quick_success)
@Override .setPositiveButton(android.R.string.ok, null)
public void onDismiss(DialogInterface dialog) { .setOnDismissListener(new DialogInterface.OnDismissListener() {
finish(); @Override
} public void onDismiss(DialogInterface dialog) {
}) finish();
.create() }
.show(); })
.create()
.show();
} }
@Override @Override
@ -461,7 +485,8 @@ public class FragmentQuickSetup extends FragmentBase {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex); Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
} finally { } finally {
etEmail.setEnabled(true); etEmail.setEnabled(true);
tilPassword.setEnabled(true); tilPassword.setEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
tilPassword.setPasswordVisibilityToggleEnabled(auth_type == Helper.AUTH_TYPE_PASSWORD);
btnAuthorize.setEnabled(true); btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true); btnCheck.setEnabled(true);
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {

@ -31,6 +31,7 @@
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:minWidth="0dp" android:minWidth="0dp"
android:minHeight="0dp" android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_authorize" android:text="@string/title_authorize"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" /> app:layout_constraintTop_toBottomOf="@id/etName" />
@ -79,6 +80,7 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="12dp" android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_check" android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHint" /> app:layout_constraintTop_toBottomOf="@id/tvHint" />
@ -107,5 +109,68 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small" android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvError" /> app:layout_constraintTop_toBottomOf="@id/tvError" />
<TextView
android:id="@+id/tvImapTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center_horizontal"
android:text="@string/title_imap"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInstructions" />
<TextView
android:id="@+id/tvImap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center_horizontal"
android:text="imap.domain.tld:993"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImapTitle" />
<TextView
android:id="@+id/tvSmtpTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:gravity="center_horizontal"
android:text="@string/title_smtp"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImap" />
<TextView
android:id="@+id/tvSmtp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:gravity="center_horizontal"
android:text="smtp.domain.tld:993"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSmtpTitle" />
<Button
android:id="@+id/btnSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_save"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvSmtp" />
<androidx.constraintlayout.widget.Group
android:id="@+id/grpSetup"
android:layout_width="0dp"
android:layout_height="0dp"
app:constraint_referenced_ids="
tvImapTitle,tvImap,
tvSmtpTitle,tvSmtp,
btnSave" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView> </ScrollView>
Loading…
Cancel
Save