Improved re OAuth

pull/190/head
M66B 5 years ago
parent 598e4345dd
commit f1c55927f4

@ -42,6 +42,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
@ -68,6 +69,7 @@ public class FragmentGmail extends FragmentBase {
private Button btnGrant;
private TextView tvGranted;
private EditText etName;
private CheckBox cbUpdate;
private Button btnSelect;
private ContentLoadingProgressBar pbSelect;
@ -89,6 +91,7 @@ public class FragmentGmail extends FragmentBase {
btnGrant = view.findViewById(R.id.btnGrant);
tvGranted = view.findViewById(R.id.tvGranted);
etName = view.findViewById(R.id.etName);
cbUpdate = view.findViewById(R.id.cbUpdate);
btnSelect = view.findViewById(R.id.btnSelect);
pbSelect = view.findViewById(R.id.pbSelect);
@ -232,6 +235,7 @@ public class FragmentGmail extends FragmentBase {
}
etName.setEnabled(granted);
cbUpdate.setEnabled(granted);
btnSelect.setEnabled(granted);
getMainHandler().post(new Runnable() {
@ -322,6 +326,7 @@ public class FragmentGmail extends FragmentBase {
Bundle args = new Bundle();
args.putString("name", etName.getText().toString().trim());
args.putBoolean("update", cbUpdate.isChecked());
args.putString("user", user);
args.putString("password", state.jsonSerializeString());
@ -329,6 +334,7 @@ public class FragmentGmail extends FragmentBase {
@Override
protected void onPreExecute(Bundle args) {
etName.setEnabled(false);
cbUpdate.setEnabled(false);
btnSelect.setEnabled(false);
pbSelect.setVisibility(View.VISIBLE);
}
@ -336,6 +342,7 @@ public class FragmentGmail extends FragmentBase {
@Override
protected void onPostExecute(Bundle args) {
etName.setEnabled(true);
cbUpdate.setEnabled(true);
btnSelect.setEnabled(true);
pbSelect.setVisibility(View.GONE);
}
@ -396,7 +403,9 @@ public class FragmentGmail extends FragmentBase {
try {
db.beginTransaction();
EntityAccount update = db.account().getAccount(user, AUTH_TYPE_GMAIL);
EntityAccount update = null;
if (args.getBoolean("update"))
update = db.account().getAccount(user, AUTH_TYPE_GMAIL);
if (update == null) {
EntityAccount primary = db.account().getPrimaryAccount();
@ -465,7 +474,7 @@ public class FragmentGmail extends FragmentBase {
identity.id = db.identity().insertIdentity(identity);
EntityLog.log(context, "Gmail identity=" + identity.name + " email=" + identity.email);
} else {
args.putLong("account", update.id);
args.putLong("account", -1);
EntityLog.log(context, "Gmail update account=" + update.name);
db.account().setAccountPassword(update.id, password);
db.identity().setIdentityPassword(update.id, update.user, password, update.auth_type);
@ -483,11 +492,16 @@ public class FragmentGmail extends FragmentBase {
@Override
protected void onExecuted(Bundle args, Void data) {
if (args.getLong("account") < 0) {
finish();
ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show();
} else {
FragmentReview fragment = new FragmentReview();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentGmail.this, ActivitySetup.REQUEST_DONE);
fragment.show(getParentFragmentManager(), "quick:review");
}
}
@Override
protected void onException(Bundle args, Throwable ex) {

@ -38,9 +38,11 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -90,6 +92,7 @@ public class FragmentOAuth extends FragmentBase {
private TextView tvGrantHint;
private EditText etName;
private EditText etEmail;
private CheckBox cbUpdate;
private Button btnOAuth;
private ContentLoadingProgressBar pbOAuth;
private TextView tvConfiguring;
@ -126,6 +129,7 @@ public class FragmentOAuth extends FragmentBase {
tvGrantHint = view.findViewById(R.id.tvGrantHint);
etName = view.findViewById(R.id.etName);
etEmail = view.findViewById(R.id.etEmail);
cbUpdate = view.findViewById(R.id.cbUpdate);
btnOAuth = view.findViewById(R.id.btnOAuth);
pbOAuth = view.findViewById(R.id.pbOAuth);
tvConfiguring = view.findViewById(R.id.tvConfiguring);
@ -231,6 +235,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setEnabled(false);
etEmail.setEnabled(false);
cbUpdate.setEnabled(false);
btnOAuth.setEnabled(false);
pbOAuth.setVisibility(View.VISIBLE);
hideError();
@ -318,6 +323,7 @@ public class FragmentOAuth extends FragmentBase {
try {
etName.setEnabled(true);
etEmail.setEnabled(true);
cbUpdate.setEnabled(true);
AuthorizationResponse auth = AuthorizationResponse.fromIntent(data);
if (auth == null)
@ -385,6 +391,7 @@ public class FragmentOAuth extends FragmentBase {
args.putBoolean("askAccount", askAccount);
args.putString("personal", etName.getText().toString().trim());
args.putString("address", etEmail.getText().toString().trim());
args.putBoolean("update", cbUpdate.isChecked());
new SimpleTask<Void>() {
@Override
@ -511,7 +518,9 @@ public class FragmentOAuth extends FragmentBase {
try {
db.beginTransaction();
EntityAccount update = db.account().getAccount(username, AUTH_TYPE_OAUTH);
EntityAccount update = null;
if (args.getBoolean("update"))
update = db.account().getAccount(username, AUTH_TYPE_OAUTH);
if (update == null) {
EntityAccount primary = db.account().getPrimaryAccount();
@ -589,7 +598,7 @@ public class FragmentOAuth extends FragmentBase {
EntityLog.log(context, "OAuth identity=" + ident.name + " email=" + ident.email);
}
} else {
args.putLong("account", update.id);
args.putLong("account", -1);
EntityLog.log(context, "OAuth update account=" + update.name);
db.account().setAccountPassword(update.id, state);
db.identity().setIdentityPassword(update.id, update.user, state, update.auth_type);
@ -609,11 +618,16 @@ public class FragmentOAuth extends FragmentBase {
protected void onExecuted(Bundle args, Void data) {
pbOAuth.setVisibility(View.GONE);
if (args.getLong("account") < 0) {
finish();
ToastEx.makeText(getContext(), R.string.title_setup_oauth_updated, Toast.LENGTH_LONG).show();
} else {
FragmentReview fragment = new FragmentReview();
fragment.setArguments(args);
fragment.setTargetFragment(FragmentOAuth.this, ActivitySetup.REQUEST_DONE);
fragment.show(getParentFragmentManager(), "oauth:review");
}
}
@Override
protected void onException(Bundle args, Throwable ex) {
@ -625,6 +639,7 @@ public class FragmentOAuth extends FragmentBase {
private void onHandleCancel() {
etName.setEnabled(true);
etEmail.setEnabled(true);
cbUpdate.setEnabled(true);
btnOAuth.setEnabled(true);
pbOAuth.setVisibility(View.GONE);
}
@ -655,6 +670,7 @@ public class FragmentOAuth extends FragmentBase {
etName.setEnabled(true);
etEmail.setEnabled(true);
cbUpdate.setEnabled(true);
btnOAuth.setEnabled(true);
pbOAuth.setVisibility(View.GONE);

@ -63,6 +63,16 @@
<requestFocus />
</eu.faircode.email.EditTextPlain>
<CheckBox
android:id="@+id/cbUpdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_oauth_update"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<Button
android:id="@+id/btnSelect"
android:layout_width="wrap_content"
@ -71,7 +81,7 @@
android:tag="disable"
android:text="@string/title_setup_select_account"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
app:layout_constraintTop_toBottomOf="@id/cbUpdate" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbSelect"

@ -52,6 +52,16 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" />
<CheckBox
android:id="@+id/cbUpdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_setup_oauth_update"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etEmail" />
<Button
android:id="@+id/btnOAuth"
android:layout_width="wrap_content"
@ -60,7 +70,7 @@
android:tag="disable"
android:text="@string/title_setup_oauth_authorize"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etEmail" />
app:layout_constraintTop_toBottomOf="@id/cbUpdate" />
<eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbOAuth"

@ -182,6 +182,8 @@
<string name="title_setup_office_remark">Microsoft does not provide this type of authorization for Outlook, Live, Hotmail, etc accounts</string>
<string name="title_setup_office_auth">The error \'AUTHENTICATE failed\' can be caused by IMAP/SMTP being disabled by the system administrator</string>
<string name="title_setup_oauth_rationale">Authorize access to your %1$s account</string>
<string name="title_setup_oauth_update">Authorize existing account again</string>
<string name="title_setup_oauth_updated">Account authorization was updated</string>
<string name="title_setup_oauth_authorize">Authorize</string>
<string name="title_setup_select_account">Select account</string>
<string name="title_setup_instructions">Setup instructions</string>

Loading…
Cancel
Save