Skip to content

Commit

Permalink
Merge pull request #50 from emreesen27/external-sup
Browse files Browse the repository at this point in the history
[DEV][Dialog UI Imp]
  • Loading branch information
emreesen27 authored Apr 20, 2024
2 parents 81debd8 + 25c030b commit 396c064
Show file tree
Hide file tree
Showing 17 changed files with 167 additions and 285 deletions.
59 changes: 59 additions & 0 deletions app/src/main/java/com/sn/snfilemanager/core/base/BaseDialog.kt
Original file line number Diff line number Diff line change
@@ -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<VBinding : ViewBinding> : 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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@ class AboutFragment : BaseFragment<FragmentAboutBinding, AboutViewModel>() {
}

private fun showLicensesDialog() {
LicenseDialog().show(childFragmentManager, LicenseDialog.TAG)
LicenseDialog().showDialog(childFragmentManager)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
Expand Down Expand Up @@ -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() {
Expand All @@ -412,7 +409,6 @@ class FilesListFragment :

private fun actionDelete() {
ConfirmationDialog(
requireContext(),
getString(R.string.are_you_sure),
getString(R.string.delete_warning),
).apply {
Expand All @@ -423,7 +419,7 @@ class FilesListFragment :
actionMode?.finish()
}
}
}.show()
}.showDialog(childFragmentManager)
}

private fun startCopyService(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,20 +161,19 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>() {
}

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 {
Expand All @@ -184,7 +183,7 @@ class HomeFragment : BaseFragment<FragmentHomeBinding, HomeViewModel>() {
}
}
}
confirmationDialog?.show()
confirmationDialog?.showDialog(childFragmentManager)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class MediaFragment :
data?.filterIsInstance<Media>()?.let { adapter?.removeItems(it) }
}
}

JobType.CREATE -> {}
JobType.RENAME -> {}
}
Expand All @@ -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 ->
Expand Down Expand Up @@ -239,7 +240,6 @@ class MediaFragment :

private fun actionDelete() {
ConfirmationDialog(
requireContext(),
getString(R.string.are_you_sure),
getString(R.string.delete_warning),
).apply {
Expand All @@ -250,7 +250,7 @@ class MediaFragment :
actionMode?.finish()
}
}
}.show()
}.showDialog(childFragmentManager)
}

private fun startCopyService(
Expand All @@ -275,9 +275,8 @@ class MediaFragment :
}

private fun actionDetail() {
DetailDialog(requireContext(), viewModel.getSelectedItem()).show(
DetailDialog(requireContext(), viewModel.getSelectedItem()).showDialog(
childFragmentManager,
DetailDialog.TAG,
)
}

Expand All @@ -302,18 +301,15 @@ class MediaFragment :
} else {
viewModel.moveMedia(Paths.get(path))
}
}).show(
childFragmentManager,
DetailDialog.TAG,
)
}).showDialog(childFragmentManager)
}

private fun showRenameDialog() {
val media = viewModel.getSelectedItem().first()
RenameFileDialog(file = media, onRename = { newName ->
actionMode?.finish()
viewModel.renameMedia(media, newName)
}).show(childFragmentManager, RenameFileDialog.TAG)
}).showDialog(childFragmentManager)
}

private fun clearSelection() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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<FragmentPathPickerBinding>() {
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()
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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<DialogConfirmationBinding>() {
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

Expand All @@ -37,11 +30,4 @@ class ConfirmationDialog(
dismiss()
}
}

private fun setWindowProperty() {
window?.apply {
setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
setGravity(Gravity.CENTER)
}
}
}
Loading

0 comments on commit 396c064

Please sign in to comment.