Contact stuff

This commit is contained in:
MM20
2025-04-04 18:16:16 +02:00
parent 0ebce91a43
commit 04dd12ee96
7 changed files with 141 additions and 73 deletions
@@ -8,13 +8,17 @@ import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.StaticLauncherIcon
import de.mm20.launcher2.icons.TextLayer
import de.mm20.launcher2.icons.VectorLayer
import de.mm20.launcher2.search.contact.CustomContactChannel
import de.mm20.launcher2.search.contact.EmailAddress
import de.mm20.launcher2.search.contact.PhoneNumber
import de.mm20.launcher2.search.contact.PostalAddress
interface Contact : SavableSearchable {
val name: String
val phoneNumbers: List<PhoneNumber>
val emailAddresses: List<EmailAddress>
val postalAddresses: List<PostalAddress>
val contactApps: List<ContactApp>
val contactChannels: List<CustomContactChannel>
val summary: String
get() {
@@ -41,32 +45,3 @@ interface Contact : SavableSearchable {
override val preferDetailsOverLaunch: Boolean
get() = true
}
data class PhoneNumber(
val number: String,
val type: ContactInfoType,
)
data class EmailAddress(
val address: String,
val type: ContactInfoType,
)
data class PostalAddress(
val address: String,
val type: ContactInfoType,
)
data class ContactApp(
val label: String,
val uri: Uri,
val mimeType: String,
val packageName: String,
)
enum class ContactInfoType {
Home,
Mobile,
Work,
Other,
}
@@ -0,0 +1,26 @@
package de.mm20.launcher2.ktx
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
fun PackageManager.getApplicationInfoOrNull(
packageName: String,
flags: Int = 0,
): ApplicationInfo? {
return try {
getApplicationInfo(packageName, flags)
} catch (e: PackageManager.NameNotFoundException) {
null
}
}
fun PackageManager.getApplicationIconOrNull(
packageName: String,
): Drawable? {
return try {
getApplicationIcon(packageName)
} catch (e: PackageManager.NameNotFoundException) {
null
}
}
@@ -0,0 +1,28 @@
package de.mm20.launcher2.plugin.contracts
import de.mm20.launcher2.search.contact.CustomContactChannel
import de.mm20.launcher2.search.contact.EmailAddress
import de.mm20.launcher2.search.contact.PhoneNumber
import de.mm20.launcher2.search.contact.PostalAddress
abstract class ContactPluginContract {
object ContactColumns: Columns() {
/**
* The unique ID of the contact.
*/
val Id = column<String>("id")
/**
* The display name of the contact.
* First name + last name, if applicable.
*/
val Name = column<String>("name")
val PhoneNumbers = column<List<PhoneNumber>>("phone_numbers")
val EmailAddresses = column<List<EmailAddress>>("email_addresses")
val PostalAddresses = column<List<PostalAddress>>("postal_addresses")
val ContactChannels = column<List<CustomContactChannel>>("contact_channels")
val PhotoUri = column<String>("photo_uri")
}
}
@@ -0,0 +1,52 @@
package de.mm20.launcher2.search.contact
import android.net.Uri
import de.mm20.launcher2.serialization.UriSerializer
import kotlinx.serialization.Serializable
@Serializable
data class PhoneNumber(
val number: String,
val type: ContactInfoType = ContactInfoType.Other,
)
@Serializable
data class EmailAddress(
val address: String,
val type: ContactInfoType = ContactInfoType.Other,
)
@Serializable
data class PostalAddress(
val address: String,
val type: ContactInfoType = ContactInfoType.Other,
)
/**
* Custom contact channel, for example, WhatsApp message, Telegram video call, etc.
*/
@Serializable
data class CustomContactChannel(
val label: String,
/**
* The data URI that is passed to the Intent.
*/
@Serializable(with = UriSerializer::class) val uri: Uri,
/**
* Type that is passed to the Intent.
*/
val mimeType: String,
/**
* Package name of the app that handles this channel.
* Used to get the app icon, and label, and to group channels by app.
* If the app is not installed, the channel will be ignored.
*/
val packageName: String,
)
enum class ContactInfoType {
Home,
Mobile,
Work,
Other,
}