Remove firstName and lastName from contact interface,
move some implementations from AndroidContact to Contact interface
This commit is contained in:
parent
fb33c859d3
commit
7ec315dfc7
@ -1,17 +1,43 @@
|
||||
package de.mm20.launcher2.search
|
||||
|
||||
import android.content.Context
|
||||
import android.net.Uri
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.rounded.Person
|
||||
import de.mm20.launcher2.icons.ColorLayer
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.icons.TextLayer
|
||||
import de.mm20.launcher2.icons.VectorLayer
|
||||
|
||||
interface Contact : SavableSearchable {
|
||||
val firstName: String
|
||||
val lastName: String
|
||||
val displayName: String
|
||||
val summary: String
|
||||
val name: String
|
||||
val phoneNumbers: List<PhoneNumber>
|
||||
val emailAddresses: List<EmailAddress>
|
||||
val postalAddresses: List<PostalAddress>
|
||||
val contactApps: List<ContactApp>
|
||||
|
||||
val summary: String
|
||||
get() {
|
||||
return (phoneNumbers.map { it.number } + emailAddresses.map { it.address })
|
||||
.joinToString(", ")
|
||||
}
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
|
||||
val letter = (labelOverride ?: label).firstOrNull()?.toString()
|
||||
|
||||
if (letter != null) {
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = TextLayer(text = letter, color = 0xFF2364AA.toInt()),
|
||||
backgroundLayer = ColorLayer(0xFF2364AA.toInt())
|
||||
)
|
||||
}
|
||||
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = VectorLayer(Icons.Rounded.Person),
|
||||
backgroundLayer = ColorLayer(0xFF2364AA.toInt())
|
||||
)
|
||||
}
|
||||
|
||||
override val preferDetailsOverLaunch: Boolean
|
||||
get() = true
|
||||
}
|
||||
|
||||
@ -10,7 +10,6 @@ import de.mm20.launcher2.icons.ColorLayer
|
||||
import de.mm20.launcher2.icons.LauncherIcon
|
||||
import de.mm20.launcher2.icons.StaticIconLayer
|
||||
import de.mm20.launcher2.icons.StaticLauncherIcon
|
||||
import de.mm20.launcher2.icons.TextLayer
|
||||
import de.mm20.launcher2.ktx.asBitmap
|
||||
import de.mm20.launcher2.ktx.tryStartActivity
|
||||
import de.mm20.launcher2.search.Contact
|
||||
@ -24,9 +23,7 @@ import kotlinx.coroutines.withContext
|
||||
|
||||
internal data class AndroidContact(
|
||||
internal val id: Long,
|
||||
override val firstName: String,
|
||||
override val lastName: String,
|
||||
override val displayName: String,
|
||||
override val name: String,
|
||||
override val phoneNumbers: List<PhoneNumber>,
|
||||
override val emailAddresses: List<EmailAddress>,
|
||||
override val postalAddresses: List<PostalAddress>,
|
||||
@ -39,8 +36,7 @@ internal data class AndroidContact(
|
||||
override val domain: String = Domain
|
||||
override val key: String
|
||||
get() = "$Domain://$id"
|
||||
override val label: String
|
||||
get() = displayName.takeIf { it.isNotBlank() } ?: "$firstName $lastName"
|
||||
override val label: String = name
|
||||
|
||||
override val summary: String
|
||||
get() {
|
||||
@ -58,16 +54,6 @@ internal data class AndroidContact(
|
||||
return context.tryStartActivity(intent, options)
|
||||
}
|
||||
|
||||
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
|
||||
val iconText =
|
||||
if (firstName.isNotEmpty()) firstName[0].toString() else "" + if (lastName.isNotEmpty()) lastName[0].toString() else ""
|
||||
|
||||
return StaticLauncherIcon(
|
||||
foregroundLayer = TextLayer(text = iconText, color = 0xFF2364AA.toInt()),
|
||||
backgroundLayer = ColorLayer(0xFF2364AA.toInt())
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun loadIcon(
|
||||
context: Context,
|
||||
size: Int,
|
||||
|
||||
@ -65,9 +65,9 @@ internal class ContactRepository(
|
||||
ContactsContract.Data.CONTENT_URI,
|
||||
null, s, null, null
|
||||
) ?: return@withContext null
|
||||
var firstName = ""
|
||||
var lastName = ""
|
||||
var displayName = ""
|
||||
var firstName: String? = null
|
||||
var lastName: String? = null
|
||||
var displayName: String? = null
|
||||
val phoneNumbers = mutableListOf<PhoneNumber>()
|
||||
val emailAddresses = mutableListOf<EmailAddress>()
|
||||
val postalAddresses = mutableListOf<PostalAddress>()
|
||||
@ -133,9 +133,9 @@ internal class ContactRepository(
|
||||
}
|
||||
|
||||
ContactsContract.CommonDataKinds.StructuredName.CONTENT_ITEM_TYPE -> {
|
||||
firstName = dataCursor.getStringOrNull(givenNameColumn) ?: ""
|
||||
lastName = dataCursor.getStringOrNull(familyNameColumn) ?: ""
|
||||
displayName = dataCursor.getStringOrNull(displayNameColumn) ?: ""
|
||||
firstName = dataCursor.getStringOrNull(givenNameColumn)
|
||||
lastName = dataCursor.getStringOrNull(familyNameColumn)
|
||||
displayName = dataCursor.getStringOrNull(displayNameColumn)
|
||||
}
|
||||
|
||||
else -> {
|
||||
@ -170,9 +170,9 @@ internal class ContactRepository(
|
||||
|
||||
return@withContext AndroidContact(
|
||||
id = id,
|
||||
firstName = firstName,
|
||||
lastName = lastName,
|
||||
displayName = displayName,
|
||||
name = displayName
|
||||
?: listOfNotNull(firstName, lastName).joinToString(" ").takeIf { it.isNotBlank() }
|
||||
?: return@withContext null,
|
||||
phoneNumbers = phoneNumbers.sortedByDescending {
|
||||
it.number.count { !PhoneNumberUtils.isReallyDialable(it) }
|
||||
}.map {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user