mirror of
https://github.com/M66B/FairEmail.git
synced 2026-04-08 18:13:24 +02:00
Added 'edit' OAuth password
This commit is contained in:
@@ -19,6 +19,13 @@ package eu.faircode.email;
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||
|
||||
import android.app.NotificationManager;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -52,6 +59,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
|
||||
@@ -68,12 +76,6 @@ import java.util.Objects;
|
||||
|
||||
import javax.mail.Folder;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_NONE;
|
||||
import static com.google.android.material.textfield.TextInputLayout.END_ICON_PASSWORD_TOGGLE;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_PASSWORD;
|
||||
|
||||
public class FragmentAccount extends FragmentBase {
|
||||
private ViewGroup view;
|
||||
private ScrollView scroll;
|
||||
@@ -1394,6 +1396,11 @@ public class FragmentAccount extends FragmentBase {
|
||||
long id = args.getLong("id");
|
||||
|
||||
DB db = DB.getInstance(context);
|
||||
|
||||
List<EntityIdentity> identities = db.identity().getIdentities(id);
|
||||
if (identities != null && identities.size() == 1)
|
||||
args.putString("personal", identities.get(0).name);
|
||||
|
||||
return db.account().getAccount(id);
|
||||
}
|
||||
|
||||
@@ -1517,8 +1524,51 @@ public class FragmentAccount extends FragmentBase {
|
||||
|
||||
if (auth != AUTH_TYPE_PASSWORD) {
|
||||
etUser.setEnabled(false);
|
||||
tilPassword.setEnabled(false);
|
||||
tilPassword.getEditText().setEnabled(false);
|
||||
btnCertificate.setEnabled(false);
|
||||
|
||||
tilPassword.setEndIconDrawable(R.drawable.twotone_edit_24);
|
||||
tilPassword.setEndIconOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Fragment fragment;
|
||||
if (auth == AUTH_TYPE_GMAIL)
|
||||
fragment = new FragmentGmail();
|
||||
else if (auth == AUTH_TYPE_OAUTH)
|
||||
fragment = new FragmentOAuth();
|
||||
else {
|
||||
Log.e("Unknown auth=" + auth);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
Bundle aargs = new Bundle();
|
||||
if (auth == AUTH_TYPE_OAUTH) {
|
||||
if (account == null)
|
||||
throw new IllegalArgumentException("Account missing");
|
||||
|
||||
EmailProvider provider =
|
||||
EmailProvider.getProvider(view.getContext(), account.provider);
|
||||
aargs.putString("id", provider.id);
|
||||
aargs.putString("name", provider.description);
|
||||
aargs.putString("privacy", provider.oauth.privacy);
|
||||
aargs.putBoolean("askAccount", provider.oauth.askAccount);
|
||||
}
|
||||
aargs.putString("personal", args.getString("personal"));
|
||||
aargs.putString("address", etUser.getText().toString());
|
||||
aargs.putBoolean("update", true);
|
||||
|
||||
fragment.setArguments(aargs);
|
||||
|
||||
getParentFragmentManager().popBackStack();
|
||||
FragmentTransaction fragmentTransaction = getParentFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("quick");
|
||||
fragmentTransaction.commit();
|
||||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
cbOnDemand.setEnabled(cbSynchronize.isChecked());
|
||||
|
||||
@@ -19,6 +19,11 @@ package eu.faircode.email;
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import static android.accounts.AccountManager.newChooseAccountIntent;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static eu.faircode.email.GmailState.TYPE_GOOGLE;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL;
|
||||
|
||||
import android.Manifest;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
@@ -55,12 +60,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static android.accounts.AccountManager.newChooseAccountIntent;
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static eu.faircode.email.GmailState.TYPE_GOOGLE;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_GMAIL;
|
||||
|
||||
public class FragmentGmail extends FragmentBase {
|
||||
private String personal;
|
||||
private String address;
|
||||
private boolean update;
|
||||
|
||||
private ViewGroup view;
|
||||
private ScrollView scroll;
|
||||
|
||||
@@ -82,6 +86,18 @@ public class FragmentGmail extends FragmentBase {
|
||||
|
||||
private static final String PRIVACY_URI = "https://policies.google.com/privacy";
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
personal = args.getString("personal");
|
||||
address = args.getString("address");
|
||||
update = args.getBoolean("update");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
@@ -139,7 +155,6 @@ public class FragmentGmail extends FragmentBase {
|
||||
if (TextUtils.isEmpty(name))
|
||||
throw new IllegalArgumentException(getString(R.string.title_no_name));
|
||||
|
||||
|
||||
Intent intent = newChooseAccountIntent(
|
||||
null,
|
||||
null,
|
||||
@@ -183,6 +198,8 @@ public class FragmentGmail extends FragmentBase {
|
||||
// Initialize
|
||||
Helper.setViewsEnabled(view, false);
|
||||
tvTitle.setText(getString(R.string.title_setup_oauth_rationale, "Gmail"));
|
||||
etName.setText(personal);
|
||||
cbUpdate.setChecked(update);
|
||||
pbSelect.setVisibility(View.GONE);
|
||||
grpError.setVisibility(View.GONE);
|
||||
|
||||
@@ -226,7 +243,8 @@ public class FragmentGmail extends FragmentBase {
|
||||
btnGrant.setEnabled(!granted);
|
||||
tvGranted.setVisibility(granted ? View.VISIBLE : View.GONE);
|
||||
|
||||
if (granted) {
|
||||
boolean hasName = (etName.getText() != null && etName.getText().length() > 0);
|
||||
if (granted && !hasName) {
|
||||
try (Cursor cursor = getContext().getContentResolver().query(
|
||||
ContactsContract.Profile.CONTENT_URI,
|
||||
new String[]{ContactsContract.Profile.DISPLAY_NAME}, null, null, null)) {
|
||||
|
||||
@@ -19,6 +19,9 @@ package eu.faircode.email;
|
||||
Copyright 2018-2021 by Marcel Bokhorst (M66B)
|
||||
*/
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -84,15 +87,16 @@ import java.util.Map;
|
||||
import javax.mail.AuthenticationFailedException;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
import static eu.faircode.email.ServiceAuthenticator.AUTH_TYPE_OAUTH;
|
||||
|
||||
public class FragmentOAuth extends FragmentBase {
|
||||
private String id;
|
||||
private String name;
|
||||
private String privacy;
|
||||
private boolean askAccount;
|
||||
|
||||
private String personal;
|
||||
private String address;
|
||||
private boolean update;
|
||||
|
||||
private ViewGroup view;
|
||||
private ScrollView scroll;
|
||||
|
||||
@@ -124,6 +128,10 @@ public class FragmentOAuth extends FragmentBase {
|
||||
name = args.getString("name");
|
||||
privacy = args.getString("privacy");
|
||||
askAccount = args.getBoolean("askAccount", false);
|
||||
|
||||
personal = args.getString("personal");
|
||||
address = args.getString("address");
|
||||
update = args.getBoolean("update");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -187,6 +195,10 @@ public class FragmentOAuth extends FragmentBase {
|
||||
tvGmailHint.setVisibility("gmail".equals(id) ? View.VISIBLE : View.GONE);
|
||||
hideError();
|
||||
|
||||
etName.setText(personal);
|
||||
etEmail.setText(address);
|
||||
cbUpdate.setChecked(update);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user