package it.integry.integrywmsnative.view.dialogs;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;

import androidx.databinding.DataBindingUtil;

import it.integry.integrywmsnative.R;
import it.integry.integrywmsnative.databinding.DialogProgressBinding;

public class DialogProgress {

    private Context mContext;
    private DialogProgressBinding mBinding;

    private Dialog mDialog;

    public static Dialog make(Context context,String subtitle) {
        DialogProgress progress = new DialogProgress(context);
        progress.setSubtitle(subtitle);
        return progress.mDialog;
    }

    public static Dialog make(Context context) {
        return new DialogProgress(context).mDialog;
    }



    private DialogProgress(Context context) {
        mContext = context;

        LayoutInflater inflater = (LayoutInflater) context.getSystemService( Context.LAYOUT_INFLATER_SERVICE );
        mBinding = DataBindingUtil.inflate(inflater, R.layout.dialog_progress, null, false);

//        final Thread[] progressBarThread = new Thread[1];

        mDialog = new Dialog(mContext);
        mDialog.setContentView(mBinding.getRoot());
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setCancelable(false);
        mDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

        mDialog.setOnShowListener(dialog -> {
//            ((ProgressBar) currentView.findViewById(R.id.progressBar)).setIndeterminate(true);
//            progressBarThread[0] = UtilityProgress.makeProgressBarIndeterminate(mBinding.progressBar);
        });

        mDialog.setOnDismissListener(dialog -> {
//            progressBarThread[0].interrupt();
        });
    }

    private void setSubtitle(String subtitle){
        mBinding.subtitleText.setText(subtitle);
    }

}
