mirror of
https://github.com/SimpleMobileTools/Simple-SMS-Messenger.git
synced 2025-03-04 11:27:51 +01:00
Restructure code
This commit is contained in:
parent
93848b1894
commit
b6e21507c1
@ -76,6 +76,6 @@ class VCardViewerActivity : SimpleActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun prepareData(vCards: List<VCard>): List<VCardWrapper> {
|
private fun prepareData(vCards: List<VCard>): List<VCardWrapper> {
|
||||||
return vCards.map { VCardWrapper(it) }
|
return vCards.map { vCard -> VCardWrapper.from(this, vCard) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,7 +20,7 @@ import kotlinx.android.synthetic.main.item_vcard_contact.view.*
|
|||||||
import kotlinx.android.synthetic.main.item_vcard_contact_property.view.*
|
import kotlinx.android.synthetic.main.item_vcard_contact_property.view.*
|
||||||
|
|
||||||
class VCardViewerAdapter(
|
class VCardViewerAdapter(
|
||||||
private val activity: SimpleActivity, private var items: MutableList<Any>, private val itemClick: (Any) -> Unit
|
activity: SimpleActivity, private var items: MutableList<Any>, private val itemClick: (Any) -> Unit
|
||||||
) : RecyclerView.Adapter<VCardViewerAdapter.VCardViewHolder>() {
|
) : RecyclerView.Adapter<VCardViewerAdapter.VCardViewHolder>() {
|
||||||
|
|
||||||
private var fontSize = activity.getTextSize()
|
private var fontSize = activity.getTextSize()
|
||||||
@ -53,7 +53,7 @@ class VCardViewerAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun setupVCardView(view: View, item: VCardWrapper) {
|
private fun setupVCardView(view: View, item: VCardWrapper) {
|
||||||
val name = item.getFullName()
|
val name = item.fullName
|
||||||
view.apply {
|
view.apply {
|
||||||
item_contact_name.apply {
|
item_contact_name.apply {
|
||||||
text = name
|
text = name
|
||||||
@ -121,7 +121,7 @@ class VCardViewerAdapter(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun expandOrCollapseRow(view: View, item: VCardWrapper) {
|
private fun expandOrCollapseRow(view: View, item: VCardWrapper) {
|
||||||
val properties = item.getVCardProperties(context = activity)
|
val properties = item.properties
|
||||||
if (item.expanded) {
|
if (item.expanded) {
|
||||||
collapseRow(view, properties, item)
|
collapseRow(view, properties, item)
|
||||||
} else {
|
} else {
|
||||||
|
@ -12,28 +12,33 @@ private val displayedPropertyClasses = arrayOf(
|
|||||||
Telephone::class.java, Email::class.java, Organization::class.java, Birthday::class.java, Anniversary::class.java, Note::class.java
|
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) {
|
data class VCardWrapper(val vCard: VCard, val fullName: String?, val properties: List<VCardPropertyWrapper>, var expanded: Boolean = false) {
|
||||||
|
|
||||||
fun getFullName(): String? {
|
companion object {
|
||||||
var formattedName = vCard.formattedName?.value
|
private fun VCard.extractFullName(): String? {
|
||||||
if (formattedName.isNullOrEmpty()) {
|
var fullName = formattedName?.value
|
||||||
val structured = vCard.structuredName
|
if (fullName.isNullOrEmpty()) {
|
||||||
|
val structured = structuredName
|
||||||
val given = structured?.given
|
val given = structured?.given
|
||||||
val family = structured.family
|
val family = structured.family
|
||||||
formattedName = if (family != null) {
|
fullName = if (family != null) {
|
||||||
given?.plus(" ")?.plus(family)
|
given?.plus(" ")?.plus(family)
|
||||||
} else {
|
} else {
|
||||||
given
|
given
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return formattedName
|
return fullName
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVCardProperties(context: Context): List<VCardPropertyWrapper> {
|
fun from(context: Context, vCard: VCard): VCardWrapper {
|
||||||
return vCard.properties
|
val properties = vCard.properties
|
||||||
.filter { displayedPropertyClasses.contains(it::class.java) }
|
.filter { displayedPropertyClasses.contains(it::class.java) }
|
||||||
.map { VCardPropertyWrapper.from(context, it) }
|
.map { VCardPropertyWrapper.from(context, it) }
|
||||||
.distinctBy { it.value }
|
.distinctBy { it.value }
|
||||||
|
val fullName = vCard.extractFullName()
|
||||||
|
|
||||||
|
return VCardWrapper(vCard, fullName, properties, expanded = false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user