1
0
Fork 0

Fixes #389 - Opens the browser when opening from a link

master
Jeff Boek 2019-02-06 14:31:39 -08:00 committed by Colin Lee
parent 623dc55eac
commit 6e31927cc7
3 changed files with 39 additions and 22 deletions

View File

@ -9,13 +9,21 @@ import android.os.Bundle
import android.util.AttributeSet
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.fragment.NavHostFragment
import mozilla.components.concept.engine.EngineView
import mozilla.components.feature.intent.IntentProcessor
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.browser.BrowserFragment
import org.mozilla.fenix.ext.components
open class HomeActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_home)
if (intent?.extras?.getBoolean(OPEN_TO_BROWSER) == true) {
openToBrowser()
}
}
override fun onCreateView(
@ -38,4 +46,17 @@ open class HomeActivity : AppCompatActivity() {
super.onBackPressed()
}
private fun openToBrowser() {
val sessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
val host = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
host.navController.navigate(R.id.action_global_browser, Bundle().apply {
putString(BrowserFragment.SESSION_ID, sessionId)
})
}
companion object {
const val OPEN_TO_BROWSER = "open_to_browser"
}
}

View File

@ -18,15 +18,28 @@ class IntentReceiverActivity : Activity() {
super.onCreate(savedInstanceState)
components.utils.intentProcessor.process(intent)
var openToBrowser = false
val intent = Intent(intent)
if (CustomTabConfig.isCustomTabIntent(SafeIntent(intent))) {
intent.setClassName(applicationContext, CustomTabActivity::class.java.name)
} else {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
openToBrowser = when {
CustomTabConfig.isCustomTabIntent(SafeIntent(intent)) -> {
intent.setClassName(applicationContext, CustomTabActivity::class.java.name)
true
}
intent.action == Intent.ACTION_VIEW -> {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
true
}
else -> {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
false
}
}
intent.putExtra(HomeActivity.OPEN_TO_BROWSER, openToBrowser)
startActivity(intent)
finish()
}
}

View File

@ -4,23 +4,6 @@
package org.mozilla.fenix.customtabs
import android.os.Bundle
import androidx.navigation.fragment.NavHostFragment
import mozilla.components.feature.intent.IntentProcessor
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.R
import org.mozilla.fenix.browser.BrowserFragment
class CustomTabActivity : HomeActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val sessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
val host = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
host.navController.navigate(R.id.action_global_browser, Bundle().apply {
putString(BrowserFragment.SESSION_ID, sessionId)
})
}
}
class CustomTabActivity : HomeActivity()