1
0
Fork 0

For #10969: Fix and clarify logic for checking showing PWA dialog.

master
mcarare 2020-05-28 10:31:55 +03:00 committed by Mihai Branescu
parent aa487bf4c3
commit 9ec6ebc92a
4 changed files with 15 additions and 23 deletions

View File

@ -74,6 +74,6 @@ object Performance {
* Disables the first time PWA popup. * Disables the first time PWA popup.
*/ */
private fun disableFirstTimePWAPopup(context: Context) { private fun disableFirstTimePWAPopup(context: Context) {
Settings.getInstance(context).shouldShowFirstTimePwaFragment = false Settings.getInstance(context).userKnowsAboutPWAs = true
} }
} }

View File

@ -27,7 +27,7 @@ class FirstTimePwaObserver(
val directions = BrowserFragmentDirections.actionBrowserFragmentToFirstTimePwaFragment() val directions = BrowserFragmentDirections.actionBrowserFragmentToFirstTimePwaFragment()
navController.nav(R.id.browserFragment, directions) navController.nav(R.id.browserFragment, directions)
settings.shouldShowFirstTimePwaFragment = false settings.userKnowsAboutPWAs = true
} }
} }
} }

View File

@ -456,34 +456,25 @@ class Settings private constructor(
default = false default = false
) )
var shouldShowFirstTimePwaFragment: Boolean val shouldShowFirstTimePwaFragment: Boolean
get() { get() {
val alreadyShownPwaOnboarding = preferences.getBoolean(
appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa), false)
// ShortcutManager::pinnedShortcuts is only available on Oreo+ // ShortcutManager::pinnedShortcuts is only available on Oreo+
if (!alreadyShownPwaOnboarding && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (!userKnowsAboutPWAs && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val alreadyHavePWaInstalled = val alreadyHavePWaInstalled =
appContext.getSystemService(ShortcutManager::class.java) appContext.getSystemService(ShortcutManager::class.java)
.pinnedShortcuts.size > 0 .pinnedShortcuts.size > 0
// Users don't need to be shown the PWA onboarding if they already have PWAs installed. // Users know about PWAs onboarding if they already have PWAs installed.
preferences.edit() userKnowsAboutPWAs = alreadyHavePWaInstalled
.putBoolean(
appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa),
alreadyHavePWaInstalled)
.apply()
return !alreadyHavePWaInstalled
} }
// Show dialog only if user does not know abut PWAs
return !userKnowsAboutPWAs
}
return !alreadyShownPwaOnboarding var userKnowsAboutPWAs by booleanPreference(
} appContext.getPreferenceKey(R.string.pref_key_user_knows_about_pwa),
set(value) { default = false
preferences.edit() )
.putBoolean(appContext.getPreferenceKey(R.string.pref_key_show_first_time_pwa), value)
.apply()
}
@VisibleForTesting(otherwise = PRIVATE) @VisibleForTesting(otherwise = PRIVATE)
internal val trackingProtectionOnboardingCount by intPreference( internal val trackingProtectionOnboardingCount by intPreference(

View File

@ -161,7 +161,8 @@
<string name="default_top_sites_added" translatable="false">pref_key_pocket_top_site_added</string> <string name="default_top_sites_added" translatable="false">pref_key_pocket_top_site_added</string>
<string name="pref_key_top_sites_size" translatable="false">pref_key_top_sites_size</string> <string name="pref_key_top_sites_size" translatable="false">pref_key_top_sites_size</string>
<string name="pref_key_show_first_time_pwa" translatable="false">pref_key_show_first_time_pwa</string> <!-- A value of `true` means the PWA dialog has been showed or user already has PWAs installed-->
<string name="pref_key_user_knows_about_pwa" translatable="false">pref_key_user_knows_about_pwa</string>
<string name="pref_key_migrating_from_fenix_nightly_tip" translatable="false">pref_key_migrating_from_fenix_nightly_tip</string> <string name="pref_key_migrating_from_fenix_nightly_tip" translatable="false">pref_key_migrating_from_fenix_nightly_tip</string>
<string name="pref_key_migrating_from_firefox_nightly_tip" translatable="false">pref_key_migrating_from_firefox_nightly_tip</string> <string name="pref_key_migrating_from_firefox_nightly_tip" translatable="false">pref_key_migrating_from_firefox_nightly_tip</string>