package com.community.pocket.util; import androidx.annotation.StringRes; import androidx.lifecycle.MutableLiveData; import org.jetbrains.annotations.NotNull; import okhttp3.Call; import okhttp3.Response; /** * HTTP响应实体 * * @param */ public class SimpleHttpParse implements HttpParse { private MutableLiveData liveData; //TODO 废弃 @Deprecated private Integer success; //TODO 废弃 @Deprecated private Integer error; //TODO 废弃 @Deprecated public SimpleHttpParse(MutableLiveData liveData, @StringRes Integer success, @StringRes Integer error) { this.liveData = liveData; this.success = success; this.error = error; } public SimpleHttpParse(MutableLiveData liveData) { this.liveData = liveData; } public HttpResponse getInterface(Class 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); } }