You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pocketcommunityclient/app/src/main/java/com/community/pocket/util/SimpleHttpParse.java

40 lines
1.1 KiB

package com.community.pocket.util;
import androidx.annotation.StringRes;
import androidx.lifecycle.MutableLiveData;
import org.jetbrains.annotations.NotNull;
import okhttp3.Call;
import okhttp3.Response;
public class SimpleHttpParse<T extends com.community.pocket.ui.main.ui.share.Response> implements HttpParse<T> {
private MutableLiveData liveData;
private Integer success;
private Integer error;
public SimpleHttpParse(MutableLiveData liveData, @StringRes Integer success, @StringRes Integer error) {
this.liveData = liveData;
this.success = success;
this.error = error;
}
public HttpResponse<T> getInterface(Class<T> tClass) {
return new HttpResponse<>(tClass, this);
}
@Override
@SuppressWarnings("unchecked")
public void onParseOk(@NotNull Call call, @NotNull Response response, T t) {
if (t.getResult() == com.community.pocket.ui.main.ui.share.Response.Result.OK) {
t.setSuccess(success);
} else {
t.setError(error);
}
liveData.postValue(t);
}
}