diff options
author | Ricki Hirner <hirner@bitfire.at> | 2022-03-07 18:56:10 +0300 |
---|---|---|
committer | Ricki Hirner <hirner@bitfire.at> | 2022-03-07 18:56:10 +0300 |
commit | d18a0bddc0cbfbb05910eebe8a3262eb52ef9067 (patch) | |
tree | a966cb9393a6fefc289597f815f2985f47f12834 | |
parent | 98188b5e89a3b7a03ada6cd4f56b4574d41bee9f (diff) |
[WIP] IM: Improve label/type handling
-rw-r--r-- | src/main/java/at/bitfire/vcard4android/contactrow/ImBuilder.kt | 25 | ||||
-rw-r--r-- | src/main/java/at/bitfire/vcard4android/contactrow/ImHandler.kt | 41 |
2 files changed, 30 insertions, 36 deletions
diff --git a/src/main/java/at/bitfire/vcard4android/contactrow/ImBuilder.kt b/src/main/java/at/bitfire/vcard4android/contactrow/ImBuilder.kt index c3f4b08..266b9ea 100644 --- a/src/main/java/at/bitfire/vcard4android/contactrow/ImBuilder.kt +++ b/src/main/java/at/bitfire/vcard4android/contactrow/ImBuilder.kt @@ -27,20 +27,14 @@ class ImBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact) continue } - var typeCode: Int = Im.TYPE_OTHER - var typeLabel: String? = null - if (labeledIm.label != null) { - typeCode = Im.TYPE_CUSTOM - typeLabel = labeledIm.label - } else { - for (type in impp.types) - when (type) { - ImppType.HOME, - ImppType.PERSONAL -> typeCode = Im.TYPE_HOME - ImppType.WORK, - ImppType.BUSINESS -> typeCode = Im.TYPE_WORK - } - } + var typeCode = Im.TYPE_OTHER + for (type in impp.types) + when (type) { + ImppType.HOME, + ImppType.PERSONAL -> typeCode = Im.TYPE_HOME + ImppType.WORK, + ImppType.BUSINESS -> typeCode = Im.TYPE_WORK + } var protocolCode: Int var protocolLabel: String? = null @@ -58,7 +52,7 @@ class ImBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact) protocol.equals("sip", true) -> continue // IMPP:sip:… is handled by SipAddressBuilder else -> { protocolCode = Im.PROTOCOL_CUSTOM - protocolLabel = protocol + protocolLabel = labeledIm.label ?: protocol } } @@ -66,7 +60,6 @@ class ImBuilder(dataRowUri: Uri, rawContactId: Long?, contact: Contact) result += newDataRow() .withValue(Im.DATA, impp.handle) .withValue(Im.TYPE, typeCode) - .withValue(Im.LABEL, typeLabel) .withValue(Im.PROTOCOL, protocolCode) .withValue(Im.CUSTOM_PROTOCOL, protocolLabel) } diff --git a/src/main/java/at/bitfire/vcard4android/contactrow/ImHandler.kt b/src/main/java/at/bitfire/vcard4android/contactrow/ImHandler.kt index 9ecbdd7..8d4fdea 100644 --- a/src/main/java/at/bitfire/vcard4android/contactrow/ImHandler.kt +++ b/src/main/java/at/bitfire/vcard4android/contactrow/ImHandler.kt @@ -11,6 +11,7 @@ import at.bitfire.vcard4android.Contact import at.bitfire.vcard4android.LabeledProperty import ezvcard.parameter.ImppType import ezvcard.property.Impp +import java.util.logging.Level object ImHandler: DataRowHandler() { @@ -26,47 +27,47 @@ object ImHandler: DataRowHandler() { return } - var impp: Impp? = null - when (values.getAsInteger(Im.PROTOCOL)) { + val labeledImpp = when (values.getAsInteger(Im.PROTOCOL)) { Im.PROTOCOL_AIM -> - impp = Impp.aim(handle) + LabeledProperty(Impp.aim(handle)) Im.PROTOCOL_MSN -> - impp = Impp.msn(handle) + LabeledProperty(Impp.msn(handle)) Im.PROTOCOL_YAHOO -> - impp = Impp.yahoo(handle) + LabeledProperty(Impp.yahoo(handle)) Im.PROTOCOL_SKYPE -> - impp = Impp.skype(handle) + LabeledProperty(Impp.skype(handle)) Im.PROTOCOL_QQ -> - impp = Impp("qq", handle) + LabeledProperty(Impp("qq", handle)) Im.PROTOCOL_GOOGLE_TALK -> - impp = Impp("google-talk", handle) + LabeledProperty(Impp("google-talk", handle)) Im.PROTOCOL_ICQ -> - impp = Impp.icq(handle) + LabeledProperty(Impp.icq(handle)) Im.PROTOCOL_JABBER -> - impp = Impp.xmpp(handle) + LabeledProperty(Impp.xmpp(handle)) Im.PROTOCOL_NETMEETING -> - impp = Impp("netmeeting", handle) + LabeledProperty(Impp("netmeeting", handle)) Im.PROTOCOL_CUSTOM -> try { - impp = Impp(protocolToUriScheme(values.getAsString(Im.CUSTOM_PROTOCOL)), handle) + LabeledProperty( + Impp(protocolToUriScheme(values.getAsString(Im.CUSTOM_PROTOCOL)), handle), + values.getAsString(Im.CUSTOM_PROTOCOL) + ) } catch(e: IllegalArgumentException) { Constants.log.warning("Messenger type/value can't be expressed as URI; ignoring") + return } + else -> { + Constants.log.log(Level.WARNING, "Unknown IM type", values) + return + } } - - if (impp == null) - return - val labeledImpp = LabeledProperty(impp) + val impp = labeledImpp.property when (values.getAsInteger(Im.TYPE)) { Im.TYPE_HOME -> impp.types += ImppType.HOME Im.TYPE_WORK -> impp.types += ImppType.WORK - Im.TYPE_CUSTOM -> - values.getAsString(Im.LABEL)?.let { - labeledImpp.label = it - } } contact.impps += labeledImpp |