diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CreateNewGroupDialog.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CreateNewGroupDialog.kt index 5897b671..8ab8b4d8 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CreateNewGroupDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/dialogs/CreateNewGroupDialog.kt @@ -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() + 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() + 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() }) } } diff --git a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt index e41fabdb..56bbd854 100644 --- a/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt +++ b/app/src/main/kotlin/com/simplemobiletools/contacts/helpers/ContactsHelper.kt @@ -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.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()) } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index cd8d7bdb..4de49973 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Foto machen diff --git a/app/src/main/res/values-fr/strings.xml b/app/src/main/res/values-fr/strings.xml index bdba1f9a..9125e26f 100644 --- a/app/src/main/res/values-fr/strings.xml +++ b/app/src/main/res/values-fr/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Prendre une photo diff --git a/app/src/main/res/values-ko-rKR/strings.xml b/app/src/main/res/values-ko-rKR/strings.xml index e71dafc0..c2e550a2 100644 --- a/app/src/main/res/values-ko-rKR/strings.xml +++ b/app/src/main/res/values-ko-rKR/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account 사진 촬영 diff --git a/app/src/main/res/values-lt/strings.xml b/app/src/main/res/values-lt/strings.xml index 25806d34..eb3d883a 100644 --- a/app/src/main/res/values-lt/strings.xml +++ b/app/src/main/res/values-lt/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Nufotografuoti diff --git a/app/src/main/res/values-pt/strings.xml b/app/src/main/res/values-pt/strings.xml index bf7016d6..0b4685c1 100644 --- a/app/src/main/res/values-pt/strings.xml +++ b/app/src/main/res/values-pt/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Tirar foto diff --git a/app/src/main/res/values-ru/strings.xml b/app/src/main/res/values-ru/strings.xml index 66b189b9..0ccfc198 100644 --- a/app/src/main/res/values-ru/strings.xml +++ b/app/src/main/res/values-ru/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Снять фото diff --git a/app/src/main/res/values-sk/strings.xml b/app/src/main/res/values-sk/strings.xml index 85177e12..7b218e5a 100644 --- a/app/src/main/res/values-sk/strings.xml +++ b/app/src/main/res/values-sk/strings.xml @@ -24,6 +24,7 @@ Nemáte v zariadení vytvorené žiadne skupiny kontaktov Vytvoriť skupinu Pridať do skupiny + Vytvoriť skupinu pod účet Vytvoriť foto diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 74b3aadf..cbf54e3c 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Ta foto diff --git a/app/src/main/res/values-zh-rTW/strings.xml b/app/src/main/res/values-zh-rTW/strings.xml index c05a2c9e..58f3265d 100644 --- a/app/src/main/res/values-zh-rTW/strings.xml +++ b/app/src/main/res/values-zh-rTW/strings.xml @@ -24,6 +24,7 @@ 裝置內沒有聯絡人群組 建立群組 添加到群組 + Create group under account 拍照 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8d9edd77..24167197 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -24,6 +24,7 @@ There are no contact groups on the device Create group Add to group + Create group under account Take photo