package com.casic.dcms.mvp.presenter;

import com.casic.dcms.bean.ActionResultBean;
import com.casic.dcms.mvp.BasePresenter;
import com.casic.dcms.mvp.model.UploadAudioModelImpl;
import com.casic.dcms.mvp.view.IUploadFileView;

import java.io.File;

public class UploadAudioPresenterImpl extends BasePresenter implements IUploadFilePresenter, UploadAudioModelImpl.OnUploadAudioListener {

    private IUploadFileView view;
    private UploadAudioModelImpl actionModel;

    public UploadAudioPresenterImpl(IUploadFileView uploadAudioView) {
        this.view = uploadAudioView;
        actionModel = new UploadAudioModelImpl(this);
    }

    @Override
    public void onReadyRetrofitRequest(File file) {
        view.showProgress();
        addSubscription(actionModel.sendRetrofitRequest(file));
    }

    @Override
    public void onSuccess(ActionResultBean resultBean) {
        view.hideProgress();
        view.obtainUploadAudioResult(resultBean);
    }

    @Override
    public void onFailure(Throwable throwable) {
        view.hideProgress();
        view.obtainDataFail();
    }

    @Override
    public void disposeRetrofitRequest() {
        unSubscription();
    }
}
