1
0
Fork 0
5775: Closes #5233, don't display private-browsing-shortcut creation items if shortcut already exists r=NotWoods a=bswe

Closes issue #5233:

Added doesPrivateBrowsingPinnedShortcutExist() method to the PrivateShortcutCreateManager class to check for the existence of the shortcut.  Code only works on devices with API 25 or higher, so a check for that condition was also included in the new method.

Calls to the new method were added to the SettingsFragment and HomeFragment classes to determine whether the settings menu item and the recommendation dialog should be displayed.

**Quality**: The pre-push test failed to start on my windows 10 OS, but this code has been thoroughly tested manually on simulators and physical devices.

**Tests**: This code only effects UI appearance so not sure how to test for that and no tests were written.

**Screenshots**: This code does not add anything new to the UI, it only controls whether to display existing items.

Co-authored-by: bswe <bbollenbacher@mindspring.com>
master
MozLando 2019-10-14 22:23:45 +00:00
commit 9d3dc2b6dc
3 changed files with 22 additions and 2 deletions

View File

@ -14,12 +14,26 @@ 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
pinnedShortcuts.any {
it.intent?.extras?.getString(HomeActivity.OPEN_TO_SEARCH) ==
StartSearchIntentProcessor.PRIVATE_BROWSING_PINNED_SHORTCUT
}
} else
false
}
fun createPrivateShortcut(context: Context) {
if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) return

View File

@ -347,8 +347,10 @@ class HomeFragment : Fragment() {
}
}
}, owner = this)
if (context.settings().showPrivateModeContextualFeatureRecommender &&
browsingModeManager.mode.isPrivate) {
browsingModeManager.mode.isPrivate &&
!PrivateShortcutCreateManager.doesPrivateBrowsingPinnedShortcutExist(context)) {
recommendPrivateBrowsingShortcut()
}
}

View File

@ -132,6 +132,10 @@ class SettingsFragment : PreferenceFragmentCompat(), AccountObserver {
}
}
findPreference<Preference>(getPreferenceKey(R.string.pref_key_add_private_browsing_shortcut))?.apply {
isVisible = !PrivateShortcutCreateManager.doesPrivateBrowsingPinnedShortcutExist(context)
}
setupPreferences()
updateAccountUIState(context!!, requireComponents.backgroundServices.accountManager.accountProfile())