package com.live.mylivewallpaper.request;
import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

public class ObserverWrapper<T> implements Observer<T> {
    private OnRequestListener<T> requestListener;

    public ObserverWrapper(OnRequestListener<T> requestListener) {
        this.requestListener = requestListener;
    }

    @Override
    public void onSubscribe(Disposable d) {

    }

    @Override
    public void onNext(T t) {
//        String responseBody = (String) t;
//        ResponseBody responseBody = (ResponseBody) t;
//        InputStream inputStream = responseBody.byteStream();
//        Utils.writeFile(inputStream,App.context.getCacheDir()+"/test.mp4");


//        JSONObject jsonObject =  toJsonObject(responseBody);
//        try {
//            if (responseBody != null) {
//                if (jsonObject.has("playabilityStatus")) {
//                    String status = jsonObject.getJSONObject("playabilityStatus").getString("status");
//                    if (!status.equals("OK")) {
//                        requestListener.onFail("");
//                        return;
//                    }
//
//                }
                requestListener.onSuccess(t);
//            }

//        } catch (JSONException e) {
//            requestListener.onFail(e.getMessage());
//        }


    }

    @Override
    public void onError(Throwable e) {
        requestListener.onFail(e.getMessage());
    }

    @Override
    public void onComplete() {

    }



}

