From f089ed2033d749fc921592e30b64ceb90745e743 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Mon, 13 Mar 2017 19:13:49 +0100 Subject: [PATCH] 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 --- .../com/keylesspalace/tusky/LoginActivity.java | 17 +++++++++++++---- .../com/keylesspalace/tusky/MastodonAPI.java | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java index 32b3374f..07758956 100644 --- a/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java +++ b/app/src/main/java/com/keylesspalace/tusky/LoginActivity.java @@ -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 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 diff --git a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java index e881f996..da42829f 100644 --- a/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java +++ b/app/src/main/java/com/keylesspalace/tusky/MastodonAPI.java @@ -175,7 +175,7 @@ public interface MastodonAPI { @POST("api/v1/apps") Call authenticateApp( @Field("client_name") String clientName, - @Field("redirect_uris[]") List redirectUris, + @Field("redirect_uris") String redirectUris, @Field("scopes") String scopes, @Field("website") String website);