mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 22:30:30 +05:30
Use ShortcutManagerCompat.setDynamicShortcuts().
This commit is contained in:
parent
f9ab38add3
commit
d4f18799ea
@ -16,30 +16,25 @@ object ShortcutHelper {
|
|||||||
AppShortcut("trends", R.string.trends, R.drawable.ic_trending),
|
AppShortcut("trends", R.string.trends, R.drawable.ic_trending),
|
||||||
AppShortcut("subscriptions", R.string.subscriptions, R.drawable.ic_subscriptions),
|
AppShortcut("subscriptions", R.string.subscriptions, R.drawable.ic_subscriptions),
|
||||||
AppShortcut("library", R.string.library, R.drawable.ic_library)
|
AppShortcut("library", R.string.library, R.drawable.ic_library)
|
||||||
).reversed()
|
)
|
||||||
|
|
||||||
private fun createShortcut(context: Context, action: String, label: String, icon: IconCompat) {
|
private fun createShortcut(context: Context, appShortcut: AppShortcut): ShortcutInfoCompat {
|
||||||
val shortcut = ShortcutInfoCompat.Builder(context, action)
|
val label = context.getString(appShortcut.label)
|
||||||
|
return ShortcutInfoCompat.Builder(context, appShortcut.action)
|
||||||
.setShortLabel(label)
|
.setShortLabel(label)
|
||||||
.setLongLabel(label)
|
.setLongLabel(label)
|
||||||
.setIcon(icon)
|
.setIcon(IconCompat.createWithResource(context, appShortcut.drawable))
|
||||||
.setIntent(
|
.setIntent(
|
||||||
Intent(context, MainActivity::class.java).apply {
|
Intent(Intent.ACTION_VIEW, null, context, MainActivity::class.java)
|
||||||
this.action = Intent.ACTION_VIEW
|
.putExtra(IntentData.fragmentToOpen, appShortcut.action)
|
||||||
putExtra(IntentData.fragmentToOpen, action)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
ShortcutManagerCompat.pushDynamicShortcut(context, shortcut)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createShortcuts(context: Context) {
|
fun createShortcuts(context: Context) {
|
||||||
ShortcutManagerCompat.getDynamicShortcuts(context).takeIf { it.isEmpty() } ?: return
|
if (ShortcutManagerCompat.getDynamicShortcuts(context).isEmpty()) {
|
||||||
|
val dynamicShortcuts = shortcuts.map { createShortcut(context, it) }
|
||||||
shortcuts.forEach {
|
ShortcutManagerCompat.setDynamicShortcuts(context, dynamicShortcuts)
|
||||||
val icon = IconCompat.createWithResource(context, it.drawable)
|
|
||||||
createShortcut(context, it.action, context.getString(it.label), icon)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user