Check both short and long label for shortcuts

This closes #132
This commit is contained in:
Ensar Sarajčić 2023-09-21 10:17:31 +02:00
parent 6e9d8686bf
commit d50d5702ba
3 changed files with 13 additions and 5 deletions

View file

@ -13,6 +13,7 @@ import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.content.pm.ShortcutInfo
import android.content.res.Configuration
import android.graphics.Bitmap
import android.graphics.Color
@ -235,8 +236,8 @@ class MainActivity : SimpleActivity(), FlingListener {
val item = launcherApps.getPinItemRequest(resultData)
item.accept()
val shortcutId = item.shortcutInfo?.id!!
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: ""
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
val label = item.shortcutInfo.getLabel()
val icon = launcherApps.getShortcutBadgedIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
mActionOnAddShortcut?.invoke(shortcutId, label, icon)
}
}
@ -363,8 +364,8 @@ class MainActivity : SimpleActivity(), FlingListener {
ensureBackgroundThread {
val shortcutId = item.shortcutInfo?.id!!
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: ""
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
val label = item.shortcutInfo.getLabel()
val icon = launcherApps.getShortcutBadgedIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
val (page, rect) = findFirstEmptyCell()
val gridItem = HomeScreenGridItem(
null,

View file

@ -126,7 +126,7 @@ fun Activity.handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridI
if (hasShortcuts) {
val iconSize = resources.getDimensionPixelSize(R.dimen.menu_icon_size)
shortcuts?.forEach {
menu.add(R.id.group_shortcuts, Menu.NONE, Menu.NONE, it.longLabel)
menu.add(R.id.group_shortcuts, Menu.NONE, Menu.NONE, it.getLabel())
.setIcon(
launcherApps.getShortcutIconDrawable(it, resources.displayMetrics.densityDpi).toBitmap(width = iconSize, height = iconSize)
.toDrawable(resources)

View file

@ -0,0 +1,7 @@
package com.simplemobiletools.launcher.extensions
import android.content.pm.ShortcutInfo
fun ShortcutInfo?.getLabel() = this?.longLabel?.toString().ifNullOrEmpty { this?.shortLabel?.toString() } ?: ""
private fun String?.ifNullOrEmpty(block: () -> String?) = this?.ifEmpty { block() } ?: block()