Fix account url which wasn't updated in retrofit when its text field value was, in account creation activity
This commit is contained in:
parent
7ed5876285
commit
69bd33a428
@ -54,6 +54,7 @@ import org.jetbrains.annotations.NotNull;
|
|||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -526,6 +527,7 @@ public class MainActivity extends AppCompatActivity implements SwipeRefreshLayou
|
|||||||
adapter.clearData();
|
adapter.clearData();
|
||||||
|
|
||||||
if (!viewModel.isAccountLocal()) {
|
if (!viewModel.isAccountLocal()) {
|
||||||
|
getAccountCredentials(Collections.singletonList(newAccount));
|
||||||
refreshLayout.setRefreshing(true);
|
refreshLayout.setRefreshing(true);
|
||||||
onRefresh();
|
onRefresh();
|
||||||
}
|
}
|
||||||
|
@ -18,12 +18,19 @@ public abstract class API<T> {
|
|||||||
protected static final int MAX_ITEMS = 5000;
|
protected static final int MAX_ITEMS = 5000;
|
||||||
|
|
||||||
protected T api;
|
protected T api;
|
||||||
|
private Retrofit retrofit;
|
||||||
|
|
||||||
|
private Class<T> clazz;
|
||||||
|
private String endPoint;
|
||||||
|
|
||||||
public API(Credentials credentials, @NonNull Class<T> clazz, @NonNull 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 Retrofit getConfiguredRetrofitInstance(@NonNull String endPoint) {
|
protected Retrofit getConfiguredRetrofitInstance() {
|
||||||
return new Retrofit.Builder()
|
return new Retrofit.Builder()
|
||||||
.baseUrl(HttpManager.getInstance().getCredentials().getUrl() + endPoint)
|
.baseUrl(HttpManager.getInstance().getCredentials().getUrl() + endPoint)
|
||||||
.addConverterFactory(GsonConverterFactory.create())
|
.addConverterFactory(GsonConverterFactory.create())
|
||||||
@ -32,14 +39,20 @@ public abstract class API<T> {
|
|||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
private T createAPI(@NonNull Credentials credentials, @NonNull Class<T> clazz, @NonNull String endPoint) {
|
private T createAPI(@NonNull Credentials credentials) {
|
||||||
HttpManager.getInstance().setCredentials(credentials);
|
HttpManager.getInstance().setCredentials(credentials);
|
||||||
Retrofit retrofit = getConfiguredRetrofitInstance(endPoint);
|
retrofit = getConfiguredRetrofitInstance();
|
||||||
|
|
||||||
return retrofit.create(clazz);
|
return retrofit.create(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCredentials(@NonNull Credentials credentials) {
|
public void setCredentials(@NonNull Credentials credentials) {
|
||||||
HttpManager.getInstance().setCredentials(credentials);
|
HttpManager.getInstance().setCredentials(credentials);
|
||||||
|
|
||||||
|
retrofit = retrofit.newBuilder()
|
||||||
|
.baseUrl(credentials.getUrl() + endPoint)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
api = retrofit.create(clazz);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user