Further search result design adjustments
This commit is contained in:
+4
-3
@@ -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,
|
||||
|
||||
+6
-5
@@ -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,
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user