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

@ -62,6 +62,7 @@ import javax.mail.Transport;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.Group;
import static android.accounts.AccountManager.newChooseAccountIntent;
import static android.app.Activity.RESULT_OK;
@ -74,9 +75,15 @@ public class FragmentQuickSetup extends FragmentBase {
private Button btnAuthorize;
private TextInputLayout tilPassword;
private Button btnCheck;
private TextView tvError;
private TextView tvInstructions;
private TextView tvImap;
private TextView tvSmtp;
private Button btnSave;
private Group grpSetup;
private int auth_type = Helper.AUTH_TYPE_PASSWORD;
@Override
@ -92,9 +99,15 @@ public class FragmentQuickSetup extends FragmentBase {
etEmail = view.findViewById(R.id.etEmail);
tilPassword = view.findViewById(R.id.tilPassword);
btnCheck = view.findViewById(R.id.btnCheck);
tvError = view.findViewById(R.id.tvError);
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
btnAuthorize.setOnClickListener(new View.OnClickListener() {
@ -110,30 +123,39 @@ public class FragmentQuickSetup extends FragmentBase {
}
});
TextWatcher credentialsWatcher = new TextWatcher() {
etEmail.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if (auth_type != Helper.AUTH_TYPE_PASSWORD) {
auth_type = Helper.AUTH_TYPE_PASSWORD;
tilPassword.getEditText().setText(null);
tilPassword.setEnabled(true);
tilPassword.setPasswordVisibilityToggleEnabled(true);
}
}
@Override
public void afterTextChanged(Editable s) {
}
};
etEmail.addTextChangedListener(credentialsWatcher);
tilPassword.getEditText().addTextChangedListener(credentialsWatcher);
});
tilPassword.setHintEnabled(false);
btnCheck.setOnClickListener(new View.OnClickListener() {
@Override
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);
tvInstructions.setVisibility(View.GONE);
tvInstructions.setMovementMethod(LinkMovementMethod.getInstance());
grpSetup.setVisibility(View.GONE);
return view;
}
private void onCheck() {
private void onSave(boolean check) {
Bundle args = new Bundle();
args.putString("name", etName.getText().toString());
args.putString("email", etEmail.getText().toString().trim());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putInt("auth_type", auth_type);
args.putBoolean("check", check);
new SimpleTask<Void>() {
new SimpleTask<EmailProvider>() {
@Override
protected void onPreExecute(Bundle args) {
etName.setEnabled(false);
etEmail.setEnabled(false);
tilPassword.setEnabled(false);
btnAuthorize.setEnabled(false);
btnCheck.setEnabled(false);
boolean check = args.getBoolean("check");
Helper.setViewsEnabled(view, false);
tvError.setVisibility(View.GONE);
tvInstructions.setVisibility(View.GONE);
grpSetup.setVisibility(check ? View.GONE : View.VISIBLE);
}
@Override
protected void onPostExecute(Bundle args) {
etName.setEnabled(true);
etEmail.setEnabled(true);
tilPassword.setEnabled(true);
btnAuthorize.setEnabled(true);
btnCheck.setEnabled(true);
Helper.setViewsEnabled(view, true);
}
@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 email = args.getString("email");
String password = args.getString("password");
int auth_type = args.getInt("auth_type");
boolean check = args.getBoolean("check");
if (TextUtils.isEmpty(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]);
Character separator;
long now = new Date().getTime();
List<EntityFolder> folders = new ArrayList<>();
long now = new Date().getTime();
{
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);
try {
db.beginTransaction();
@ -354,11 +376,13 @@ public class FragmentQuickSetup extends FragmentBase {
}
@Override
protected void onExecuted(Bundle args, Void data) {
etName.setText(null);
etEmail.setText(null);
tilPassword.getEditText().setText(null);
protected void onExecuted(Bundle args, EmailProvider result) {
boolean check = args.getBoolean("check");
if (check) {
tvImap.setText(result == null ? null : result.imap_host + ":" + result.imap_port);
tvSmtp.setText(result == null ? null : result.smtp_host + ":" + result.smtp_port);
grpSetup.setVisibility(result == null ? View.GONE : View.VISIBLE);
} else
new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(R.string.title_setup_quick_success)
.setPositiveButton(android.R.string.ok, null)
@ -461,7 +485,8 @@ public class FragmentQuickSetup extends FragmentBase {
Helper.unexpectedError(getContext(), getViewLifecycleOwner(), ex);
} finally {
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);
btnCheck.setEnabled(true);
new Handler().postDelayed(new Runnable() {

@ -31,6 +31,7 @@
android:layout_marginTop="12dp"
android:minWidth="0dp"
android:minHeight="0dp"
android:tag="disable"
android:text="@string/title_authorize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
@ -79,6 +80,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:tag="disable"
android:text="@string/title_check"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvHint" />
@ -107,5 +109,68 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
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>
</ScrollView>
Loading…
Cancel
Save