Services.kt 1.66 KB
Newer Older
1
2
3
4
5
6
/* 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.components

7
import android.content.Context
8
import androidx.preference.PreferenceManager
9
10
11
12
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import mozilla.components.feature.accounts.FirefoxAccountsAuthFeature
13
import mozilla.components.feature.app.links.AppLinksInterceptor
14
import mozilla.components.service.fxa.manager.FxaAccountManager
15
16
import org.mozilla.fenix.R
import org.mozilla.fenix.ext.getPreferenceKey
17
import org.mozilla.fenix.settings.SupportUtils
18
import org.mozilla.fenix.utils.Mockable
19
20
21
22

/**
 * Component group which encapsulates foreground-friendly services.
 */
23
@Mockable
24
class Services(
Grisha Kruglov's avatar
Grisha Kruglov committed
25
    private val context: Context,
26
    private val accountManager: FxaAccountManager
27
28
) {
    val accountsAuthFeature by lazy {
29
        FirefoxAccountsAuthFeature(accountManager, FxaServer.redirectUrl()) { context, authUrl ->
30
31
32
33
34
            CoroutineScope(Dispatchers.Main).launch {
                val intent = SupportUtils.createAuthCustomTabIntent(context, authUrl)
                context.startActivity(intent)
            }
        }
35
    }
36

37
38
39
40
41
    val appLinksInterceptor by lazy {
        AppLinksInterceptor(
            context,
            interceptLinkClicks = true,
            launchInApp = {
42
                PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
43
44
45
46
                    context.getPreferenceKey(R.string.pref_key_open_links_in_external_app), false)
            }
        )
    }
47
}