1
0
Fork 0

Cleanup shortcut code

master
Tiger Oakes 2019-09-26 10:45:19 -07:00
parent a598148b29
commit e572562c7a
2 changed files with 54 additions and 24 deletions

View File

@ -16,7 +16,7 @@ import mozilla.components.support.utils.Browsers
import org.mozilla.fenix.customtabs.ExternalAppBrowserActivity
import org.mozilla.fenix.ext.components
import org.mozilla.fenix.ext.settings
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
import org.mozilla.fenix.shortcut.NewTabShortcutIntentProcessor
/**
* Processes incoming intents and sends them to the corresponding activity.
@ -58,8 +58,9 @@ class IntentReceiverActivity : Activity() {
components.intentProcessors.intentProcessor
}
val intentProcessors =
components.intentProcessors.externalAppIntentProcessors + tabIntentProcessor
val intentProcessors = components.intentProcessors.externalAppIntentProcessors +
tabIntentProcessor +
NewTabShortcutIntentProcessor()
intentProcessors.any { it.process(intent) }
setIntentActivity(intent, tabIntentProcessor)
@ -86,24 +87,6 @@ class IntentReceiverActivity : Activity() {
// from a session that the user already "erased".
intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY == 0
}
intent.action == ACTION_OPEN_TAB || intent.action == ACTION_OPEN_PRIVATE_TAB -> {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
val startPrivateMode = (intent.action == ACTION_OPEN_PRIVATE_TAB)
if (startPrivateMode) {
intent.putExtra(
HomeActivity.OPEN_TO_SEARCH,
StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_PRIVATE_TAB
)
} else {
intent.putExtra(
HomeActivity.OPEN_TO_SEARCH,
StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_TAB
)
}
intent.putExtra(HomeActivity.PRIVATE_BROWSING_MODE, startPrivateMode)
intent.flags = intent.flags or Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
false
}
else -> {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
false
@ -116,8 +99,5 @@ class IntentReceiverActivity : Activity() {
companion object {
// This constant must match the metadata from the private activity-alias
const val LAUNCH_PRIVATE_LINK = "org.mozilla.fenix.LAUNCH_PRIVATE_LINK"
const val ACTION_OPEN_TAB = "org.mozilla.fenix.OPEN_TAB"
const val ACTION_OPEN_PRIVATE_TAB = "org.mozilla.fenix.OPEN_PRIVATE_TAB"
}
}

View File

@ -0,0 +1,50 @@
/* 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 android.content.Intent
import android.content.Intent.FLAG_ACTIVITY_CLEAR_TASK
import android.content.Intent.FLAG_ACTIVITY_NEW_TASK
import mozilla.components.feature.intent.processing.IntentProcessor
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.home.intent.StartSearchIntentProcessor
class NewTabShortcutIntentProcessor : IntentProcessor {
/**
* Returns true if this intent processor will handle the intent.
*/
override fun matches(intent: Intent): Boolean {
val safeIntent = SafeIntent(intent)
return safeIntent.action == ACTION_OPEN_TAB || safeIntent.action == ACTION_OPEN_PRIVATE_TAB
}
/**
* Processes the given [Intent].
*
* @param intent The intent to process.
* @return True if the intent was processed, otherwise false.
*/
override suspend fun process(intent: Intent): Boolean {
val safeIntent = SafeIntent(intent)
val (searchExtra, startPrivateMode) = when (safeIntent.action) {
ACTION_OPEN_TAB -> StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_TAB to false
ACTION_OPEN_PRIVATE_TAB -> StartSearchIntentProcessor.STATIC_SHORTCUT_NEW_PRIVATE_TAB to true
else -> return false
}
intent.putExtra(HomeActivity.OPEN_TO_SEARCH, searchExtra)
intent.putExtra(HomeActivity.PRIVATE_BROWSING_MODE, startPrivateMode)
intent.flags = intent.flags or FLAG_ACTIVITY_NEW_TASK or FLAG_ACTIVITY_CLEAR_TASK
return true
}
companion object {
const val ACTION_OPEN_TAB = "org.mozilla.fenix.OPEN_TAB"
const val ACTION_OPEN_PRIVATE_TAB = "org.mozilla.fenix.OPEN_PRIVATE_TAB"
}
}