properly handle IM fields at the edit screen
This commit is contained in:
parent
c416a46214
commit
fbd58b4bb9
|
@ -30,6 +30,7 @@ import kotlinx.android.synthetic.main.activity_edit_contact.*
|
||||||
import kotlinx.android.synthetic.main.item_edit_address.view.*
|
import kotlinx.android.synthetic.main.item_edit_address.view.*
|
||||||
import kotlinx.android.synthetic.main.item_edit_email.view.*
|
import kotlinx.android.synthetic.main.item_edit_email.view.*
|
||||||
import kotlinx.android.synthetic.main.item_edit_group.view.*
|
import kotlinx.android.synthetic.main.item_edit_group.view.*
|
||||||
|
import kotlinx.android.synthetic.main.item_edit_im.view.*
|
||||||
import kotlinx.android.synthetic.main.item_edit_phone_number.view.*
|
import kotlinx.android.synthetic.main.item_edit_phone_number.view.*
|
||||||
import kotlinx.android.synthetic.main.item_edit_website.view.*
|
import kotlinx.android.synthetic.main.item_edit_website.view.*
|
||||||
import kotlinx.android.synthetic.main.item_event.view.*
|
import kotlinx.android.synthetic.main.item_event.view.*
|
||||||
|
@ -407,7 +408,18 @@ class EditContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupIMs() {
|
private fun setupIMs() {
|
||||||
|
contact!!.IMs.forEachIndexed { index, IM ->
|
||||||
|
var imHolder = contact_ims_holder.getChildAt(index)
|
||||||
|
if (imHolder == null) {
|
||||||
|
imHolder = layoutInflater.inflate(R.layout.item_edit_im, contact_ims_holder, false)
|
||||||
|
contact_ims_holder.addView(imHolder)
|
||||||
|
}
|
||||||
|
|
||||||
|
imHolder!!.apply {
|
||||||
|
contact_im.setText(IM.value)
|
||||||
|
setupIMTypePicker(contact_im_type, IM.type, IM.label)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupNotes() {
|
private fun setupNotes() {
|
||||||
|
@ -546,6 +558,13 @@ class EditContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contact!!.IMs.isEmpty()) {
|
||||||
|
val IMHolder = contact_ims_holder.getChildAt(0)
|
||||||
|
(IMHolder as? ViewGroup)?.contact_im_type?.apply {
|
||||||
|
setupIMTypePicker(this, DEFAULT_IM_TYPE, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (contact!!.events.isEmpty()) {
|
if (contact!!.events.isEmpty()) {
|
||||||
val eventHolder = contact_events_holder.getChildAt(0)
|
val eventHolder = contact_events_holder.getChildAt(0)
|
||||||
(eventHolder as? ViewGroup)?.apply {
|
(eventHolder as? ViewGroup)?.apply {
|
||||||
|
@ -588,6 +607,15 @@ class EditContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setupIMTypePicker(imTypeField: TextView, type: Int, label: String) {
|
||||||
|
imTypeField.apply {
|
||||||
|
text = getIMTypeText(type, label)
|
||||||
|
setOnClickListener {
|
||||||
|
showIMTypePicker(it as TextView)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupEventTypePicker(eventHolder: ViewGroup, type: Int = DEFAULT_EVENT_TYPE) {
|
private fun setupEventTypePicker(eventHolder: ViewGroup, type: Int = DEFAULT_EVENT_TYPE) {
|
||||||
eventHolder.contact_event_type.apply {
|
eventHolder.contact_event_type.apply {
|
||||||
setText(getEventTextId(type))
|
setText(getEventTextId(type))
|
||||||
|
@ -712,6 +740,31 @@ class EditContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun showIMTypePicker(imTypeField: TextView) {
|
||||||
|
val items = arrayListOf(
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_AIM, getString(R.string.aim)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_MSN, getString(R.string.windows_live)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_YAHOO, getString(R.string.yahoo)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_SKYPE, getString(R.string.skype)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_QQ, getString(R.string.qq)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK, getString(R.string.hangouts)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_ICQ, getString(R.string.icq)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_JABBER, getString(R.string.jabber)),
|
||||||
|
RadioItem(CommonDataKinds.Im.PROTOCOL_CUSTOM, getString(R.string.custom))
|
||||||
|
)
|
||||||
|
|
||||||
|
val currentIMTypeId = getIMTypeId(imTypeField.value)
|
||||||
|
RadioGroupDialog(this, items, currentIMTypeId) {
|
||||||
|
if (it as Int == CommonDataKinds.Im.PROTOCOL_CUSTOM) {
|
||||||
|
CustomLabelDialog(this) {
|
||||||
|
imTypeField.text = it
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
imTypeField.text = getIMTypeText(it, "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun showEventTypePicker(eventTypeField: TextView) {
|
private fun showEventTypePicker(eventTypeField: TextView) {
|
||||||
val items = arrayListOf(
|
val items = arrayListOf(
|
||||||
RadioItem(CommonDataKinds.Event.TYPE_BIRTHDAY, getString(R.string.birthday)),
|
RadioItem(CommonDataKinds.Event.TYPE_BIRTHDAY, getString(R.string.birthday)),
|
||||||
|
@ -757,6 +810,7 @@ class EditContactActivity : ContactActivity() {
|
||||||
phoneNumbers = getFilledPhoneNumbers()
|
phoneNumbers = getFilledPhoneNumbers()
|
||||||
emails = getFilledEmails()
|
emails = getFilledEmails()
|
||||||
addresses = getFilledAddresses()
|
addresses = getFilledAddresses()
|
||||||
|
IMs = getFilledIMs()
|
||||||
events = getFilledEvents()
|
events = getFilledEvents()
|
||||||
starred = if (isContactStarred()) 1 else 0
|
starred = if (isContactStarred()) 1 else 0
|
||||||
notes = contact_notes.value
|
notes = contact_notes.value
|
||||||
|
@ -828,8 +882,20 @@ class EditContactActivity : ContactActivity() {
|
||||||
return addresses
|
return addresses
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFilledIMs() {
|
private fun getFilledIMs(): ArrayList<IM> {
|
||||||
|
val IMs = ArrayList<IM>()
|
||||||
|
val IMsCount = contact_ims_holder.childCount
|
||||||
|
for (i in 0 until IMsCount) {
|
||||||
|
val IMsHolder = contact_ims_holder.getChildAt(i)
|
||||||
|
val IM = IMsHolder.contact_im.value
|
||||||
|
val IMType = getIMTypeId(IMsHolder.contact_im_type.value)
|
||||||
|
val IMLabel = if (IMType == CommonDataKinds.Im.PROTOCOL_CUSTOM) IMsHolder.contact_im_type.value else ""
|
||||||
|
|
||||||
|
if (IM.isNotEmpty()) {
|
||||||
|
IMs.add(IM(IM, IMType, IMLabel))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return IMs
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getFilledEvents(): ArrayList<Event> {
|
private fun getFilledEvents(): ArrayList<Event> {
|
||||||
|
@ -933,7 +999,14 @@ class EditContactActivity : ContactActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewIMField() {
|
private fun addNewIMField() {
|
||||||
|
val IMHolder = layoutInflater.inflate(R.layout.item_edit_im, contact_ims_holder, false) as ViewGroup
|
||||||
|
updateTextColors(IMHolder)
|
||||||
|
setupIMTypePicker(IMHolder.contact_im_type, DEFAULT_IM_TYPE, "")
|
||||||
|
contact_ims_holder.addView(IMHolder)
|
||||||
|
contact_ims_holder.onGlobalLayout {
|
||||||
|
IMHolder.contact_im.requestFocus()
|
||||||
|
showKeyboard(IMHolder.contact_im)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addNewEventField() {
|
private fun addNewEventField() {
|
||||||
|
@ -1097,4 +1170,16 @@ class EditContactActivity : ContactActivity() {
|
||||||
getString(R.string.other) -> CommonDataKinds.StructuredPostal.TYPE_OTHER
|
getString(R.string.other) -> CommonDataKinds.StructuredPostal.TYPE_OTHER
|
||||||
else -> CommonDataKinds.StructuredPostal.TYPE_CUSTOM
|
else -> CommonDataKinds.StructuredPostal.TYPE_CUSTOM
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun getIMTypeId(value: String) = when (value) {
|
||||||
|
getString(R.string.aim) -> CommonDataKinds.Im.PROTOCOL_AIM
|
||||||
|
getString(R.string.windows_live) -> CommonDataKinds.Im.PROTOCOL_MSN
|
||||||
|
getString(R.string.yahoo) -> CommonDataKinds.Im.PROTOCOL_YAHOO
|
||||||
|
getString(R.string.skype) -> CommonDataKinds.Im.PROTOCOL_SKYPE
|
||||||
|
getString(R.string.qq) -> CommonDataKinds.Im.PROTOCOL_QQ
|
||||||
|
getString(R.string.hangouts) -> CommonDataKinds.Im.PROTOCOL_GOOGLE_TALK
|
||||||
|
getString(R.string.icq) -> CommonDataKinds.Im.PROTOCOL_ICQ
|
||||||
|
getString(R.string.jabber) -> CommonDataKinds.Im.PROTOCOL_JABBER
|
||||||
|
else -> CommonDataKinds.Im.PROTOCOL_CUSTOM
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,7 @@ const val DEFAULT_ADDRESS_TYPE = CommonDataKinds.StructuredPostal.TYPE_HOME
|
||||||
const val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
const val DEFAULT_EVENT_TYPE = CommonDataKinds.Event.TYPE_BIRTHDAY
|
||||||
const val DEFAULT_ORGANIZATION_TYPE = CommonDataKinds.Organization.TYPE_WORK
|
const val DEFAULT_ORGANIZATION_TYPE = CommonDataKinds.Organization.TYPE_WORK
|
||||||
const val DEFAULT_WEBSITE_TYPE = CommonDataKinds.Website.TYPE_HOMEPAGE
|
const val DEFAULT_WEBSITE_TYPE = CommonDataKinds.Website.TYPE_HOMEPAGE
|
||||||
|
const val DEFAULT_IM_TYPE = CommonDataKinds.Im.PROTOCOL_SKYPE
|
||||||
|
|
||||||
// some manufacturer contact account types from https://stackoverflow.com/a/44802016/1967672
|
// some manufacturer contact account types from https://stackoverflow.com/a/44802016/1967672
|
||||||
val localAccountTypes = arrayListOf("vnd.sec.contact.phone",
|
val localAccountTypes = arrayListOf("vnd.sec.contact.phone",
|
||||||
|
|
Loading…
Reference in New Issue