Merge pull request #136 from esensar/fix/132-empty-shortcut-labels

Check both short and long label for shortcuts
This commit is contained in:
Tibor Kaputa 2023-09-21 11:40:06 +02:00 committed by GitHub
commit f46b6fcc2c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.ActivityInfo
import android.content.pm.LauncherApps import android.content.pm.LauncherApps
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.content.pm.ShortcutInfo
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.Bitmap import android.graphics.Bitmap
import android.graphics.Color import android.graphics.Color
@ -235,8 +236,8 @@ class MainActivity : SimpleActivity(), FlingListener {
val item = launcherApps.getPinItemRequest(resultData) val item = launcherApps.getPinItemRequest(resultData)
item.accept() item.accept()
val shortcutId = item.shortcutInfo?.id!! val shortcutId = item.shortcutInfo?.id!!
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: "" val label = item.shortcutInfo.getLabel()
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi) val icon = launcherApps.getShortcutBadgedIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
mActionOnAddShortcut?.invoke(shortcutId, label, icon) mActionOnAddShortcut?.invoke(shortcutId, label, icon)
} }
} }
@ -363,8 +364,8 @@ class MainActivity : SimpleActivity(), FlingListener {
ensureBackgroundThread { ensureBackgroundThread {
val shortcutId = item.shortcutInfo?.id!! val shortcutId = item.shortcutInfo?.id!!
val label = item.shortcutInfo?.shortLabel?.toString() ?: item.shortcutInfo?.longLabel?.toString() ?: "" val label = item.shortcutInfo.getLabel()
val icon = launcherApps.getShortcutIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi) val icon = launcherApps.getShortcutBadgedIconDrawable(item.shortcutInfo!!, resources.displayMetrics.densityDpi)
val (page, rect) = findFirstEmptyCell() val (page, rect) = findFirstEmptyCell()
val gridItem = HomeScreenGridItem( val gridItem = HomeScreenGridItem(
null, null,

View File

@ -126,7 +126,7 @@ fun Activity.handleGridItemPopupMenu(anchorView: View, gridItem: HomeScreenGridI
if (hasShortcuts) { if (hasShortcuts) {
val iconSize = resources.getDimensionPixelSize(R.dimen.menu_icon_size) val iconSize = resources.getDimensionPixelSize(R.dimen.menu_icon_size)
shortcuts?.forEach { 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( .setIcon(
launcherApps.getShortcutIconDrawable(it, resources.displayMetrics.densityDpi).toBitmap(width = iconSize, height = iconSize) launcherApps.getShortcutIconDrawable(it, resources.displayMetrics.densityDpi).toBitmap(width = iconSize, height = iconSize)
.toDrawable(resources) .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()