Contact stuff
This commit is contained in:
@@ -62,12 +62,10 @@ import androidx.compose.ui.text.AnnotatedString
|
||||
import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.IntRect
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.compose.ui.unit.roundToIntRect
|
||||
import androidx.lifecycle.compose.collectAsStateWithLifecycle
|
||||
import coil.compose.AsyncImage
|
||||
import de.mm20.launcher2.ktx.tryStartActivity
|
||||
import de.mm20.launcher2.search.Contact
|
||||
import de.mm20.launcher2.search.ContactInfoType
|
||||
import de.mm20.launcher2.ui.R
|
||||
import de.mm20.launcher2.ui.component.DefaultToolbarAction
|
||||
import de.mm20.launcher2.ui.component.ShapedLauncherIcon
|
||||
@@ -85,6 +83,9 @@ import kotlinx.coroutines.flow.flow
|
||||
import kotlinx.coroutines.flow.flowOn
|
||||
import androidx.core.net.toUri
|
||||
import de.mm20.launcher2.ktx.checkPermission
|
||||
import de.mm20.launcher2.ktx.getApplicationIconOrNull
|
||||
import de.mm20.launcher2.ktx.getApplicationInfoOrNull
|
||||
import de.mm20.launcher2.search.contact.ContactInfoType
|
||||
|
||||
@Composable
|
||||
fun ContactItem(
|
||||
@@ -275,48 +276,34 @@ fun ContactItem(
|
||||
)
|
||||
}
|
||||
val apps = remember(contact) {
|
||||
contact.contactApps.groupBy { it.packageName }
|
||||
contact.contactChannels.groupBy { it.packageName }
|
||||
}
|
||||
for ((i, app) in apps.entries.withIndex()) {
|
||||
val packageName = remember(app) {
|
||||
context.packageManager.queryIntentActivities(
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(
|
||||
app.value.first().uri,
|
||||
app.value.first().mimeType
|
||||
)
|
||||
},
|
||||
0,
|
||||
).firstOrNull()?.activityInfo?.packageName
|
||||
val packageName = app.key
|
||||
val packageInfo = remember(packageName) {
|
||||
context.packageManager.getApplicationInfoOrNull(packageName)
|
||||
} ?: continue
|
||||
val appIcon by remember(app) {
|
||||
flow {
|
||||
try {
|
||||
emit(context.packageManager.getApplicationIcon(packageName))
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
emit(null)
|
||||
}
|
||||
}.flowOn(Dispatchers.IO)
|
||||
}.collectAsState(null)
|
||||
|
||||
val appIcon = remember(packageName) {
|
||||
context.packageManager.getApplicationIconOrNull(packageName)
|
||||
}
|
||||
val label = remember(app) {
|
||||
try {
|
||||
context.packageManager.getApplicationInfo(packageName, 0)
|
||||
.loadLabel(context.packageManager).toString()
|
||||
} catch (e: PackageManager.NameNotFoundException) {
|
||||
app.key
|
||||
}
|
||||
packageInfo.loadLabel(context.packageManager).toString()
|
||||
}
|
||||
val itemsWithPermission = remember(app) {
|
||||
app.value.filter {
|
||||
// exclude activities we have no permission for
|
||||
val resolvedActivityInfo = context.packageManager.resolveActivity(
|
||||
Intent(Intent.ACTION_VIEW).setDataAndType(it.uri, it.mimeType),
|
||||
Intent(Intent.ACTION_VIEW).setPackage(it.packageName).setDataAndType(it.uri, it.mimeType),
|
||||
0
|
||||
)?.activityInfo ?: return@filter false
|
||||
|
||||
resolvedActivityInfo.permission == null || context.checkPermission(resolvedActivityInfo.permission)
|
||||
}
|
||||
}
|
||||
|
||||
if (itemsWithPermission.isEmpty()) continue
|
||||
|
||||
ContactInfo(
|
||||
icon = Icons.AutoMirrored.Rounded.OpenInNew,
|
||||
customIcon = appIcon,
|
||||
@@ -334,6 +321,7 @@ fun ContactItem(
|
||||
viewModel.reportUsage(contact)
|
||||
context.tryStartActivity(
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
setPackage(packageName)
|
||||
setDataAndType(
|
||||
it.uri,
|
||||
it.mimeType
|
||||
|
||||
Reference in New Issue
Block a user