mirror of
https://github.com/M66B/FairEmail.git
synced 2025-02-27 16:33:47 +00:00
Refactoring
This commit is contained in:
parent
ac27c9bb80
commit
fe7ba69e80
1 changed files with 23 additions and 21 deletions
|
@ -1157,7 +1157,11 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private AuthorizationService getAuthorizationService() {
|
||||
private void onOAuth(Intent intent) {
|
||||
try {
|
||||
String name = intent.getStringExtra("name");
|
||||
for (EmailProvider provider : EmailProvider.loadProfiles(this))
|
||||
if (provider.name.equals(name) && provider.oauth != null) {
|
||||
AppAuthConfiguration appAuthConfig = new AppAuthConfiguration.Builder()
|
||||
.setBrowserMatcher(new BrowserMatcher() {
|
||||
@Override
|
||||
|
@ -1167,19 +1171,13 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
Browsers.SBrowser.SIGNATURE_SET,
|
||||
true,
|
||||
VersionRange.atMost("5.3"));
|
||||
return descriptor.useCustomTab && !sbrowser.matches(descriptor);
|
||||
return !sbrowser.matches(descriptor);
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
return new AuthorizationService(this, appAuthConfig);
|
||||
}
|
||||
AuthorizationService authService = new AuthorizationService(this, appAuthConfig);
|
||||
|
||||
private void onOAuth(Intent intent) {
|
||||
try {
|
||||
String name = intent.getStringExtra("name");
|
||||
for (EmailProvider provider : EmailProvider.loadProfiles(this))
|
||||
if (provider.name.equals(name) && provider.oauth != null) {
|
||||
AuthorizationServiceConfiguration serviceConfig = new AuthorizationServiceConfiguration(
|
||||
Uri.parse(provider.oauth.authorizationEndpoint),
|
||||
Uri.parse(provider.oauth.tokenEndpoint));
|
||||
|
@ -1199,7 +1197,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
.build();
|
||||
|
||||
Log.i("OAuth request provider=" + provider.name);
|
||||
Intent authIntent = getAuthorizationService().getAuthorizationRequestIntent(authRequest);
|
||||
Intent authIntent = authService.getAuthorizationRequestIntent(authRequest);
|
||||
startActivityForResult(authIntent, REQUEST_OAUTH);
|
||||
|
||||
return;
|
||||
|
@ -1221,9 +1219,12 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
if (provider.name.equals(auth.state)) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
final AuthState authState = AuthState.jsonDeserialize(prefs.getString("oauth." + provider.name, null));
|
||||
authState.update(auth, null);
|
||||
prefs.edit().remove("oauth." + provider.name).apply();
|
||||
|
||||
authState.update(auth, null);
|
||||
|
||||
AuthorizationService authService = new AuthorizationService(this);
|
||||
|
||||
ClientAuthentication clientAuth;
|
||||
if (provider.oauth.clientSecret == null)
|
||||
clientAuth = NoClientAuthentication.INSTANCE;
|
||||
|
@ -1231,7 +1232,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
clientAuth = new ClientSecretPost(provider.oauth.clientSecret);
|
||||
|
||||
Log.i("OAuth get token provider=" + provider.name);
|
||||
getAuthorizationService().performTokenRequest(
|
||||
authService.performTokenRequest(
|
||||
auth.createTokenExchangeRequest(),
|
||||
clientAuth,
|
||||
new AuthorizationService.TokenResponseCallback() {
|
||||
|
@ -1451,6 +1452,7 @@ public class ActivitySetup extends ActivityBase implements FragmentManager.OnBac
|
|||
|
||||
@Override
|
||||
protected void onException(Bundle args, Throwable ex) {
|
||||
// TODO: Handle IllegalArgumentException
|
||||
Log.unexpectedError(getSupportFragmentManager(), ex);
|
||||
}
|
||||
}.execute(ActivitySetup.this, args, "oauth:configure");
|
||||
|
|
Loading…
Reference in a new issue