package com.app.duck.dialog;

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

import android.app.Activity;
import android.app.ProgressDialog;
import android.widget.EditText;

import androidx.appcompat.app.AlertDialog;

import com.blankj.utilcode.util.ActivityUtils;
import com.blankj.utilcode.util.StringUtils;
import com.app.duck.R;
import com.app.duck.ui.MainActivity;
import com.app.duck.util.HxUtils;
import com.jeremyliao.liveeventbus.LiveEventBus;

public class DialogManager {

    private static DialogManager manager;
    public ProgressDialog progressDialog;

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

    public static void phoneEditDialog() {
        Activity context = ActivityUtils.getTopActivity();
        androidx.appcompat.app.AlertDialog.Builder builder = new androidx.appcompat.app.AlertDialog.Builder(context);
        builder.setTitle(R.string.phone_number);
        builder.setMessage(R.string.number);
        final EditText editText = new EditText(context);
        builder.setView(editText);
        builder.setPositiveButton(R.string.ok, (dialog, which) -> {
            String name = editText.getText().toString();
            if (!StringUtils.isEmpty(name)) {
                HxUtils.setPhone(name);
                LiveEventBus.get(PHONE_TAG).post(name);
            }
        });
        builder.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.cancel());
        AlertDialog dialog = builder.create();
        dialog.show();
    }


}
