From d0ce0368c53fefc13927f84b606e52e7777523b2 Mon Sep 17 00:00:00 2001 From: Isira Seneviratne Date: Fri, 3 Mar 2023 05:16:33 +0530 Subject: [PATCH] Report selected shortcut to the system. --- .../libretube/ui/activities/MainActivity.kt | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt index ff0ea7808..1dfd36d86 100644 --- a/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/ui/activities/MainActivity.kt @@ -13,6 +13,7 @@ import android.view.ViewGroup import android.widget.ScrollView import androidx.activity.addCallback import androidx.appcompat.widget.SearchView +import androidx.core.content.pm.ShortcutManagerCompat import androidx.core.os.bundleOf import androidx.core.view.children import androidx.core.widget.NestedScrollView @@ -411,17 +412,18 @@ class MainActivity : BaseActivity() { ) } - when (intent?.getStringExtra("fragmentToOpen")) { - "home" -> - navController.navigate(R.id.homeFragment) - "trends" -> - navController.navigate(R.id.trendsFragment) - "subscriptions" -> - navController.navigate(R.id.subscriptionsFragment) - "library" -> - navController.navigate(R.id.libraryFragment) - "downloads" -> - navController.navigate(R.id.downloadsFragment) + intent?.getStringExtra("fragmentToOpen")?.let { + if (it != "downloads") { // Not a shortcut + ShortcutManagerCompat.reportShortcutUsed(this, it) + } + + when (it) { + "home" -> navController.navigate(R.id.homeFragment) + "trends" -> navController.navigate(R.id.trendsFragment) + "subscriptions" -> navController.navigate(R.id.subscriptionsFragment) + "library" -> navController.navigate(R.id.libraryFragment) + "downloads" -> navController.navigate(R.id.downloadsFragment) + } } if (intent?.getBooleanExtra(IntentData.downloading, false) == true) { (supportFragmentManager.fragments.find { it is NavHostFragment })