Further search result design adjustments

This commit is contained in:
MM20
2024-06-29 21:57:31 +02:00
parent 7258d456d3
commit 304ca12e65
18 changed files with 775 additions and 336 deletions
@@ -29,6 +29,10 @@ import org.apache.commons.text.similarity.FuzzyScore
import java.util.Locale
interface AppRepository : SearchableRepository<Application> {
fun findOne(
packageName: String,
user: UserHandle,
): Flow<Application?>
fun findMany(): Flow<ImmutableList<Application>>
}
@@ -195,6 +199,17 @@ internal class AppRepositoryImpl(
return LauncherApp(context, launcherActivityInfo)
}
override fun findOne(
packageName: String,
user: UserHandle,
): Flow<Application?> {
return installedApps.map {
it.firstOrNull {
it.componentName.packageName == packageName && it.user == user
}
}
}
override fun findMany(): Flow<ImmutableList<Application>> {
return installedApps.map { it.toImmutableList() }
}
@@ -42,8 +42,11 @@ class LauncherShortcutDeserializer(
val id = json.getString("id")
val userSerial = json.optLong("user")
val userManager = context.getSystemService<UserManager>()!!
val user = userManager.getUserForSerialNumber(userSerial) ?: return null
if (!launcherApps.hasShortcutHostPermission()) {
return UnavailableShortcut(context, id, packageName, userSerial)
return UnavailableShortcut(context, id, packageName, user, userSerial)
}
else {
val query = LauncherApps.ShortcutQuery()
@@ -55,8 +58,6 @@ class LauncherShortcutDeserializer(
LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED_BY_ANY_LAUNCHER
)
query.setShortcutIds(mutableListOf(id))
val userManager = context.getSystemService<UserManager>()!!
val user = userManager.getUserForSerialNumber(userSerial) ?: return null
val shortcuts = try {
launcherApps.getShortcuts(query, user)
} catch (e: IllegalStateException) {
@@ -10,6 +10,7 @@ import android.content.pm.ShortcutInfo
import android.graphics.drawable.AdaptiveIconDrawable
import android.os.Bundle
import android.os.Process
import android.os.UserHandle
import android.util.Log
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService
@@ -41,6 +42,9 @@ internal data class LauncherShortcut(
override val packageName: String
get() = launcherShortcut.`package`
override val user: UserHandle
get() = launcherShortcut.userHandle
constructor(
context: Context,
launcherShortcut: ShortcutInfo,
@@ -5,6 +5,7 @@ import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Process
import android.os.UserHandle
import android.os.UserManager
import de.mm20.launcher2.icons.ColorLayer
import de.mm20.launcher2.icons.StaticLauncherIcon
@@ -24,15 +25,15 @@ internal class UnavailableShortcut(
override val packageName: String,
val shortcutId: String,
val isMainProfile: Boolean,
override val user: UserHandle,
val userSerial: Long,
): AppShortcut {
override val key: String
get() = if (isMainProfile) {
"$domain://${packageName}/${shortcutId}"
} else {
"$domain://${packageName}/${shortcutId}:userSerial"
"$domain://${packageName}/${shortcutId}:$userSerial"
}
override val labelOverride: String?
@@ -70,19 +71,19 @@ internal class UnavailableShortcut(
get() = if (isMainProfile) AppProfile.Personal else AppProfile.Work
companion object {
internal operator fun invoke(context: Context, id: String, packageName: String, userSerial: Long): UnavailableShortcut? {
internal operator fun invoke(context: Context, id: String, packageName: String, user: UserHandle, userSerial: Long): UnavailableShortcut? {
val appInfo = try {
context.packageManager.getApplicationInfo(packageName, 0)
} catch (e: PackageManager.NameNotFoundException) {
return null
}
val userManager = context.getSystemService(Context.USER_SERVICE) as UserManager
return UnavailableShortcut(
label = context.getString(R.string.shortcut_label_unavailable),
appName = appInfo.loadLabel(context.packageManager).toString(),
packageName = packageName,
shortcutId = id,
isMainProfile = userManager.getUserForSerialNumber(userSerial) == Process.myUserHandle(),
isMainProfile = user == Process.myUserHandle(),
user = user,
userSerial = userSerial,
)
}
@@ -70,10 +70,10 @@ data class Notification(
get() = extras.getInt(NotificationCompat.EXTRA_PROGRESS_MAX).takeIf { it > 0 }
val title: String?
get() = extras.getString(NotificationCompat.EXTRA_TITLE)
get() = extras.getString(NotificationCompat.EXTRA_TITLE)?.takeIf { it.isNotBlank() }
val text: String?
get() = extras.getString(NotificationCompat.EXTRA_TEXT)
get() = extras.getString(NotificationCompat.EXTRA_TEXT)?.takeIf { it.isNotBlank() }
val isGroupSummary: Boolean
get() = flags and NotificationCompat.FLAG_GROUP_SUMMARY != 0
@@ -16,10 +16,10 @@ import java.util.concurrent.ExecutionException
internal data class WebsiteImpl(
override val label: String,
override val url: String,
override val description: String,
override val imageUrl: String,
override val faviconUrl: String,
override val color: Int,
override val description: String?,
override val imageUrl: String?,
override val faviconUrl: String?,
override val color: Int?,
override val labelOverride: String? = null,
) : Website {
@@ -38,7 +38,7 @@ internal data class WebsiteImpl(
size: Int,
themed: Boolean,
): LauncherIcon? {
if (faviconUrl.isEmpty()) return null
if (faviconUrl == null) return null
try {
val request = ImageRequest.Builder(context)
.data(faviconUrl)
@@ -61,7 +61,7 @@ internal data class WebsiteImpl(
}
override fun getPlaceholderIcon(context: Context): StaticLauncherIcon {
val color = if (color != 0) color else 0xFFF76F8E.toInt()
val color = color ?: 0xFFF76F8E.toInt()
if (label.isNotBlank()) {
return StaticLauncherIcon(
foregroundLayer = TextLayer(text = label[0].toString(), color = color),
@@ -95,10 +95,10 @@ internal class WebsiteRepository(
return@withContext WebsiteImpl(
label = title,
url = url,
description = description,
imageUrl = image,
faviconUrl = favicon,
color = color
description = description.takeIf { it.isNotBlank() },
imageUrl = image.takeIf { it.isNotBlank() },
faviconUrl = favicon.takeIf { it.isNotBlank() },
color = color.takeIf { it != 0 }
)
} catch (e: IOException) {
//Ignore. Not a HTML page or no connection. No result for this query
@@ -28,11 +28,11 @@ class WebsiteDeserializer: SearchableDeserializer {
val json = JSONObject(serialized)
return WebsiteImpl(
label = json.getString("label"),
faviconUrl = json.getString("favicon"),
imageUrl = json.getString("image"),
description = json.getString("description"),
faviconUrl = json.getString("favicon").takeIf { it.isNotBlank() },
imageUrl = json.getString("image").takeIf { it.isNotBlank() },
description = json.getString("description").takeIf { it.isNotBlank() },
url = json.getString("url"),
color = json.getInt("color")
color = json.getInt("color").takeIf { it != 0 }
)
}
}