@@ -29,50 +29,41 @@ class DialogAppChooser(private val darkMode: Boolean): DialogFullScreen(R.layout
2929}
3030*/
3131
32- open class DialogFullScreen (private val layout : Int , darkMode : Boolean ) : androidx.fragment.app.DialogFragment() {
33- override fun onCreateView (inflater : LayoutInflater , container : ViewGroup ? , savedInstanceState : Bundle ? ): View ? {
34- currentView = inflater.inflate(layout, container)
35- return currentView
36- }
32+ open class DialogFullScreen (
33+ private val layout : Int ,
34+ darkMode : Boolean
35+ ) : DialogFragment() {
3736
38- private var themeResId: Int = 0
39- private lateinit var currentView: View
37+ init {
38+ setStyle(
39+ STYLE_NORMAL ,
40+ if (darkMode)
41+ R .style.dialog_full_screen_dark
42+ else
43+ R .style.dialog_full_screen_light
44+ )
45+ }
4046
41- override fun onCreateDialog ( savedInstanceState : Bundle ? ): Dialog {
42- return if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . M ) {
43- Dialog (activity !! , if (themeResId != 0 ) themeResId else R .style.dialog_full_screen_light)
44- } else {
45- Dialog (activity !! , - 1 )
46- }
47+ override fun onCreateView (
48+ inflater : LayoutInflater ,
49+ container : ViewGroup ? ,
50+ savedInstanceState : Bundle ?
51+ ): View {
52+ return inflater.inflate(layout, container, false )
4753 }
4854
4955 override fun onViewCreated (view : View , savedInstanceState : Bundle ? ) {
5056 super .onViewCreated(view, savedInstanceState)
5157
52- val activity = this .activity
53- if (activity != null ) {
54- dialog?.window?.run {
55- if (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) {
56- setWindowAnimations(android.R .style.Animation_Translucent )
57- }
58-
59- DialogHelper .setWindowBlurBg(this , activity)
58+ dialog?.window?.let { window ->
59+ if (Build .VERSION .SDK_INT < Build .VERSION_CODES .M ) {
60+ window.setWindowAnimations(android.R .style.Animation_Translucent )
6061 }
62+ DialogHelper .setWindowBlurBg(window, requireActivity())
6163 }
6264 }
6365
64- override fun onActivityCreated (savedInstanceState : Bundle ? ) {
65- super .onActivityCreated(savedInstanceState)
66- }
67-
6866 fun closeView () {
69- try {
70- dismiss()
71- } catch (ex: java.lang.Exception ) {
72- }
73- }
74-
75- init {
76- themeResId = if (darkMode) R .style.dialog_full_screen_dark else R .style.dialog_full_screen_light
67+ dismissAllowingStateLoss()
7768 }
7869}
0 commit comments