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

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

@ -63,6 +63,16 @@
<requestFocus /> <requestFocus />
</eu.faircode.email.EditTextPlain> </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 <Button
android:id="@+id/btnSelect" android:id="@+id/btnSelect"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -71,7 +81,7 @@
android:tag="disable" android:tag="disable"
android:text="@string/title_setup_select_account" android:text="@string/title_setup_select_account"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" /> app:layout_constraintTop_toBottomOf="@id/cbUpdate" />
<eu.faircode.email.ContentLoadingProgressBar <eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbSelect" android:id="@+id/pbSelect"

@ -52,6 +52,16 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etName" /> 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 <Button
android:id="@+id/btnOAuth" android:id="@+id/btnOAuth"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@ -60,7 +70,7 @@
android:tag="disable" android:tag="disable"
android:text="@string/title_setup_oauth_authorize" android:text="@string/title_setup_oauth_authorize"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/etEmail" /> app:layout_constraintTop_toBottomOf="@id/cbUpdate" />
<eu.faircode.email.ContentLoadingProgressBar <eu.faircode.email.ContentLoadingProgressBar
android:id="@+id/pbOAuth" 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_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_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_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_oauth_authorize">Authorize</string>
<string name="title_setup_select_account">Select account</string> <string name="title_setup_select_account">Select account</string>
<string name="title_setup_instructions">Setup instructions</string> <string name="title_setup_instructions">Setup instructions</string>

Loading…
Cancel
Save