package com.doverfuelingsolutions.issp.view.util

import android.content.Context
import android.view.View
import android.widget.TextView
import androidx.annotation.StringRes
import com.doverfuelingsolutions.issp.R
import com.doverfuelingsolutions.issp.utils.StringUtil
import com.google.android.material.dialog.MaterialAlertDialogBuilder

class LoadingDialogBuilder(context: Context) : MaterialAlertDialogBuilder(context) {

    // loading view
    private val loadingView = View.inflate(context, R.layout.layout_loading, null)
    private val loadingText: TextView = loadingView.findViewById(R.id.loadingTip)
    init {
        setView(loadingView)
    }

    override fun setTitle(titleId: Int): LoadingDialogBuilder {
        super.setTitle(titleId)
        return this
    }

    override fun setCancelable(cancelable: Boolean): LoadingDialogBuilder {
        super.setCancelable(cancelable)
        return this
    }

    fun setLoadingText(@StringRes string: Int) = setLoadingText(StringUtil.get(string))

    fun setLoadingText(string: String): LoadingDialogBuilder {
        loadingText.text = string
        return this
    }
}