Last active
July 29, 2021 14:47
-
-
Save kibotu/aefadd42696dd1888ee1c64c15c24bd8 to your computer and use it in GitHub Desktop.
BaseDialogFragment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* https://github.com/exozet/AndroidCore/blob/master/core/src/main/java/com/exozet/android/core/extensions/Dialog%2BExtenions.kt | |
*/ | |
abstract class BaseDialogFragment : DialogFragment() { | |
/** | |
* Current dialog layout. | |
*/ | |
@get:LayoutRes | |
protected abstract val layout: Int | |
override fun onCreateDialog(savedInstanceState: Bundle?) = super.onCreateDialog(savedInstanceState).apply { | |
isCancelable = true | |
window?.setWindowAnimations(R.style.DialogAnimation) | |
}.addFullScreenFlags() | |
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View = inflater.inflate(layout, container, false) | |
fun show(): BaseDialogFragment { | |
val supportFragmentManager = (ActivityProvider.currentActivity as FragmentActivity).supportFragmentManager | |
if (supportFragmentManager.findFragmentByTag(javaClass.canonicalName) != null) return this | |
show(supportFragmentManager, javaClass.canonicalName) | |
return this | |
} | |
override fun onStart() { | |
super.onStart() | |
i("[Lifecycle-onStart]") | |
dialog?.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment