For #336 - allow the browser to intercept the back button
parent
854eb4a2a0
commit
27a56e2974
|
@ -0,0 +1,11 @@
|
|||
package org.mozilla.fenix
|
||||
/* 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/. */
|
||||
|
||||
/**
|
||||
* Interface for fragments that want to handle 'back' button presses.
|
||||
*/
|
||||
interface BackHandler {
|
||||
fun onBackPressed(): Boolean
|
||||
}
|
|
@ -31,4 +31,14 @@ class HomeActivity : AppCompatActivity() {
|
|||
).asView()
|
||||
else -> super.onCreateView(parent, name, context, attrs)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
supportFragmentManager.primaryNavigationFragment?.childFragmentManager?.fragments?.forEach {
|
||||
if (it is BackHandler && it.onBackPressed()) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,8 +27,9 @@ import org.mozilla.fenix.R
|
|||
import org.mozilla.fenix.components.toolbar.ToolbarIntegration
|
||||
import org.mozilla.fenix.ext.requireComponents
|
||||
import mozilla.components.feature.prompts.PromptFeature
|
||||
import org.mozilla.fenix.BackHandler
|
||||
|
||||
class BrowserFragment : Fragment() {
|
||||
class BrowserFragment : Fragment(), BackHandler {
|
||||
|
||||
private lateinit var contextMenuFeature: ContextMenuFeature
|
||||
private lateinit var downloadsFeature: DownloadsFeature
|
||||
|
@ -111,6 +112,14 @@ class BrowserFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
override fun onBackPressed(): Boolean {
|
||||
if (sessionFeature.handleBackPressed()) return true
|
||||
|
||||
// We'll want to improve this when we add multitasking
|
||||
requireComponents.core.sessionManager.remove()
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
|
||||
when (requestCode) {
|
||||
REQUEST_CODE_DOWNLOAD_PERMISSIONS -> downloadsFeature.onPermissionsResult(permissions, grantResults)
|
||||
|
|
|
@ -38,8 +38,8 @@
|
|||
android:label="fragment_browser"
|
||||
tools:layout="@layout/fragment_browser">
|
||||
<action
|
||||
android:id="@+id/action_browserFragment_to_homeFragment"
|
||||
app:destination="@id/homeFragment" />
|
||||
android:id="@+id/action_browserFragment_to_homeFragment"
|
||||
app:destination="@id/homeFragment" app:popUpToInclusive="true" app:popUpTo="@+id/homeFragment"/>
|
||||
<action
|
||||
android:id="@+id/action_browserFragment_to_searchFragment"
|
||||
app:destination="@id/searchFragment" />
|
||||
|
|
Loading…
Reference in New Issue