class SimpleDialog : BaseDialogFragment(0, null) {
companion object {
const val DEF_DIALOG_TAG = "GabiDialog"
const val canBeCanceled = false
}
private val viewBinding: DialogGabiBinding by viewBinding(createMethod = CreateMethod.INFLATE)
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
isCancelable = canBeCanceled
val dialog = AlertDialog.Builder(requireContext())
.setView(viewBinding.root)
.setCancelable(canBeCanceled)
.create()
initDialogView(dialog)
return dialog
}
private fun initDialogView(dialog: AlertDialog) {
viewBinding.dialogTitle.apply {}
viewBinding.dialogContent.apply {}
viewBinding.confirmBtn.apply {}
viewBinding.cancelBtn.apply {}
}
fun showDialog(fragmentManager: FragmentManager, tag: String = DEF_DIALOG_TAG) {
if (fragmentManager.findFragmentByTag(tag) != null)
(fragmentManager.findFragmentByTag(tag) as? DialogFragment)
?.dismiss()
show(fragmentManager, tag)
}
}
abstract class BaseDialogFragment(
@LayoutRes private val layoutRes: Int,
private val onDismiss: (() -> Unit)? = null
): DialogFragment() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Timber.d("Lifecycle - onCreate %s", this.javaClass.name)
}
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View? {
return if (layoutRes != 0)
inflater.inflate(layoutRes, container, false)
else
null
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Timber.d("Lifecycle - onViewCreated %s", this.javaClass.name)
}
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val dialog = super.onCreateDialog(savedInstanceState)
Timber.d("Lifecycle - onCreateDialog %s", this.javaClass.name)
return dialog
}
override fun onStart() {
super.onStart()
Timber.d("Lifecycle - onStart() %s", this.javaClass.name)
}
override fun onStop() {
super.onStop()
Timber.d("Lifecycle - onStop() %s", this.javaClass.name)
}
override fun onResume() {
super.onResume()
Timber.d("Lifecycle - onResume() %s", this.javaClass.name)
}
override fun onPause() {
super.onPause()
Timber.d("Lifecycle - onPause() %s", this.javaClass.name)
}
override fun onDestroyView() {
super.onDestroyView()
Timber.d("Lifecycle - onDestroyView() %s", this.javaClass.name)
}
override fun onDestroy() {
super.onDestroy()
Timber.d("Lifecycle - onDestroy() %s", this.javaClass.name)
}
override fun onDismiss(dialog: DialogInterface) {
super.onDismiss(dialog)
onDismiss?.invoke()
}
}