1
0
Fork 0

Issue #5233: Added doesPrivateBrowsingPinnedShortcutExist function to determine whether a shortcut already exists (only available in API >=25).

master
bswe 2019-10-03 12:02:51 -07:00
parent 8e4d7248ac
commit dcebd83e9f
1 changed files with 19 additions and 1 deletions

View File

@ -14,12 +14,30 @@ import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
import java.util.UUID
import android.content.pm.ShortcutManager
import android.os.Build
import android.os.Build.VERSION.SDK_INT
/**
* Handles the creation of pinned shortcuts.
* Handles the creation and existence of pinned shortcuts.
*/
object PrivateShortcutCreateManager {
fun doesPrivateBrowsingPinnedShortcutExist(context: Context) : Boolean {
return if (SDK_INT >= Build.VERSION_CODES.N_MR1) {
val pinnedShortcuts = context.getSystemService(ShortcutManager::class.java).pinnedShortcuts
for (s in pinnedShortcuts) {
if (s.intent?.extras?.getString(HomeActivity.OPEN_TO_SEARCH) ==
StartSearchIntentProcessor.PRIVATE_BROWSING_PINNED_SHORTCUT) {
return true
}
}
false
} else {
false
}
}
fun createPrivateShortcut(context: Context) {
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) return