properly show the public contact source on all visible places

This commit is contained in:
tibbi 2018-02-02 13:57:24 +01:00
parent 996a9ead0a
commit b72c6cb787
3 changed files with 24 additions and 12 deletions

View File

@ -226,7 +226,7 @@ class EditContactActivity : SimpleActivity() {
contact_first_name.setText(contact!!.firstName)
contact_middle_name.setText(contact!!.middleName)
contact_surname.setText(contact!!.surname)
contact_source.text = contact!!.source
contact_source.text = getPublicContactSource(contact!!.source)
contact_toggle_favorite.apply {
beVisible()
@ -302,11 +302,12 @@ class EditContactActivity : SimpleActivity() {
private fun setupNewContact() {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE)
supportActionBar?.title = resources.getString(R.string.new_contact)
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), "", 0, 0, "")
contact_source.text = config.lastUsedContactSource
contact = Contact(0, "", "", "", "", ArrayList(), ArrayList(), ArrayList(), config.lastUsedContactSource, 0, 0, "")
contact_source.text = getPublicContactSource(contact!!.source)
contact_source.setOnClickListener {
showContactSourcePicker(contact_source.value) {
contact_source.text = it
showContactSourcePicker(contact!!.source) {
contact!!.source = it
contact_source.text = getPublicContactSource(it)
}
}
}
@ -515,7 +516,7 @@ class EditContactActivity : SimpleActivity() {
phoneNumbers = getFilledPhoneNumbers()
emails = getFilledEmails()
events = getFilledEvents()
source = contact_source.value
source = contact!!.source
starred = if (isContactStarred()) 1 else 0
Thread {

View File

@ -4,22 +4,26 @@ import android.support.v7.app.AlertDialog
import android.view.ViewGroup
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.contacts.R
import com.simplemobiletools.contacts.activities.SimpleActivity
import com.simplemobiletools.contacts.extensions.config
import com.simplemobiletools.contacts.extensions.getPublicContactSource
import com.simplemobiletools.contacts.extensions.showContactSourcePicker
import com.simplemobiletools.contacts.helpers.VcfImporter
import com.simplemobiletools.contacts.helpers.VcfImporter.ImportResult.IMPORT_FAIL
import kotlinx.android.synthetic.main.dialog_import_contacts.view.*
class ImportContactsDialog(val activity: SimpleActivity, val path: String, private val callback: (refreshView: Boolean) -> Unit) {
private var targetContactSource = ""
init {
val view = (activity.layoutInflater.inflate(R.layout.dialog_import_contacts, null) as ViewGroup).apply {
import_contacts_title.text = activity.config.lastUsedContactSource
targetContactSource = activity.config.lastUsedContactSource
import_contacts_title.text = activity.getPublicContactSource(targetContactSource)
import_contacts_title.setOnClickListener {
activity.showContactSourcePicker(import_contacts_title.value) {
import_contacts_title.text = it
activity.showContactSourcePicker(targetContactSource) {
targetContactSource = it
import_contacts_title.text = activity.getPublicContactSource(it)
}
}
}
@ -32,7 +36,7 @@ class ImportContactsDialog(val activity: SimpleActivity, val path: String, priva
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
activity.toast(R.string.importing)
Thread {
val result = VcfImporter(activity).importContacts(path, view.import_contacts_title.value)
val result = VcfImporter(activity).importContacts(path, targetContactSource)
handleParseResult(result)
dismiss()
}.start()

View File

@ -54,7 +54,12 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
val sources = it.map { it.name }
var currentSourceIndex = -1
sources.forEachIndexed { index, account ->
items.add(RadioItem(index, account))
var publicAccount = account
if (account == config.localAccountName) {
publicAccount = getString(com.simplemobiletools.contacts.R.string.phone_storage)
}
items.add(RadioItem(index, publicAccount))
if (account == currentSource) {
currentSourceIndex = index
}
@ -68,6 +73,8 @@ fun SimpleActivity.showContactSourcePicker(currentSource: String, callback: (new
}
}
fun SimpleActivity.getPublicContactSource(source: String) = if (source == config.localAccountName) getString(com.simplemobiletools.contacts.R.string.phone_storage) else source
fun BaseSimpleActivity.shareContacts(contacts: ArrayList<Contact>) {
val file = getTempFile()
if (file == null) {