1
0
Fork 0

Switch to new intent processors

master
Tiger Oakes 2019-07-22 09:49:43 -04:00 committed by Emily Kager
parent 6480f405e2
commit 3c99c8540f
2 changed files with 39 additions and 27 deletions

View File

@ -7,9 +7,9 @@ package org.mozilla.fenix
import android.app.Activity import android.app.Activity
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import mozilla.components.browser.session.tab.CustomTabConfig import kotlinx.coroutines.MainScope
import mozilla.components.support.utils.SafeIntent import kotlinx.coroutines.launch
import org.mozilla.fenix.components.NotificationManager.Companion.RECEIVE_TABS_TAG import org.mozilla.fenix.components.NotificationManager
import org.mozilla.fenix.customtabs.AuthCustomTabActivity import org.mozilla.fenix.customtabs.AuthCustomTabActivity
import org.mozilla.fenix.customtabs.CustomTabActivity import org.mozilla.fenix.customtabs.CustomTabActivity
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
@ -21,31 +21,42 @@ class IntentReceiverActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
// The intent property is nullable, but the rest of the code below
// assumes it is not. If it's null, then we make a new one and open
// the HomeActivity.
val intent = intent?.let { Intent(intent) } ?: Intent()
val isPrivate = Settings.getInstance(this).usePrivateMode val isPrivate = Settings.getInstance(this).usePrivateMode
if (isPrivate) { MainScope().launch {
components.utils.privateIntentProcessor.process(intent) // The intent property is nullable, but the rest of the code below
} else { // assumes it is not. If it's null, then we make a new one and open
components.utils.intentProcessor.process(intent) // the HomeActivity.
} val intent = intent?.let { Intent(intent) } ?: Intent()
val intentProcessors = listOf(
components.utils.customTabIntentProcessor,
if (isPrivate) components.utils.privateIntentProcessor else components.utils.intentProcessor
)
intentProcessors.any { it.process(intent) }
setIntentActivity(intent)
startActivity(intent)
finish()
}
}
private fun setIntentActivity(intent: Intent) {
val openToBrowser = when { val openToBrowser = when {
CustomTabConfig.isCustomTabIntent(SafeIntent(intent)) -> { components.utils.customTabIntentProcessor.matches(intent) -> {
intent.setClassName( val activityClass = if (intent.hasExtra(getString(R.string.intent_extra_auth))) {
applicationContext, AuthCustomTabActivity::class
if (intent.hasExtra(getString(R.string.intent_extra_auth))) AuthCustomTabActivity::class.java.name } else {
else CustomTabActivity::class.java.name CustomTabActivity::class
) }
intent.setClassName(applicationContext, activityClass.java.name)
true true
} }
intent.action == Intent.ACTION_VIEW -> { intent.action == Intent.ACTION_VIEW -> {
intent.setClassName(applicationContext, HomeActivity::class.java.name) intent.setClassName(applicationContext, HomeActivity::class.java.name)
if (!intent.getBooleanExtra(RECEIVE_TABS_TAG, false)) { if (!intent.getBooleanExtra(NotificationManager.RECEIVE_TABS_TAG, false)) {
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
} }
true true
@ -57,9 +68,5 @@ class IntentReceiverActivity : Activity() {
} }
intent.putExtra(HomeActivity.OPEN_TO_BROWSER, openToBrowser) intent.putExtra(HomeActivity.OPEN_TO_BROWSER, openToBrowser)
startActivity(intent)
finish()
} }
} }

View File

@ -6,7 +6,8 @@ package org.mozilla.fenix.components
import android.content.Context import android.content.Context
import mozilla.components.browser.session.SessionManager import mozilla.components.browser.session.SessionManager
import mozilla.components.feature.intent.IntentProcessor import mozilla.components.feature.customtabs.CustomTabIntentProcessor
import mozilla.components.feature.intent.TabIntentProcessor
import mozilla.components.feature.search.SearchUseCases import mozilla.components.feature.search.SearchUseCases
import mozilla.components.feature.session.SessionUseCases import mozilla.components.feature.session.SessionUseCases
import org.mozilla.fenix.test.Mockable import org.mozilla.fenix.test.Mockable
@ -26,11 +27,15 @@ class Utilities(
* and ACTION_SEND intents. * and ACTION_SEND intents.
*/ */
val intentProcessor by lazy { val intentProcessor by lazy {
IntentProcessor(sessionUseCases, sessionManager, searchUseCases, context) TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = false)
} }
val privateIntentProcessor by lazy { val privateIntentProcessor by lazy {
IntentProcessor(sessionUseCases, sessionManager, searchUseCases, context, isPrivate = true) TabIntentProcessor(sessionManager, sessionUseCases.loadUrl, searchUseCases.newTabSearch, isPrivate = true)
}
val customTabIntentProcessor by lazy {
CustomTabIntentProcessor(sessionManager, sessionUseCases.loadUrl, context.resources.displayMetrics)
} }
/** /**