For #311 - Uses Navigation component for opening the browser
This commit is contained in:
parent
21508f49ca
commit
10495657c5
|
@ -10,24 +10,12 @@ import android.util.AttributeSet
|
|||
import android.view.View
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
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() {
|
||||
private var sessionId: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
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(
|
||||
|
|
|
@ -139,7 +139,6 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
requireComponents.toolbar.menuBuilder
|
||||
) { requireActivity().finish() }
|
||||
|
||||
|
||||
lifecycle.addObservers(
|
||||
contextMenuFeature,
|
||||
downloadsFeature,
|
||||
|
@ -164,9 +163,11 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
lifecycle.removeObserver(sessionFeature)
|
||||
}
|
||||
|
||||
@SuppressWarnings("ReturnCount")
|
||||
override fun onBackPressed(): Boolean {
|
||||
if (findInPageIntegration.onBackPressed()) return true
|
||||
if (sessionFeature.handleBackPressed()) return true
|
||||
if (customTabsToolbarFeature.onBackPressed()) return true
|
||||
|
||||
// We'll want to improve this when we add multitasking
|
||||
requireComponents.core.sessionManager.remove()
|
||||
|
@ -190,15 +191,9 @@ class BrowserFragment : Fragment(), BackHandler {
|
|||
}
|
||||
|
||||
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_PROMPT_PERMISSIONS = 2
|
||||
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
|
||||
|
||||
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()
|
||||
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"
|
||||
app:startDestination="@id/homeFragment">
|
||||
|
||||
<action
|
||||
android:id="@+id/action_global_browser"
|
||||
app:destination="@id/browserFragment" />
|
||||
|
||||
<fragment
|
||||
android:id="@+id/homeFragment"
|
||||
android:name="org.mozilla.fenix.home.HomeFragment"
|
||||
|
|
Loading…
Reference in New Issue
Block a user