2019-01-09 23:22:58 +01:00
|
|
|
/* 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/. */
|
|
|
|
|
2018-12-07 21:11:50 +01:00
|
|
|
package org.mozilla.fenix
|
|
|
|
|
2019-02-13 01:17:08 +01:00
|
|
|
import android.app.Activity
|
2019-01-19 00:33:40 +01:00
|
|
|
import android.content.Context
|
2018-12-07 21:11:50 +01:00
|
|
|
import android.os.Bundle
|
2019-01-19 00:33:40 +01:00
|
|
|
import android.util.AttributeSet
|
|
|
|
import android.view.View
|
2019-02-13 01:17:08 +01:00
|
|
|
import android.view.inputmethod.InputMethodManager
|
2019-01-07 22:47:47 +01:00
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.appcompat.widget.Toolbar
|
2019-02-06 23:31:39 +01:00
|
|
|
import androidx.navigation.fragment.NavHostFragment
|
2019-02-08 00:37:52 +01:00
|
|
|
import androidx.navigation.ui.AppBarConfiguration
|
|
|
|
import androidx.navigation.ui.NavigationUI
|
2019-01-19 00:33:40 +01:00
|
|
|
import mozilla.components.concept.engine.EngineView
|
2019-02-06 23:31:39 +01:00
|
|
|
import mozilla.components.feature.intent.IntentProcessor
|
2019-02-08 13:50:22 +01:00
|
|
|
import mozilla.components.support.base.feature.BackHandler
|
2019-02-06 23:31:39 +01:00
|
|
|
import mozilla.components.support.utils.SafeIntent
|
2019-01-23 22:39:53 +01:00
|
|
|
import org.mozilla.fenix.ext.components
|
2018-12-07 21:11:50 +01:00
|
|
|
|
2019-01-31 18:58:52 +01:00
|
|
|
open class HomeActivity : AppCompatActivity() {
|
2019-02-08 18:43:17 +01:00
|
|
|
val themeManager = DefaultThemeManager().also {
|
|
|
|
it.onThemeChange = { theme ->
|
|
|
|
setTheme(theme)
|
|
|
|
recreate()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-15 18:31:03 +01:00
|
|
|
lateinit var browsingModeManager: DefaultBrowsingModeManager
|
|
|
|
|
2018-12-07 21:11:50 +01:00
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2019-02-15 18:31:03 +01:00
|
|
|
browsingModeManager = DefaultBrowsingModeManager(this)
|
|
|
|
|
2018-12-07 21:11:50 +01:00
|
|
|
setContentView(R.layout.activity_home)
|
2019-02-06 23:31:39 +01:00
|
|
|
|
2019-02-08 18:43:17 +01:00
|
|
|
setTheme(themeManager.currentTheme)
|
|
|
|
DefaultThemeManager.applyStatusBarTheme(window, themeManager, this)
|
|
|
|
|
2019-02-06 23:31:39 +01:00
|
|
|
if (intent?.extras?.getBoolean(OPEN_TO_BROWSER) == true) {
|
|
|
|
openToBrowser()
|
|
|
|
}
|
2019-02-08 00:37:52 +01:00
|
|
|
|
|
|
|
val host = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
|
|
|
|
val hostNavController = host.navController
|
|
|
|
val appBarConfiguration = AppBarConfiguration.Builder(setOf(R.id.libraryFragment)).build()
|
|
|
|
val navigationToolbar = findViewById<Toolbar>(R.id.navigationToolbar)
|
|
|
|
setSupportActionBar(navigationToolbar)
|
|
|
|
NavigationUI.setupWithNavController(navigationToolbar, hostNavController, appBarConfiguration)
|
2018-12-07 21:11:50 +01:00
|
|
|
}
|
2019-01-19 00:33:40 +01:00
|
|
|
|
2019-01-31 20:33:56 +01:00
|
|
|
override fun onCreateView(
|
|
|
|
parent: View?,
|
|
|
|
name: String,
|
|
|
|
context: Context,
|
|
|
|
attrs: AttributeSet
|
|
|
|
): View? =
|
2019-01-19 00:33:40 +01:00
|
|
|
when (name) {
|
2019-01-31 18:58:52 +01:00
|
|
|
EngineView::class.java.name -> components.core.engine.createView(context, attrs).asView()
|
2019-01-19 00:33:40 +01:00
|
|
|
else -> super.onCreateView(parent, name, context, attrs)
|
|
|
|
}
|
2019-02-01 06:52:26 +01:00
|
|
|
|
|
|
|
override fun onBackPressed() {
|
|
|
|
supportFragmentManager.primaryNavigationFragment?.childFragmentManager?.fragments?.forEach {
|
|
|
|
if (it is BackHandler && it.onBackPressed()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.onBackPressed()
|
|
|
|
}
|
2019-02-06 23:31:39 +01:00
|
|
|
|
2019-02-13 01:17:08 +01:00
|
|
|
override fun onPause() {
|
|
|
|
super.onPause()
|
|
|
|
hideSoftwareKeyboard()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun hideSoftwareKeyboard() {
|
|
|
|
(getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager).apply {
|
|
|
|
currentFocus?.also {
|
|
|
|
this.hideSoftInputFromWindow(it.windowToken, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-06 23:31:39 +01:00
|
|
|
private fun openToBrowser() {
|
|
|
|
val sessionId = SafeIntent(intent).getStringExtra(IntentProcessor.ACTIVE_SESSION_ID)
|
|
|
|
val host = supportFragmentManager.findFragmentById(R.id.container) as NavHostFragment
|
2019-02-15 18:31:03 +01:00
|
|
|
val directions = NavGraphDirections.actionGlobalBrowser(sessionId, browsingModeManager.isPrivate)
|
2019-02-08 19:35:48 +01:00
|
|
|
host.navController.navigate(directions)
|
2019-02-06 23:31:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
const val OPEN_TO_BROWSER = "open_to_browser"
|
|
|
|
}
|
2018-12-07 21:11:50 +01:00
|
|
|
}
|