I have a custom progress bar class that I want to convert to an extension function so that i can use it any where in the project (Both fragment and activity) without initialising.
I want to be able to inflate the progress bar layout in the function and also have the one to dismiss the progress bar.
How can i do this?
class CustomProgressDialog(context: Context) : AlertDialog(context) {
private val messageTextView: TextView
init {
val view = LayoutInflater.from(context).inflate(R.layout.layout_loading_dialog, null)
messageTextView = view.findViewById(R.id.message)
setView(view)
}
override fun setMessage(message: CharSequence?) {
this.messageTextView.text = message.toString()
}
fun showProgressDialog(message: String) {
this.setMessage(message)
this.setCanceledOnTouchOutside(false)
this.setCancelable(false)
this.show()
}
fun hideProgressDialog() {
this.dismiss()
}
}