Fix: Fixed the appSelectionDialog from not closing right.

Signed-off-by: HeCodes2Much <wayne6324@gmail.com>
This commit is contained in:
HeCodes2Much
2024-07-09 17:09:41 +01:00
parent bb01d97add
commit 3efe24503c
2 changed files with 20 additions and 14 deletions

View File

@@ -339,15 +339,14 @@ class SettingsFragment : Fragment(),
launcherFontDialog?.show()
}
// Add this function to dismiss the dialog if it's showing
private fun dismissDialogs() {
launcherFontDialog?.dismiss()
searchEngineDialog?.dismiss()
}
private var appSelectionDialog: AlertDialog? = null
private fun showAppSelectionDialog(swipeType: Constants.Swipe) {
// Make sure this method is called within a lifecycle owner scope
lifecycleScope.launch(Dispatchers.Main) {
// Dismiss any existing dialog to prevent multiple dialogs open simultaneously
appSelectionDialog?.dismiss()
// Collect the flow of installed apps
appInfoRepository.getDrawApps().collect { installedApps ->
// Extract app names and package names
@@ -355,9 +354,9 @@ class SettingsFragment : Fragment(),
val packageNames = installedApps.map { it.packageName }
// Build and display the dialog
val builder = AlertDialog.Builder(binding.root.context)
builder.setTitle("Select an App")
builder.setItems(appNames) { _, which ->
val dialogBuilder = MaterialAlertDialogBuilder(context)
dialogBuilder.setTitle("Select an App")
dialogBuilder.setItems(appNames) { _, which ->
val selectedPackageName = packageNames[which]
when (swipeType) {
Constants.Swipe.DoubleTap,
@@ -368,11 +367,21 @@ class SettingsFragment : Fragment(),
}
}
builder.show()
// Assign the created dialog to launcherFontDialog
appSelectionDialog = dialogBuilder.create()
appSelectionDialog?.show()
}
}
}
// Add this function to dismiss the dialog if it's showing
private fun dismissDialogs() {
launcherFontDialog?.dismiss()
searchEngineDialog?.dismiss()
appSelectionDialog?.dismiss()
}
private fun handleSwipeAction(swipeType: Constants.Swipe, selectedPackageName: String) {
val selectedApp = context.getAppNameFromPackageName(selectedPackageName)