From 5a9ba348f74d35428c59b7156682dda1051b1036 Mon Sep 17 00:00:00 2001 From: Shinokuni Date: Fri, 17 Jan 2020 19:40:42 +0100 Subject: [PATCH] Fix account url which wasn't updated in retrofit when its text field value was, in account creation activity --- .../readrops/app/activities/MainActivity.java | 4 ++-- .../readropslibrary/services/API.java | 21 +++++++++++++++---- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/com/readrops/app/activities/MainActivity.java b/app/src/main/java/com/readrops/app/activities/MainActivity.java index 256b1fdb..a18cec5e 100644 --- a/app/src/main/java/com/readrops/app/activities/MainActivity.java +++ b/app/src/main/java/com/readrops/app/activities/MainActivity.java @@ -550,10 +550,10 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou adapter.clearData(); if (!viewModel.isAccountLocal()) { + getAccountCredentials(Collections.singletonList(newAccount)); refreshLayout.setRefreshing(true); onRefresh(); - } else - getAccountCredentials(Collections.singletonList(newAccount)); + } drawerManager.resetItems(); drawerManager.addAccount(newAccount, true); diff --git a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/API.java b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/API.java index 47a14957..aa4aaaa8 100644 --- a/readropslibrary/src/main/java/com/readrops/readropslibrary/services/API.java +++ b/readropslibrary/src/main/java/com/readrops/readropslibrary/services/API.java @@ -19,14 +19,21 @@ public abstract class API { protected static final int MAX_ITEMS = 5000; protected T api; + private Retrofit retrofit; + + private Class clazz; + private String endPoint; public API(Credentials credentials, @NonNull Class clazz, @NonNull String endPoint) { - api = createAPI(credentials, clazz, endPoint); + this.clazz = clazz; + this.endPoint = endPoint; + + api = createAPI(credentials); } protected abstract Moshi buildMoshi(); - protected Retrofit getConfiguredRetrofitInstance(@NonNull String endPoint) { + protected Retrofit getConfiguredRetrofitInstance() { return new Retrofit.Builder() .baseUrl(HttpManager.getInstance().getCredentials().getUrl() + endPoint) .addConverterFactory(MoshiConverterFactory.create(buildMoshi())) @@ -35,14 +42,20 @@ public abstract class API { .build(); } - private T createAPI(@NonNull Credentials credentials, @NonNull Class clazz, @NonNull String endPoint) { + private T createAPI(@NonNull Credentials credentials) { HttpManager.getInstance().setCredentials(credentials); - Retrofit retrofit = getConfiguredRetrofitInstance(endPoint); + retrofit = getConfiguredRetrofitInstance(); return retrofit.create(clazz); } public void setCredentials(@NonNull Credentials credentials) { HttpManager.getInstance().setCredentials(credentials); + + retrofit = retrofit.newBuilder() + .baseUrl(credentials.getUrl() + endPoint) + .build(); + + api = retrofit.create(clazz); } }