I have a DialogFragment that allows the user to input long messages. By default, if the user clicks outside the DialogFragment or back button, the dialog is dismissed and the user inputs will be lost.
If I use "this.isCancelable = false", it entirely prevents the back button/outside click from firing, which I do not want.
Instead, I want to have a popup message to appear with "Are you sure you want to discard changes", and dismiss DialogFragment only if the user clicks yes then. How should I do this?
Edit: also tried to solve this with flags but still having issues.
Add to DialogFragment's "override fun OnResume()"
//FLAG_WATCH_OUTSIDE_TOUCH requires FLAG_NOT_TOUCH_MODAL to work
dialog?.window?.addFlags(
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
)
dialog?.window?.addFlags(
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
)
dialog?.window?.decorView?.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_OUTSIDE) {
//action to show a message
}
true
}
Problem with this approach is due to FLAG_NOT_TOUCH_MODAL, I can now click items behind the dialog, which messes up the navigation controller and breaks the app. Is it possible to monitor MotionEvent.ACTION_OUTSIDE, but prevents any actual clicks outside the dialog?