package epson.common;

import android.arch.lifecycle.MutableLiveData;
import android.arch.lifecycle.ViewModel;

import java.util.ArrayDeque;
import java.util.Deque;

public class DialogProgressViewModel extends ViewModel {
    public static final String DO_DISMISS = "do_dismiss";
    public static final String DO_SHOW = "do_show";
    private final MutableLiveData<Deque<String[]>> mJob = new MutableLiveData<>();
    private final Deque<String[]> mQueue = new ArrayDeque();

    public void doShow(String str) {
        mQueue.offer(new String[]{str, "do_show"});
        mJob.postValue(mQueue);
    }

    public void doDismiss(String str) {
        mQueue.offer(new String[]{str, "do_dismiss"});
        mJob.postValue(mQueue);
    }

    public MutableLiveData<Deque<String[]>> getDialogJob() {
        return mJob;
    }

    public String[] checkQueue() {
        String[] poll = mQueue.poll();
        if (poll != null) {
            mJob.postValue(mQueue);
        }
        return poll;
    }
}
