Fix usage of Retrofit in LoginActivity - baseUrl wasn't
being set correctly since BaseActivity relies on the already saved preference LoginActivity instantiated its own, trimmed down MastodonAPI instance
This commit is contained in:
parent
60cef27c86
commit
b3c7f94951
2 changed files with 14 additions and 5 deletions
|
@ -39,6 +39,8 @@ import java.util.Map;
|
|||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
|
||||
public class LoginActivity extends BaseActivity {
|
||||
private static String OAUTH_SCOPES = "read write follow";
|
||||
|
@ -94,6 +96,15 @@ public class LoginActivity extends BaseActivity {
|
|||
startActivity(viewIntent);
|
||||
}
|
||||
|
||||
private MastodonAPI getApiFor(String domain) {
|
||||
Retrofit retrofit = new Retrofit.Builder()
|
||||
.baseUrl("https://" + domain)
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.build();
|
||||
|
||||
return retrofit.create(MastodonAPI.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain the oauth client credentials for this app. This is only necessary the first time the
|
||||
* app is run on a given server instance. So, after the first authentication, they are
|
||||
|
@ -134,9 +145,7 @@ public class LoginActivity extends BaseActivity {
|
|||
}
|
||||
};
|
||||
|
||||
List<String> redirectUris = new ArrayList<>();
|
||||
redirectUris.add(getOauthRedirectUri());
|
||||
mastodonAPI.authenticateApp(getString(R.string.app_name), redirectUris, OAUTH_SCOPES,
|
||||
getApiFor(domain).authenticateApp(getString(R.string.app_name), getOauthRedirectUri(), OAUTH_SCOPES,
|
||||
getString(R.string.app_website)).enqueue(callback);
|
||||
|
||||
}
|
||||
|
@ -245,7 +254,7 @@ public class LoginActivity extends BaseActivity {
|
|||
editText.setError(t.getMessage());
|
||||
}
|
||||
};
|
||||
mastodonAPI.fetchOAuthToken(clientId, clientSecret, redirectUri, code,
|
||||
getApiFor(domain).fetchOAuthToken(clientId, clientSecret, redirectUri, code,
|
||||
"authorization_code").enqueue(callback);
|
||||
} else if (error != null) {
|
||||
/* Authorization failed. Put the error response where the user can read it and they
|
||||
|
|
|
@ -175,7 +175,7 @@ public interface MastodonAPI {
|
|||
@POST("api/v1/apps")
|
||||
Call<AppCredentials> authenticateApp(
|
||||
@Field("client_name") String clientName,
|
||||
@Field("redirect_uris[]") List<String> redirectUris,
|
||||
@Field("redirect_uris") String redirectUris,
|
||||
@Field("scopes") String scopes,
|
||||
@Field("website") String website);
|
||||
|
||||
|
|
Loading…
Reference in a new issue