Add vCard attachment preview
This commit is contained in:
parent
d874e16024
commit
f07abeb54c
58 changed files with 1263 additions and 117 deletions
|
|
@ -0,0 +1,54 @@
|
|||
package com.simplemobiletools.smsmessenger.models
|
||||
|
||||
import android.content.Context
|
||||
import com.simplemobiletools.commons.extensions.normalizePhoneNumber
|
||||
import com.simplemobiletools.smsmessenger.R
|
||||
import com.simplemobiletools.smsmessenger.extensions.config
|
||||
import com.simplemobiletools.smsmessenger.extensions.format
|
||||
import ezvcard.VCard
|
||||
import ezvcard.property.*
|
||||
|
||||
private val displayedPropertyClasses = arrayOf(
|
||||
Telephone::class.java, Email::class.java, Organization::class.java, Birthday::class.java, Anniversary::class.java, Note::class.java
|
||||
)
|
||||
|
||||
data class VCardWrapper(val vCard: VCard, var expanded: Boolean = false) {
|
||||
|
||||
fun getVCardProperties(context: Context): List<VCardPropertyWrapper> {
|
||||
return vCard.properties
|
||||
.filter { displayedPropertyClasses.contains(it::class.java) }
|
||||
.map { VCardPropertyWrapper.from(context, it) }
|
||||
}
|
||||
}
|
||||
|
||||
data class VCardPropertyWrapper(val value: String, val type: String, val property: VCardProperty) {
|
||||
|
||||
companion object {
|
||||
private const val CELL = "CELL"
|
||||
private const val HOME = "HOME"
|
||||
private const val WORK = "WORK"
|
||||
|
||||
private fun VCardProperty.getPropertyTypeString(context: Context): String {
|
||||
return when (parameters.type) {
|
||||
CELL -> context.getString(R.string.mobile)
|
||||
HOME -> context.getString(R.string.home)
|
||||
WORK -> context.getString(R.string.work)
|
||||
else -> ""
|
||||
}
|
||||
}
|
||||
|
||||
fun from(context: Context, property: VCardProperty): VCardPropertyWrapper {
|
||||
return property.run {
|
||||
when (this) {
|
||||
is Telephone -> VCardPropertyWrapper(text.normalizePhoneNumber(), getPropertyTypeString(context), property)
|
||||
is Email -> VCardPropertyWrapper(value, getPropertyTypeString(context), property)
|
||||
is Organization -> VCardPropertyWrapper(values.joinToString(), context.getString(R.string.work), property)
|
||||
is Birthday -> VCardPropertyWrapper(date.format(context.config.dateFormat), context.getString(R.string.birthday), property)
|
||||
is Anniversary -> VCardPropertyWrapper(date.format(context.config.dateFormat), context.getString(R.string.anniversary), property)
|
||||
is Note -> VCardPropertyWrapper(value, context.getString(R.string.notes), property)
|
||||
else -> VCardPropertyWrapper("", "", property)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue