PwaOnboardingObserver.kt 1.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.fenix.shortcut

import androidx.navigation.NavController
import mozilla.components.browser.session.Session
import mozilla.components.feature.pwa.WebAppUseCases
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserFragmentDirections
import org.mozilla.fenix.ext.nav
import org.mozilla.fenix.utils.Settings

/**
16
 * Displays the [PwaOnboardingDialogFragment] info dialog when a PWA is opened in the browser for the third time.
17
 */
18
class PwaOnboardingObserver(
19
20
21
22
23
    private val navController: NavController,
    private val settings: Settings,
    private val webAppUseCases: WebAppUseCases
) : Session.Observer {

24
    override fun onLoadingStateChanged(session: Session, loading: Boolean) {
25
        @SuppressWarnings("CollapsibleIfStatements")
26
        if (!loading && webAppUseCases.isInstallable() && !settings.userKnowsAboutPwas) {
27
            // settings.incrementVisitedInstallableCount()
28
            if (settings.shouldShowPwaCfr) {
29
30
31
                val directions =
                    BrowserFragmentDirections.actionBrowserFragmentToPwaOnboardingDialogFragment()
                navController.nav(R.id.browserFragment, directions)
32
                settings.lastCfrShownTimeInMillis = System.currentTimeMillis()
33
34
                settings.userKnowsAboutPwas = true
            }
35
36
37
        }
    }
}