package com.app.duck.dialog;

import static com.app.duck.Config.PHONE_TAG;

import android.text.TextUtils;

import com.afollestad.materialdialogs.MaterialDialog;
import com.app.duck.R;
import com.app.duck.util.HxUtils;
import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.StringUtils;
import com.jeremyliao.liveeventbus.LiveEventBus;

public class DialogManager {

    private static DialogManager manager;

    public static DialogManager getInstance() {
        if (manager == null) {
            manager = new DialogManager();
        }
        return manager;
    }

    public static void phoneEditDialog() {
        new MaterialDialog.Builder(ActivityUtils.getTopActivity())
                .title(R.string.phone_number)
                .canceledOnTouchOutside(false)
                .autoDismiss(false)
                .negativeText(R.string.cancel)
                .positiveText(R.string.done)
                .onNegative((dialog, which) -> dialog.dismiss())
                .onPositive((dialog, which) -> dialog.dismiss())
                .input("", TextUtils.isEmpty(HxUtils.getPhone()) ? "" : HxUtils.getPhone(), false, (dialog, input) ->
                {
                    if (!StringUtils.isEmpty(input)) {
                        HxUtils.setPhone(input.toString());
                        LiveEventBus.get(PHONE_TAG).post(input.toString());
                        dialog.dismiss();
                    }
                }).show();
    }


}
