diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt index b52b41f..5d8f2e2 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/activities/MainActivity.kt @@ -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, diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Activity.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Activity.kt index a4c2e50..b427b5b 100644 --- a/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Activity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Activity.kt @@ -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) diff --git a/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Misc.kt b/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Misc.kt new file mode 100644 index 0000000..abf71b0 --- /dev/null +++ b/app/src/main/kotlin/com/simplemobiletools/launcher/extensions/Misc.kt @@ -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()