2019-02-15 23:44:43 +01:00
|
|
|
/* 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
|
|
|
|
|
2019-07-26 04:55:51 +02:00
|
|
|
import android.content.Context
|
2020-01-02 19:08:11 +01:00
|
|
|
import androidx.preference.PreferenceManager
|
2019-08-02 00:40:43 +02:00
|
|
|
import kotlinx.coroutines.CoroutineScope
|
|
|
|
import kotlinx.coroutines.Dispatchers
|
|
|
|
import kotlinx.coroutines.launch
|
|
|
|
import mozilla.components.feature.accounts.FirefoxAccountsAuthFeature
|
2019-12-20 14:27:19 +01:00
|
|
|
import mozilla.components.feature.app.links.AppLinksInterceptor
|
2019-05-08 18:04:06 +02:00
|
|
|
import mozilla.components.service.fxa.manager.FxaAccountManager
|
2019-12-20 14:27:19 +01:00
|
|
|
import org.mozilla.fenix.R
|
|
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
2019-08-02 00:40:43 +02:00
|
|
|
import org.mozilla.fenix.settings.SupportUtils
|
2020-04-04 00:20:11 +02:00
|
|
|
import org.mozilla.fenix.utils.Mockable
|
2019-02-15 23:44:43 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Component group which encapsulates foreground-friendly services.
|
|
|
|
*/
|
2019-05-07 23:36:37 +02:00
|
|
|
@Mockable
|
2019-02-15 23:44:43 +01:00
|
|
|
class Services(
|
2019-08-23 01:56:13 +02:00
|
|
|
private val context: Context,
|
2019-06-05 00:57:24 +02:00
|
|
|
private val accountManager: FxaAccountManager
|
2019-02-15 23:44:43 +01:00
|
|
|
) {
|
|
|
|
val accountsAuthFeature by lazy {
|
2020-06-16 20:21:45 +02:00
|
|
|
FirefoxAccountsAuthFeature(accountManager, FxaServer.REDIRECT_URL) { context, authUrl ->
|
2019-08-02 00:40:43 +02:00
|
|
|
CoroutineScope(Dispatchers.Main).launch {
|
|
|
|
val intent = SupportUtils.createAuthCustomTabIntent(context, authUrl)
|
|
|
|
context.startActivity(intent)
|
|
|
|
}
|
|
|
|
}
|
2019-02-15 23:44:43 +01:00
|
|
|
}
|
2019-07-26 04:55:51 +02:00
|
|
|
|
2019-12-20 14:27:19 +01:00
|
|
|
val appLinksInterceptor by lazy {
|
|
|
|
AppLinksInterceptor(
|
|
|
|
context,
|
|
|
|
interceptLinkClicks = true,
|
|
|
|
launchInApp = {
|
2020-01-02 19:08:11 +01:00
|
|
|
PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
|
2019-12-20 14:27:19 +01:00
|
|
|
context.getPreferenceKey(R.string.pref_key_open_links_in_external_app), false)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
2019-02-15 23:44:43 +01:00
|
|
|
}
|