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 implements HttpParse { 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 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); } }