package epson.maintain.activity;

import android.app.Application;
import android.arch.lifecycle.AndroidViewModel;
import android.arch.lifecycle.MutableLiveData;
import android.net.Uri;
import android.os.AsyncTask;
import epson.common.EventWrapper;
import epson.print.CommonDefine;
import epson.print.Util.BuyInkUrl;

public class MaintainBuyInkOnlineRegTask extends AndroidViewModel {
    public static final int URL_BUY_INK = 1;
    public static final int URL_NOZZLE_CHECK = 2;
    private boolean mState = true;
    private MutableLiveData<EventWrapper<Uri>> mUriEvent;

    public MaintainBuyInkOnlineRegTask(Application application) {
        super(application);
    }

    public void setReady(boolean z) {
        mState = z;
    }

    public boolean getReady() {
        return mState;
    }

    public void setUriEvent(Uri uri) {
        if (mUriEvent == null) {
            mUriEvent = new MutableLiveData<>();
        }
        mUriEvent.setValue(new EventWrapper(uri));
    }

    public MutableLiveData<EventWrapper<Uri>> getUriEvent() {
        if (mUriEvent == null) {
            mUriEvent = new MutableLiveData<>();
        }
        return mUriEvent;
    }

    public void loadData(final int i, final String str) {
        final Application application = getApplication();
        new AsyncTask<Void, Void, Uri>() {
            protected void onPreExecute() {
                super.onPreExecute();
                MaintainBuyInkOnlineRegTask.this.setReady(false);
            }

            protected Uri doInBackground(Void... voidArr) {
                MaintainActivity.disableSimpleApAndWait(application, str);
                if (i != 2) {
                    return BuyInkUrl.getBuyInkUri(application);
                }
                return BuyInkUrl.getNozzleCheckGuidanceUri(application);
            }

            protected void onPostExecute(Uri uri) {
                super.onPostExecute(uri);
                MaintainBuyInkOnlineRegTask.this.setUriEvent(uri);
                MaintainBuyInkOnlineRegTask.this.setReady(true);
            }
        }.execute(new Void[0]);
    }

    public void loadData(final String str) {
        final Application application = getApplication();
        new AsyncTask<Void, Void, Uri>() {
            protected void onPreExecute() {
                super.onPreExecute();
                MaintainBuyInkOnlineRegTask.this.setReady(false);
            }

            protected Uri doInBackground(Void... voidArr) {
                MaintainActivity.disableSimpleApAndWait(application, str);
                return Uri.parse(BuyInkUrl.urlSupport(application, CommonDefine.URL_ONLINE_REGISTRATION));
            }

            protected void onPostExecute(Uri uri) {
                super.onPostExecute(uri);
                MaintainBuyInkOnlineRegTask.this.setUriEvent(uri);
                MaintainBuyInkOnlineRegTask.this.setReady(true);
            }
        }.execute(new Void[0]);
    }
}
