Dialog bug fixed

This commit is contained in:
merkost 2023-07-15 14:00:47 +10:00
parent 13a66d9c8d
commit 6d67aa4ae7
1 changed files with 4 additions and 20 deletions

View File

@ -12,7 +12,6 @@ import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.commons.helpers.ContactsHelper import com.simplemobiletools.commons.helpers.ContactsHelper
import com.simplemobiletools.commons.helpers.ensureBackgroundThread import com.simplemobiletools.commons.helpers.ensureBackgroundThread
import com.simplemobiletools.commons.models.contacts.ContactSource
import com.simplemobiletools.contacts.pro.R import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.activities.SimpleActivity import com.simplemobiletools.contacts.pro.activities.SimpleActivity
import com.simplemobiletools.contacts.pro.extensions.config import com.simplemobiletools.contacts.pro.extensions.config
@ -26,21 +25,9 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup) private val view = (activity.layoutInflater.inflate(R.layout.dialog_manage_automatic_backups, null) as ViewGroup)
private val config = activity.config private val config = activity.config
private var backupFolder = config.autoBackupFolder private var backupFolder = config.autoBackupFolder
private var selectedContactTypes = HashSet<ContactSource>() private var selectedContactSources = config.autoBackupContactSources
private fun setContactTypes() {
ContactsHelper(activity).getContactSources { contactSources ->
val availableContactSources = contactSources.toSet()
if (config.autoBackupContactSources.isEmpty()) {
selectedContactTypes = contactSources.toHashSet()
} else {
selectedContactTypes = availableContactSources.filter { it.name in config.autoBackupContactSources }.toHashSet()
}
}
}
init { init {
setContactTypes()
view.apply { view.apply {
backup_events_folder.setText(activity.humanizePath(backupFolder)) backup_events_folder.setText(activity.humanizePath(backupFolder))
val filename = config.autoBackupFilename.ifEmpty { val filename = config.autoBackupFilename.ifEmpty {
@ -63,8 +50,8 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
manage_event_types_holder.setOnClickListener { manage_event_types_holder.setOnClickListener {
activity.runOnUiThread { activity.runOnUiThread {
SelectContactTypesDialog(activity, selectedContactTypes.map { it.name }) { SelectContactTypesDialog(activity, selectedContactSources.toList()) {
selectedContactTypes = it selectedContactSources = it.map { it.name }.toSet()
config.autoBackupContactSources = it.map { it.name }.toSet() config.autoBackupContactSources = it.map { it.name }.toSet()
} }
} }
@ -86,7 +73,7 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
return@setOnClickListener return@setOnClickListener
} }
if (selectedContactTypes.isEmpty()) { if (selectedContactSources.isEmpty()) {
activity.toast(R.string.no_entries_for_exporting) activity.toast(R.string.no_entries_for_exporting)
return@setOnClickListener return@setOnClickListener
} }
@ -95,9 +82,6 @@ class ManageAutoBackupsDialog(private val activity: SimpleActivity, onSuccess: (
config.apply { config.apply {
autoBackupFolder = backupFolder autoBackupFolder = backupFolder
autoBackupFilename = filename autoBackupFilename = filename
if (autoBackupContactSources != selectedContactTypes) {
autoBackupContactSources = selectedContactTypes.map { it.type }.toSet()
}
} }
activity.runOnUiThread { activity.runOnUiThread {