Skip to content

Commit

Permalink
For mozilla-mobile#311 - Uses Navigation component for opening the br…
Browse files Browse the repository at this point in the history
…owser
  • Loading branch information
boek committed Feb 5, 2019
1 parent b58a36b commit 84e821d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 21 deletions.
12 changes: 0 additions & 12 deletions app/src/main/java/org/mozilla/fenix/HomeActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/java/org/mozilla/fenix/browser/BrowserFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ class BrowserFragment : Fragment(), BackHandler {
requireComponents.toolbar.menuBuilder
) { requireActivity().finish() }


lifecycle.addObservers(
contextMenuFeature,
downloadsFeature,
Expand Down Expand Up @@ -167,6 +166,7 @@ class BrowserFragment : Fragment(), BackHandler {
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()
Expand All @@ -190,15 +190,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)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
}
4 changes: 4 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 84e821d

Please sign in to comment.