diff --git a/app/src/main/java/com/sn/snfilemanager/core/base/BaseDialog.kt b/app/src/main/java/com/sn/snfilemanager/core/base/BaseDialog.kt new file mode 100644 index 0000000..5df1baf --- /dev/null +++ b/app/src/main/java/com/sn/snfilemanager/core/base/BaseDialog.kt @@ -0,0 +1,59 @@ +package com.sn.snfilemanager.core.base + +import android.os.Bundle +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import androidx.constraintlayout.widget.ConstraintLayout +import androidx.fragment.app.DialogFragment +import androidx.fragment.app.FragmentManager +import androidx.viewbinding.ViewBinding +import com.sn.snfilemanager.R + +abstract class BaseDialog : DialogFragment() { + protected lateinit var binding: VBinding + + protected abstract fun getViewBinding(): VBinding + + open var setCancelable: Boolean = true + + protected abstract val dialogTag: String + + open fun setupViews() {} + + fun showDialog(fragmentManager: FragmentManager) { + show(fragmentManager, dialogTag) + } + + override fun onStart() { + super.onStart() + dialog?.window?.setLayout( + ConstraintLayout.LayoutParams.MATCH_PARENT, + ConstraintLayout.LayoutParams.WRAP_CONTENT, + ) + } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + binding = getViewBinding() + isCancelable = setCancelable + setStyle(STYLE_NO_TITLE, R.style.DialogTheme_transparent) + dialog?.window?.setBackgroundDrawableResource(R.drawable.dialog_rounded) + } + + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle?, + ): View? { + return binding.root + } + + override fun onViewCreated( + view: View, + savedInstanceState: Bundle?, + ) { + super.onViewCreated(view, savedInstanceState) + setupViews() + } +} diff --git a/app/src/main/java/com/sn/snfilemanager/feature/about/AboutFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/about/AboutFragment.kt index 52ba261..d421688 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/about/AboutFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/about/AboutFragment.kt @@ -28,6 +28,6 @@ class AboutFragment : BaseFragment() { } private fun showLicensesDialog() { - LicenseDialog().show(childFragmentManager, LicenseDialog.TAG) + LicenseDialog().showDialog(childFragmentManager) } } diff --git a/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt index df545c6..83a13ac 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/files/presentation/FilesListFragment.kt @@ -207,12 +207,12 @@ class FilesListFragment : override fun observeData() { observe(viewModel.conflictQuestionLiveData) { event -> event.getContentIfNotHandled()?.let { fileName -> - ConflictDialog(requireContext(), fileName).apply { + ConflictDialog(fileName).apply { onSelected = { strategy: ConflictStrategy, isAll: Boolean -> viewModel.conflictDialogDeferred.complete(Pair(strategy, isAll)) } onDismiss = { actionMode?.finish() } - }.show() + }.showDialog(childFragmentManager) } } observe(viewModel.startMoveJobLiveData) { event -> @@ -370,29 +370,26 @@ class FilesListFragment : } else { viewModel.moveFilesAndDirectories(Paths.get(path)) } - }).show( - childFragmentManager, - DetailDialog.TAG, - ) + }).showDialog(childFragmentManager) } private fun showCreateDirectoryDialog(path: String) { CreateDirectoryDialog(path = path, onCreate = { folderName -> viewModel.createFolder(folderName) - }).show(childFragmentManager, CreateDirectoryDialog.TAG) + }).showDialog(childFragmentManager) } private fun showRenameDialog() { RenameFileDialog(file = viewModel.getSelectedItem().first(), onRename = { newName -> viewModel.renameFile(newName) - }).show(childFragmentManager, RenameFileDialog.TAG) + }).showDialog(childFragmentManager) } private fun actionDetail() { - DetailDialog(requireContext(), viewModel.getSelectedItem()).show( - childFragmentManager, - DetailDialog.TAG, - ) + DetailDialog( + requireContext(), + viewModel.getSelectedItem(), + ).showDialog(childFragmentManager) } private fun actionOpenWith() { @@ -412,7 +409,6 @@ class FilesListFragment : private fun actionDelete() { ConfirmationDialog( - requireContext(), getString(R.string.are_you_sure), getString(R.string.delete_warning), ).apply { @@ -423,7 +419,7 @@ class FilesListFragment : actionMode?.finish() } } - }.show() + }.showDialog(childFragmentManager) } private fun startCopyService( diff --git a/app/src/main/java/com/sn/snfilemanager/feature/home/HomeFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/home/HomeFragment.kt index 92d2427..81b8964 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/home/HomeFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/home/HomeFragment.kt @@ -161,20 +161,19 @@ class HomeFragment : BaseFragment() { } private fun showPermissionDialog(type: PermissionDialogType = PermissionDialogType.DEFAULT) { - if (permissionDialog == null || permissionDialog?.isShowing == false) { + if (permissionDialog == null || permissionDialog?.isVisible == false) { permissionDialog = - PermissionDialog(requireContext(), type).apply { + PermissionDialog(type).apply { onAllow = { allowStoragePermission() } } - permissionDialog?.show() + permissionDialog?.showDialog(childFragmentManager) } } private fun showNotificationDialog() { - if (confirmationDialog == null || confirmationDialog?.isShowing == false) { + if (confirmationDialog == null || confirmationDialog?.isVisible == false) { confirmationDialog = ConfirmationDialog( - requireContext(), getString(R.string.permission_warning_title), getString(R.string.notification_permission_info), ).apply { @@ -184,7 +183,7 @@ class HomeFragment : BaseFragment() { } } } - confirmationDialog?.show() + confirmationDialog?.showDialog(childFragmentManager) } } diff --git a/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt index f35b349..ecbb9be 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/media/presentation/MediaFragment.kt @@ -180,6 +180,7 @@ class MediaFragment : data?.filterIsInstance()?.let { adapter?.removeItems(it) } } } + JobType.CREATE -> {} JobType.RENAME -> {} } @@ -195,12 +196,12 @@ class MediaFragment : } observe(conflictQuestionLiveData) { event -> event.getContentIfNotHandled()?.let { mediaName -> - ConflictDialog(requireContext(), mediaName).apply { + ConflictDialog(mediaName).apply { onSelected = { strategy: ConflictStrategy, isAll: Boolean -> viewModel.conflictDialogDeferred.complete(Pair(strategy, isAll)) } onDismiss = { actionMode?.finish() } - }.show() + }.showDialog(childFragmentManager) } } observe(viewModel.startMoveJobLiveData) { event -> @@ -239,7 +240,6 @@ class MediaFragment : private fun actionDelete() { ConfirmationDialog( - requireContext(), getString(R.string.are_you_sure), getString(R.string.delete_warning), ).apply { @@ -250,7 +250,7 @@ class MediaFragment : actionMode?.finish() } } - }.show() + }.showDialog(childFragmentManager) } private fun startCopyService( @@ -275,9 +275,8 @@ class MediaFragment : } private fun actionDetail() { - DetailDialog(requireContext(), viewModel.getSelectedItem()).show( + DetailDialog(requireContext(), viewModel.getSelectedItem()).showDialog( childFragmentManager, - DetailDialog.TAG, ) } @@ -302,10 +301,7 @@ class MediaFragment : } else { viewModel.moveMedia(Paths.get(path)) } - }).show( - childFragmentManager, - DetailDialog.TAG, - ) + }).showDialog(childFragmentManager) } private fun showRenameDialog() { @@ -313,7 +309,7 @@ class MediaFragment : RenameFileDialog(file = media, onRename = { newName -> actionMode?.finish() viewModel.renameMedia(media, newName) - }).show(childFragmentManager, RenameFileDialog.TAG) + }).showDialog(childFragmentManager) } private fun clearSelection() { diff --git a/app/src/main/java/com/sn/snfilemanager/feature/pathpicker/presentation/PathPickerFragment.kt b/app/src/main/java/com/sn/snfilemanager/feature/pathpicker/presentation/PathPickerFragment.kt index 39f3643..d1897b9 100644 --- a/app/src/main/java/com/sn/snfilemanager/feature/pathpicker/presentation/PathPickerFragment.kt +++ b/app/src/main/java/com/sn/snfilemanager/feature/pathpicker/presentation/PathPickerFragment.kt @@ -1,14 +1,10 @@ package com.sn.snfilemanager.feature.pathpicker.presentation -import android.os.Bundle import android.view.KeyEvent -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup import androidx.constraintlayout.widget.ConstraintLayout -import androidx.fragment.app.DialogFragment import androidx.fragment.app.viewModels import com.sn.snfilemanager.R +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.core.extensions.gone import com.sn.snfilemanager.core.extensions.visible @@ -22,12 +18,15 @@ import dagger.hilt.android.AndroidEntryPoint import java.io.File @AndroidEntryPoint -class PathPickerFragment(private val pathCallback: ((String?) -> Unit)? = null) : DialogFragment() { +class PathPickerFragment(private val pathCallback: ((String?) -> Unit)? = null) : + BaseDialog() { private var adapter: DirectoryItemAdapter? = null private val viewModel: PathPickerViewModel by viewModels() - private val binding: FragmentPathPickerBinding by lazy { - FragmentPathPickerBinding.inflate(layoutInflater) - } + + override fun getViewBinding() = FragmentPathPickerBinding.inflate(layoutInflater) + + override val dialogTag: String + get() = "PATH_PICKER_DIALOG" override fun onStart() { super.onStart() @@ -37,25 +36,7 @@ class PathPickerFragment(private val pathCallback: ((String?) -> Unit)? = null) ) } - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setStyle(STYLE_NO_TITLE, R.style.DialogTheme_transparent) - dialog?.window?.setBackgroundDrawableResource(R.drawable.dialog_rounded) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - return binding.root - } - - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) + override fun setupViews() { initAdapter() handleBackPressed() initBreadListener() diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/ConfirmationDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/ConfirmationDialog.kt index 41090c1..8e070e3 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/ConfirmationDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/ConfirmationDialog.kt @@ -1,30 +1,23 @@ package com.sn.snfilemanager.view.dialog -import android.app.Dialog -import android.content.Context -import android.os.Bundle -import android.view.Gravity -import android.view.ViewGroup +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.databinding.DialogConfirmationBinding class ConfirmationDialog( - context: Context, private val title: String, private val question: String, -) : Dialog(context) { +) : BaseDialog() { var onSelected: ((Boolean) -> Unit)? = null - private val binding: DialogConfirmationBinding by lazy { - DialogConfirmationBinding.inflate(layoutInflater) - } + override val dialogTag: String + get() = "CONFIRMATION_DIALOG" + + override fun getViewBinding() = DialogConfirmationBinding.inflate(layoutInflater) - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(binding.root) - setCancelable(false) - setWindowProperty() + override var setCancelable: Boolean = false + override fun setupViews() { binding.tvTitle.text = title binding.tvQuestion.text = question @@ -37,11 +30,4 @@ class ConfirmationDialog( dismiss() } } - - private fun setWindowProperty() { - window?.apply { - setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - setGravity(Gravity.CENTER) - } - } } diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/ConflictDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/ConflictDialog.kt index 8e2bcdb..9d5e389 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/ConflictDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/ConflictDialog.kt @@ -1,47 +1,29 @@ package com.sn.snfilemanager.view.dialog -import android.app.Dialog -import android.content.Context -import android.os.Bundle -import android.view.Gravity -import android.view.ViewGroup +import android.content.DialogInterface import com.sn.mediastorepv.data.ConflictStrategy +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.databinding.DialogConflictBinding class ConflictDialog( - context: Context, private val fileName: String, -) : Dialog(context) { - private val binding: DialogConflictBinding by lazy { - DialogConflictBinding.inflate(layoutInflater) - } - +) : BaseDialog() { var onSelected: ((ConflictStrategy, Boolean) -> Unit)? = null var onDismiss: (() -> Unit)? = null - init { - setOnDismissListener { - onDismiss?.invoke() - } - } + override fun getViewBinding() = DialogConflictBinding.inflate(layoutInflater) - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(binding.root) - setCancelable(false) - setWindowProperty() - initView() - } + override var setCancelable: Boolean = false + override val dialogTag: String + get() = "CONFLICT_DIALOG" - private fun setWindowProperty() { - window?.apply { - setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - setGravity(Gravity.CENTER) - } + override fun onDismiss(dialog: DialogInterface) { + super.onDismiss(dialog) + onDismiss?.invoke() } - private fun initView() { + override fun setupViews() { with(binding) { tvFileName.text = fileName btnSkip.click { diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/CreateDirectoryDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/CreateDirectoryDialog.kt index 085e15a..b391bb2 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/CreateDirectoryDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/CreateDirectoryDialog.kt @@ -1,13 +1,8 @@ package com.sn.snfilemanager.view.dialog -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.widget.addTextChangedListener -import androidx.fragment.app.DialogFragment import com.sn.snfilemanager.R +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.databinding.DialogCreateDirectoryBinding import java.nio.file.Files @@ -17,36 +12,13 @@ import java.nio.file.Paths class CreateDirectoryDialog( private val path: String, private val onCreate: ((Path) -> Unit)? = null, -) : DialogFragment() { - private val binding: DialogCreateDirectoryBinding by lazy { - DialogCreateDirectoryBinding.inflate(layoutInflater) - } - - companion object { - const val TAG = "CREATE_DIRECTORY_DIALOG" - } +) : BaseDialog() { + override val dialogTag: String + get() = "CREATE_DIRECTORY_DIALOG" - override fun onStart() { - super.onStart() - dialog?.window?.setLayout( - ConstraintLayout.LayoutParams.MATCH_PARENT, - ConstraintLayout.LayoutParams.WRAP_CONTENT, - ) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - return binding.root - } + override fun getViewBinding() = DialogCreateDirectoryBinding.inflate(layoutInflater) - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) + override fun setupViews() { binding.etFolderName.requestFocus() binding.btnCancel.click { dismiss() } binding.btnCreate.click { diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/RenameFileDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/RenameFileDialog.kt index ab33a8d..1f071cb 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/RenameFileDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/RenameFileDialog.kt @@ -1,14 +1,10 @@ package com.sn.snfilemanager.view.dialog -import android.os.Bundle -import android.view.LayoutInflater import android.view.View -import android.view.ViewGroup -import androidx.constraintlayout.widget.ConstraintLayout import androidx.core.widget.addTextChangedListener -import androidx.fragment.app.DialogFragment import com.sn.mediastorepv.data.Media import com.sn.snfilemanager.R +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.core.extensions.gone import com.sn.snfilemanager.core.extensions.visible @@ -24,10 +20,11 @@ import kotlin.io.path.nameWithoutExtension class RenameFileDialog( private val file: T, private val onRename: ((String) -> Unit)? = null, -) : DialogFragment() { - private val binding: DialogRenameFileBinding by lazy { - DialogRenameFileBinding.inflate(layoutInflater) - } +) : BaseDialog() { + override fun getViewBinding() = DialogRenameFileBinding.inflate(layoutInflater) + + override val dialogTag: String + get() = "RENAME_FILE_DIALOG" val nameExtractor: (T) -> String = { item -> when (item) { @@ -37,32 +34,7 @@ class RenameFileDialog( } } - companion object { - const val TAG = "RENAME_FILE_DIALOG" - } - - override fun onStart() { - super.onStart() - dialog?.window?.setLayout( - ConstraintLayout.LayoutParams.MATCH_PARENT, - ConstraintLayout.LayoutParams.WRAP_CONTENT, - ) - } - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - return binding.root - } - - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) - + override fun setupViews() { binding.btnCancel.click { dismiss() } val path = Paths.get(nameExtractor(file)) diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/detail/DetailDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/detail/DetailDialog.kt index c756f06..a54af08 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/detail/DetailDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/detail/DetailDialog.kt @@ -1,12 +1,8 @@ package com.sn.snfilemanager.view.dialog.detail import android.content.Context -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.fragment.app.DialogFragment import androidx.fragment.app.viewModels +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.core.extensions.observe import com.sn.snfilemanager.databinding.DialogDetailBinding @@ -14,30 +10,16 @@ import com.sn.snfilemanager.databinding.DialogDetailBinding class DetailDialog( private val context: Context, private val itemList: MutableList, -) : DialogFragment() { - private var adapter: DetailItemAdapter? = null +) : BaseDialog() { private val viewModel: DetailDialogViewModel by viewModels() - private val binding: DialogDetailBinding by lazy { - DialogDetailBinding.inflate(layoutInflater) - } + private var adapter: DetailItemAdapter? = null - companion object { - const val TAG = "DETAIL_DIALOG" - } + override fun getViewBinding() = DialogDetailBinding.inflate(layoutInflater) - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - return binding.root - } + override val dialogTag: String + get() = "DETAIL_DIALOG" - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) + override fun setupViews() { binding.vm = viewModel binding.lifecycleOwner = viewLifecycleOwner isCancelable = true diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseAdapter.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseAdapter.kt index 319536b..fffa674 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseAdapter.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseAdapter.kt @@ -76,7 +76,7 @@ class LicenseAdapter(private val context: Context) : binding.mtvLicense.click { if (adapterPosition != RecyclerView.NO_POSITION) { val clickedLicense = licenses[adapterPosition] - context.openUrl(clickedLicense.url) + context.openUrl(clickedLicense.license) } } } diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseDialog.kt index 3cf9418..fdecf8a 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/license/LicenseDialog.kt @@ -1,51 +1,16 @@ package com.sn.snfilemanager.view.dialog.license -import android.os.Bundle -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.constraintlayout.widget.ConstraintLayout -import androidx.fragment.app.DialogFragment -import com.sn.snfilemanager.R +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click import com.sn.snfilemanager.databinding.DialogLicenseBinding -class LicenseDialog : DialogFragment() { - companion object { - const val TAG = "LICENSE_DIALOG" - } - - private val binding: DialogLicenseBinding by lazy { - DialogLicenseBinding.inflate(layoutInflater) - } - - override fun onStart() { - super.onStart() - dialog?.window?.setLayout( - ConstraintLayout.LayoutParams.MATCH_PARENT, - ConstraintLayout.LayoutParams.MATCH_PARENT, - ) - } - - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setStyle(STYLE_NO_TITLE, R.style.DialogTheme_transparent) - dialog?.window?.setBackgroundDrawableResource(R.drawable.dialog_rounded) - } +class LicenseDialog : BaseDialog() { + override fun getViewBinding() = DialogLicenseBinding.inflate(layoutInflater) - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle?, - ): View { - return binding.root - } + override val dialogTag: String + get() = "LICENSE_DIALOG" - override fun onViewCreated( - view: View, - savedInstanceState: Bundle?, - ) { - super.onViewCreated(view, savedInstanceState) + override fun setupViews() { binding.recycler.adapter = LicenseAdapter(requireContext()) binding.ivClose.click { dismiss() } } diff --git a/app/src/main/java/com/sn/snfilemanager/view/dialog/permission/PermissionDialog.kt b/app/src/main/java/com/sn/snfilemanager/view/dialog/permission/PermissionDialog.kt index 34c3fa6..8d6472b 100644 --- a/app/src/main/java/com/sn/snfilemanager/view/dialog/permission/PermissionDialog.kt +++ b/app/src/main/java/com/sn/snfilemanager/view/dialog/permission/PermissionDialog.kt @@ -1,33 +1,25 @@ package com.sn.snfilemanager.view.dialog.permission -import android.app.Dialog -import android.content.Context -import android.os.Bundle -import android.view.Gravity -import android.view.ViewGroup -import com.google.android.material.button.MaterialButton -import com.google.android.material.textview.MaterialTextView import com.sn.snfilemanager.R +import com.sn.snfilemanager.core.base.BaseDialog import com.sn.snfilemanager.core.extensions.click +import com.sn.snfilemanager.databinding.DialogPermissionBinding class PermissionDialog( - context: Context, private val type: PermissionDialogType, -) : Dialog(context) { +) : BaseDialog() { var onAllow: (() -> Unit)? = null - override fun onCreate(savedInstanceState: Bundle?) { - super.onCreate(savedInstanceState) - setContentView(R.layout.dialog_permission) + override fun getViewBinding() = DialogPermissionBinding.inflate(layoutInflater) - window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) - window?.setGravity(Gravity.CENTER) - - setCancelable(false) + override var setCancelable: Boolean = false + override val dialogTag: String + get() = "PERMISSION_DIALOG" + override fun setupViews() { val values = getValuesByType() - findViewById(R.id.tv_permission_info).text = values.first - findViewById(R.id.btn_allow).apply { + binding.tvPermissionInfo.text = values.first + binding.btnAllow.apply { text = values.second click { onAllow?.invoke() @@ -39,13 +31,13 @@ class PermissionDialog( private fun getValuesByType(): Pair = if (type == PermissionDialogType.DEFAULT) { Pair( - context.getString(R.string.permission_message), - context.getString(R.string.click_to_allow), + requireContext().getString(R.string.permission_message), + requireContext().getString(R.string.click_to_allow), ) } else { Pair( - context.getString(R.string.permission_warning_message), - context.getString(R.string.go_to_settings), + requireContext().getString(R.string.permission_warning_message), + requireContext().getString(R.string.go_to_settings), ) } } diff --git a/app/src/main/res/drawable/dialog_rounded.xml b/app/src/main/res/drawable/dialog_rounded.xml index 349d63f..3690831 100644 --- a/app/src/main/res/drawable/dialog_rounded.xml +++ b/app/src/main/res/drawable/dialog_rounded.xml @@ -1,8 +1,8 @@ + android:insetBottom="20dp"> diff --git a/app/src/main/res/layout/dialog_detail.xml b/app/src/main/res/layout/dialog_detail.xml index 3b05452..a277de0 100644 --- a/app/src/main/res/layout/dialog_detail.xml +++ b/app/src/main/res/layout/dialog_detail.xml @@ -48,8 +48,8 @@ + app:layout_constraintEnd_toEndOf="parent" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - + app:layout_constraintStart_toStartOf="@+id/container" + app:layout_constraintTop_toBottomOf="@+id/tv_permission_info" /> \ No newline at end of file