Fix account url which wasn't updated in retrofit when its text field value was, in account creation activity

This commit is contained in:
Shinokuni 2020-01-17 19:40:42 +01:00
parent a8404ef00f
commit 5a9ba348f7
2 changed files with 19 additions and 6 deletions

View File

@ -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);

View File

@ -19,14 +19,21 @@ public abstract class API<T> {
protected static final int MAX_ITEMS = 5000;
protected T api;
private Retrofit retrofit;
private Class<T> clazz;
private String endPoint;
public API(Credentials credentials, @NonNull Class<T> 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<T> {
.build();
}
private T createAPI(@NonNull Credentials credentials, @NonNull Class<T> 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);
}
}