improve the dialog with contact source filtering

This commit is contained in:
tibbi 2017-12-26 22:03:25 +01:00
parent eee3a19e96
commit 60daf446bb

View File

@ -10,16 +10,14 @@ import com.simplemobiletools.contacts.helpers.ContactsHelper
import kotlinx.android.synthetic.main.dialog_filter_contact_sources.view.* import kotlinx.android.synthetic.main.dialog_filter_contact_sources.view.*
class FilterContactSourcesDialog(val activity: SimpleActivity, val callback: () -> Unit) { class FilterContactSourcesDialog(val activity: SimpleActivity, val callback: () -> Unit) {
var dialog: AlertDialog private var dialog: AlertDialog? = null
val view = activity.layoutInflater.inflate(R.layout.dialog_filter_contact_sources, null) private val view = activity.layoutInflater.inflate(R.layout.dialog_filter_contact_sources, null)
init { init {
ContactsHelper(activity).getContactSources { ContactsHelper(activity).getContactSources {
val selectedSources = activity.config.displayContactSources val selectedSources = activity.config.displayContactSources
activity.runOnUiThread { activity.runOnUiThread {
view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources) view.filter_contact_sources_list.adapter = FilterContactSourcesAdapter(activity, it, selectedSources)
}
}
dialog = AlertDialog.Builder(activity) dialog = AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() }) .setPositiveButton(R.string.ok, { dialogInterface, i -> confirmEventTypes() })
@ -28,6 +26,8 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, val callback: ()
activity.setupDialogStuff(view, this) activity.setupDialogStuff(view, this)
} }
} }
}
}
private fun confirmEventTypes() { private fun confirmEventTypes() {
val selectedItems = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet() val selectedItems = (view.filter_contact_sources_list.adapter as FilterContactSourcesAdapter).getSelectedItemsSet()
@ -35,6 +35,6 @@ class FilterContactSourcesDialog(val activity: SimpleActivity, val callback: ()
activity.config.displayContactSources = selectedItems activity.config.displayContactSources = selectedItems
callback() callback()
} }
dialog.dismiss() dialog?.dismiss()
} }
} }