Base Dialog Fragment
A basic DialogFragment that handles layout inflation automatically without ViewBinding or DataBinding.
Extends RootDialogFragment to inherit dialog functionality and permission management.
ViewBinding이나 DataBinding 없이 레이아웃 인플레이션을 자동으로 처리하는 기본 DialogFragment입니다.
RootDialogFragment를 확장하여 다이얼로그 기능과 권한 관리를 상속받습니다.
Why this class exists / 이 클래스가 필요한 이유:
Android DialogFragments require manual layout inflation and view lifecycle management for every dialog.
This class eliminates boilerplate by accepting a layout resource ID and automatically handling inflation and cleanup.
Provides safe rootView access with null safety checks to prevent crashes after onDestroyView().
Ideal for simple dialogs that don't need ViewBinding/DataBinding overhead.
Android DialogFragment는 매번 수동으로 레이아웃 인플레이션과 뷰 생명주기 관리가 필요합니다.
이 클래스는 레이아웃 리소스 ID를 받아 자동으로 인플레이션과 정리를 처리하여 보일러플레이트를 제거합니다.
onDestroyView() 이후 크래시를 방지하기 위해 null 안전성 검사가 포함된 안전한 rootView 접근을 제공합니다.
ViewBinding/DataBinding 오버헤드가 필요하지 않은 간단한 다이얼로그에 이상적입니다.
Design decisions / 설계 결정 이유:
Uses constructor parameter for layout resource ID to enable simple single-line class declaration.
Uses nullable _rootView with public rootView accessor that throws exception after onDestroyView() for safe access.
Extends RootDialogFragment to inherit dialog functionality (animation, gravity, permissions).
Automatically sets rootView to null in onDestroyView() to prevent memory leaks.
간단한 한 줄 클래스 선언을 위해 생성자 파라미터로 레이아웃 리소스 ID를 사용합니다.
onDestroyView() 이후 안전한 접근을 위해 nullable _rootView와 예외를 던지는 public rootView 접근자를 사용합니다.
RootDialogFragment를 상속하여 다이얼로그 기능(애니메이션, gravity, 권한)을 상속받습니다.
메모리 누수를 방지하기 위해 onDestroyView()에서 자동으로 rootView를 null로 설정합니다.
Important notes / 주의사항:
Access rootView property only between onViewCreated() and onDestroyView() - accessing after onDestroyView() throws IllegalStateException.
Use findViewById() on rootView to access child views instead of ViewBinding.
For dialogs needing ViewBinding or DataBinding, use BaseViewBindingDialogFragment or BaseDataBindingDialogFragment instead.
rootView 프로퍼티는 onViewCreated()와 onDestroyView() 사이에서만 접근 - onDestroyView() 이후 접근 시 IllegalStateException 발생.
ViewBinding 대신 rootView에서 findViewById()를 사용하여 자식 뷰에 접근하세요.
ViewBinding이나 DataBinding이 필요한 다이얼로그는 BaseViewBindingDialogFragment 또는 BaseDataBindingDialogFragment를 사용하세요.
Usage / 사용법:
Extend this class with your DialogFragment and pass the layout resource ID.
Access views through findViewById() on rootView in onViewCreated() or later lifecycle methods.
No need to manually handle view inflation or cleanup - it's done automatically.
DialogFragment에서 이 클래스를 상속받고 레이아웃 리소스 ID를 전달하세요.
onViewCreated() 또는 이후 생명주기 메서드에서 rootView의 findViewById()를 통해 뷰에 접근하세요.
뷰 인플레이션이나 정리를 수동으로 처리할 필요 없음 - 자동으로 수행됩니다.
Usage example:
class ConfirmDialog : BaseDialogFragment(R.layout.dialog_confirm) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
rootView.findViewById<TextView>(R.id.tvTitle).text = "Confirm"
rootView.findViewById<Button>(R.id.btnOk).setOnClickListener {
safeDismiss()
}
}
}Parameters
The layout resource ID for the dialog.
다이얼로그의 레이아웃 리소스 ID.
Whether to attach the inflated view to the parent container.
인플레이션된 뷰를 부모 컨테이너에 첨부할지 여부.
DialogFragment에서는 특별한 경우가 아니라면 기본값 false 사용을 권장합니다.
반환된 root view는 DialogFragment framework가 다시 처리하므로 true 사용 시 parent 중복 attach 예외가 발생할 수 있습니다.
See also
For base class with dialog and permission features.
다이얼로그 및 권한 기능이 있는 기본 클래스는 RootDialogFragment를 참조하세요.
For the abstract parent class of all binding-enabled dialog fragments.
모든 바인딩 지원 DialogFragment의 추상 부모 클래스는 ParentBindingViewDialogFragment를 참조하세요.
For ViewBinding-enabled DialogFragment.
ViewBinding을 사용하는 DialogFragment는 BaseViewBindingDialogFragment를 참조하세요.
For DataBinding-enabled DialogFragment.
DataBinding을 사용하는 DialogFragment는 BaseDataBindingDialogFragment를 참조하세요.
Properties
Functions
Requests permissions using the delegate.
Call only after the Fragment is attached (isAdded == true).
델리게이트를 사용하여 권한을 요청합니다.
Fragment가 attach된 이후(isAdded == true)에만 호출하세요.
Requests multiple permissions and returns denied results via callback.
여러 권한을 요청하고 거부 결과를 콜백으로 반환합니다.
Safely dismisses the dialog with exception handling.
Catches any exceptions that may occur during dismissal.
예외 처리와 함께 다이얼로그를 안전하게 닫습니다.
닫는 동안 발생할 수 있는 모든 예외를 잡습니다.
Safely shows the dialog with exception handling.
Catches any exceptions that may occur during showing.
예외 처리와 함께 다이얼로그를 안전하게 표시합니다.
표시하는 동안 발생할 수 있는 모든 예외를 잡습니다.
Sets the custom animation style for dialog appearance/disappearance.
Applied immediately if dialog is already showing.
다이얼로그 나타남/사라짐에 대한 커스텀 애니메이션 스타일을 설정합니다.
다이얼로그가 이미 표시 중인 경우 즉시 적용됩니다.
Sets whether the dialog can be canceled by pressing back button or touching outside.
Applied immediately if dialog is already showing.
뒤로 가기 버튼을 누르거나 외부를 터치하여 다이얼로그를 취소할 수 있는지 설정합니다.
다이얼로그가 이미 표시 중인 경우 즉시 적용됩니다.
Sets the position of the dialog on screen.
Applied immediately if dialog is already showing.
화면에서 다이얼로그의 위치를 설정합니다.
다이얼로그가 이미 표시 중인 경우 즉시 적용됩니다.
Creates and shows an indefinite duration Snackbar from a Fragment.
Logs an error if the Fragment's view is null.
Fragment에서 무제한 시간 Snackbar를 생성하고 표시합니다.
Fragment의 view가 null이면 에러를 로깅합니다.
Creates and shows a long duration Snackbar from a Fragment.
Logs an error if the Fragment's view is null.
Fragment에서 긴 시간 Snackbar를 생성하고 표시합니다.
Fragment의 view가 null이면 에러를 로깅합니다.
Creates and shows a short duration Snackbar from a Fragment.
Logs an error if the Fragment's view is null.
Fragment에서 짧은 시간 Snackbar를 생성하고 표시합니다.
Fragment의 view가 null이면 에러를 로깅합니다.
Creates and shows a long duration Toast message from a Fragment.
Logs an error if the Fragment's context is null.
Fragment에서 긴 시간 Toast 메시지를 생성하고 표시합니다.
Fragment의 context가 null이면 에러를 로깅합니다.
Creates and shows a short duration Toast message from a Fragment.
Logs an error if the Fragment's context is null.
Fragment에서 짧은 시간 Toast 메시지를 생성하고 표시합니다.
Fragment의 context가 null이면 에러를 로깅합니다.
Executes the given block and returns a result if the Fragment's context is not null.
Returns null and logs an error if the context is null.
Fragment의 context가 null이 아닌 경우 주어진 블록을 실행하고 결과를 반환합니다.
context가 null이면 null을 반환하고 에러를 로깅합니다.
Executes the given block and returns a result if the Fragment's view is not null.
Returns null and logs an error if the view is null.
Fragment의 view가 null이 아닌 경우 주어진 블록을 실행하고 결과를 반환합니다.
view가 null이면 null을 반환하고 에러를 로깅합니다.