For #311 - Uses Navigation component for opening the browser
parent
21508f49ca
commit
10495657c5
|
@ -10,24 +10,12 @@ import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import mozilla.components.concept.engine.EngineView
|
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
|
import org.mozilla.fenix.ext.components
|
||||||
|
|
||||||
open class HomeActivity : AppCompatActivity() {
|
open class HomeActivity : AppCompatActivity() {
|
||||||
private var sessionId: String? = null
|
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_home)
|
setContentView(R.layout.activity_home)
|
||||||
|
|
||||||
if (savedInstanceState == null) {
|
|
||||||
sessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
|
|
||||||
supportFragmentManager.beginTransaction()
|
|
||||||
.replace(R.id.container, BrowserFragment.create(sessionId))
|
|
||||||
.commit()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
|
|
|
@ -139,7 +139,6 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
requireComponents.toolbar.menuBuilder
|
requireComponents.toolbar.menuBuilder
|
||||||
) { requireActivity().finish() }
|
) { requireActivity().finish() }
|
||||||
|
|
||||||
|
|
||||||
lifecycle.addObservers(
|
lifecycle.addObservers(
|
||||||
contextMenuFeature,
|
contextMenuFeature,
|
||||||
downloadsFeature,
|
downloadsFeature,
|
||||||
|
@ -164,9 +163,11 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
lifecycle.removeObserver(sessionFeature)
|
lifecycle.removeObserver(sessionFeature)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("ReturnCount")
|
||||||
override fun onBackPressed(): Boolean {
|
override fun onBackPressed(): Boolean {
|
||||||
if (findInPageIntegration.onBackPressed()) return true
|
if (findInPageIntegration.onBackPressed()) return true
|
||||||
if (sessionFeature.handleBackPressed()) return true
|
if (sessionFeature.handleBackPressed()) return true
|
||||||
|
if (customTabsToolbarFeature.onBackPressed()) return true
|
||||||
|
|
||||||
// We'll want to improve this when we add multitasking
|
// We'll want to improve this when we add multitasking
|
||||||
requireComponents.core.sessionManager.remove()
|
requireComponents.core.sessionManager.remove()
|
||||||
|
@ -190,15 +191,9 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SESSION_ID = "session_id"
|
const val SESSION_ID = "session_id"
|
||||||
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
|
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
|
||||||
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
|
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
|
||||||
private const val TOOLBAR_HEIGHT = 56f
|
private const val TOOLBAR_HEIGHT = 56f
|
||||||
|
|
||||||
fun create(sessionId: String? = null): BrowserFragment = BrowserFragment().apply {
|
|
||||||
arguments = Bundle().apply {
|
|
||||||
putString(SESSION_ID, sessionId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,23 @@
|
||||||
|
|
||||||
package org.mozilla.fenix.customtabs
|
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.HomeActivity
|
||||||
|
import org.mozilla.fenix.R
|
||||||
|
import org.mozilla.fenix.browser.BrowserFragment
|
||||||
|
|
||||||
class CustomTabActivity : HomeActivity()
|
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)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -5,6 +5,10 @@
|
||||||
android:id="@+id/nav_graph"
|
android:id="@+id/nav_graph"
|
||||||
app:startDestination="@id/homeFragment">
|
app:startDestination="@id/homeFragment">
|
||||||
|
|
||||||
|
<action
|
||||||
|
android:id="@+id/action_global_browser"
|
||||||
|
app:destination="@id/browserFragment" />
|
||||||
|
|
||||||
<fragment
|
<fragment
|
||||||
android:id="@+id/homeFragment"
|
android:id="@+id/homeFragment"
|
||||||
android:name="org.mozilla.fenix.home.HomeFragment"
|
android:name="org.mozilla.fenix.home.HomeFragment"
|
||||||
|
|
Loading…
Reference in New Issue