allow selecting under which account should the contact group be created
This commit is contained in:
parent
d673a0124b
commit
ac058c4e7b
|
@ -3,12 +3,16 @@ package com.simplemobiletools.contacts.dialogs
|
|||
import android.support.v7.app.AlertDialog
|
||||
import android.view.View
|
||||
import com.simplemobiletools.commons.activities.BaseSimpleActivity
|
||||
import com.simplemobiletools.commons.dialogs.RadioGroupDialog
|
||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||
import com.simplemobiletools.commons.extensions.showKeyboard
|
||||
import com.simplemobiletools.commons.extensions.toast
|
||||
import com.simplemobiletools.commons.extensions.value
|
||||
import com.simplemobiletools.commons.models.RadioItem
|
||||
import com.simplemobiletools.contacts.R
|
||||
import com.simplemobiletools.contacts.extensions.config
|
||||
import com.simplemobiletools.contacts.helpers.ContactsHelper
|
||||
import com.simplemobiletools.contacts.models.ContactSource
|
||||
import com.simplemobiletools.contacts.models.Group
|
||||
import kotlinx.android.synthetic.main.dialog_create_new_group.view.*
|
||||
|
||||
|
@ -29,11 +33,30 @@ class CreateNewGroupDialog(val activity: BaseSimpleActivity, val callback: (newG
|
|||
return@OnClickListener
|
||||
}
|
||||
|
||||
val newGroup = ContactsHelper(activity).createNewGroup(name)
|
||||
if (newGroup != null) {
|
||||
callback(newGroup)
|
||||
val contactSources = ArrayList<ContactSource>()
|
||||
if (activity.config.localAccountName.isNotEmpty()) {
|
||||
contactSources.add(ContactSource(activity.config.localAccountName, activity.config.localAccountType))
|
||||
}
|
||||
|
||||
ContactsHelper(activity).getContactSources {
|
||||
it.filter { it.type.contains("google", true) }.mapTo(contactSources, { ContactSource(it.name, it.type) })
|
||||
|
||||
val items = ArrayList<RadioItem>()
|
||||
contactSources.forEachIndexed { index, contactSource ->
|
||||
items.add(RadioItem(index, contactSource.name))
|
||||
}
|
||||
|
||||
activity.runOnUiThread {
|
||||
RadioGroupDialog(activity, items, titleId = R.string.create_group_under_account) {
|
||||
val contactSource = contactSources[it as Int]
|
||||
val newGroup = ContactsHelper(activity).createNewGroup(name, contactSource.name, contactSource.type)
|
||||
if (newGroup != null) {
|
||||
callback(newGroup)
|
||||
}
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
dismiss()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,11 +393,13 @@ class ContactsHelper(val activity: BaseSimpleActivity) {
|
|||
return groups
|
||||
}
|
||||
|
||||
fun createNewGroup(title: String): Group? {
|
||||
fun createNewGroup(title: String, accountName: String, accountType: String): Group? {
|
||||
val operations = ArrayList<ContentProviderOperation>()
|
||||
ContentProviderOperation.newInsert(ContactsContract.Groups.CONTENT_URI).apply {
|
||||
withValue(ContactsContract.Groups.TITLE, title)
|
||||
withValue(ContactsContract.Groups.GROUP_VISIBLE, 1)
|
||||
withValue(ContactsContract.Groups.ACCOUNT_NAME, accountName)
|
||||
withValue(ContactsContract.Groups.ACCOUNT_TYPE, accountType)
|
||||
operations.add(build())
|
||||
}
|
||||
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Foto machen</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Prendre une photo</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">사진 촬영</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Nufotografuoti</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Tirar foto</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Снять фото</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">Nemáte v zariadení vytvorené žiadne skupiny kontaktov</string>
|
||||
<string name="create_group">Vytvoriť skupinu</string>
|
||||
<string name="add_to_group">Pridať do skupiny</string>
|
||||
<string name="create_group_under_account">Vytvoriť skupinu pod účet</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Vytvoriť foto</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Ta foto</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">裝置內沒有聯絡人群組</string>
|
||||
<string name="create_group">建立群組</string>
|
||||
<string name="add_to_group">添加到群組</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">拍照</string>
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
<string name="no_group_created">There are no contact groups on the device</string>
|
||||
<string name="create_group">Create group</string>
|
||||
<string name="add_to_group">Add to group</string>
|
||||
<string name="create_group_under_account">Create group under account</string>
|
||||
|
||||
<!-- Photo -->
|
||||
<string name="take_photo">Take photo</string>
|
||||
|
|
Loading…
Reference in New Issue