Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Issue #35: Handle device back button #38

Merged
merged 1 commit into from
May 4, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions app/src/main/java/mozilla/fenix/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,38 @@ import mozilla.fenix.components.FeatureLifecycleObserver
import mozilla.fenix.ext.components

class MainActivity : AppCompatActivity() {
private lateinit var toolbarFeature: ToolbarFeature
private lateinit var sessionFeature: SessionFeature

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val toolbarFeature = ToolbarFeature(
components.sessionManager,
components.sessionUseCases.loadUrl,
toolbar)
toolbarFeature = ToolbarFeature(
components.sessionManager,
components.sessionUseCases.loadUrl,
toolbar)

val sessionFeature = SessionFeature(
components.sessionManager,
components.sessionUseCases,
components.engine,
engineView,
components.sessionMapping)
sessionFeature = SessionFeature(
components.sessionManager,
components.sessionUseCases,
components.engine,
engineView,
components.sessionMapping)

lifecycle.addObserver(FeatureLifecycleObserver(sessionFeature, toolbarFeature))
}

override fun onBackPressed() {
if (toolbarFeature.handleBackPressed())
return

if (sessionFeature.handleBackPressed())
return

super.onBackPressed()
}

override fun onCreateView(parent: View?, name: String?, context: Context?, attrs: AttributeSet?): View? {
if (name == EngineView::class.java.name) {
return components.engine.createView(context!!, attrs).asView()
Expand Down