WIP: Integrate feature-customtabs component
parent
e358ea138a
commit
21508f49ca
|
@ -118,6 +118,7 @@ dependencies {
|
||||||
|
|
||||||
implementation Deps.mozilla_feature_awesomebar
|
implementation Deps.mozilla_feature_awesomebar
|
||||||
implementation Deps.mozilla_feature_contextmenu
|
implementation Deps.mozilla_feature_contextmenu
|
||||||
|
implementation Deps.mozilla_feature_customtabs
|
||||||
implementation Deps.mozilla_feature_downloads
|
implementation Deps.mozilla_feature_downloads
|
||||||
implementation Deps.mozilla_feature_intent
|
implementation Deps.mozilla_feature_intent
|
||||||
implementation Deps.mozilla_feature_prompts
|
implementation Deps.mozilla_feature_prompts
|
||||||
|
|
|
@ -25,6 +25,15 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".customtabs.CustomTabActivity"
|
||||||
|
android:configChanges="keyboard|keyboardHidden|mcc|mnc|orientation|screenSize|locale|layoutDirection|smallestScreenSize|screenLayout"
|
||||||
|
android:windowSoftInputMode="adjustResize|stateAlwaysHidden"
|
||||||
|
android:exported="false"
|
||||||
|
android:taskAffinity=""
|
||||||
|
android:persistableMode="persistNever"
|
||||||
|
android:autoRemoveFromRecents="false"
|
||||||
|
android:label="@string/app_name" />
|
||||||
|
|
||||||
<activity android:name=".IntentReceiverActivity">
|
<activity android:name=".IntentReceiverActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
|
@ -47,6 +56,15 @@
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<service
|
||||||
|
android:name=".customtabs.CustomTabsService"
|
||||||
|
android:exported="true"
|
||||||
|
tools:ignore="ExportedService">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.support.customtabs.action.CustomTabsService" />
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".settings.SettingsActivity"
|
android:name=".settings.SettingsActivity"
|
||||||
android:label="@string/settings"
|
android:label="@string/settings"
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package org.mozilla.fenix
|
package org.mozilla.fenix
|
||||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
/* 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
|
* 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/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Interface for fragments that want to handle 'back' button presses.
|
* Interface for fragments that want to handle 'back' button presses.
|
||||||
|
|
|
@ -10,12 +10,24 @@ import android.util.AttributeSet
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import mozilla.components.concept.engine.EngineView
|
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
|
import org.mozilla.fenix.ext.components
|
||||||
|
|
||||||
class HomeActivity : AppCompatActivity() {
|
open class HomeActivity : AppCompatActivity() {
|
||||||
|
private var sessionId: String? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_home)
|
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(
|
override fun onCreateView(
|
||||||
|
@ -25,10 +37,7 @@ class HomeActivity : AppCompatActivity() {
|
||||||
attrs: AttributeSet
|
attrs: AttributeSet
|
||||||
): View? =
|
): View? =
|
||||||
when (name) {
|
when (name) {
|
||||||
EngineView::class.java.name -> components.core.engine.createView(
|
EngineView::class.java.name -> components.core.engine.createView(context, attrs).asView()
|
||||||
context,
|
|
||||||
attrs
|
|
||||||
).asView()
|
|
||||||
else -> super.onCreateView(parent, name, context, attrs)
|
else -> super.onCreateView(parent, name, context, attrs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import mozilla.components.browser.session.tab.CustomTabConfig
|
import mozilla.components.browser.session.tab.CustomTabConfig
|
||||||
import mozilla.components.support.utils.SafeIntent
|
import mozilla.components.support.utils.SafeIntent
|
||||||
|
import org.mozilla.fenix.customtabs.CustomTabActivity
|
||||||
import org.mozilla.fenix.ext.components
|
import org.mozilla.fenix.ext.components
|
||||||
|
|
||||||
class IntentReceiverActivity : Activity() {
|
class IntentReceiverActivity : Activity() {
|
||||||
|
@ -20,7 +21,7 @@ class IntentReceiverActivity : Activity() {
|
||||||
|
|
||||||
val intent = Intent(intent)
|
val intent = Intent(intent)
|
||||||
if (CustomTabConfig.isCustomTabIntent(SafeIntent(intent))) {
|
if (CustomTabConfig.isCustomTabIntent(SafeIntent(intent))) {
|
||||||
// TODO Enter CustomTabActivity here.
|
intent.setClassName(applicationContext, CustomTabActivity::class.java.name)
|
||||||
} else {
|
} else {
|
||||||
intent.setClassName(applicationContext, HomeActivity::class.java.name)
|
intent.setClassName(applicationContext, HomeActivity::class.java.name)
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,6 +23,7 @@ import kotlinx.android.synthetic.main.fragment_browser.view.*
|
||||||
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
|
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
|
||||||
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
import mozilla.components.feature.contextmenu.ContextMenuCandidate
|
||||||
import mozilla.components.feature.contextmenu.ContextMenuFeature
|
import mozilla.components.feature.contextmenu.ContextMenuFeature
|
||||||
|
import mozilla.components.feature.customtabs.CustomTabsToolbarFeature
|
||||||
import mozilla.components.feature.downloads.DownloadsFeature
|
import mozilla.components.feature.downloads.DownloadsFeature
|
||||||
import mozilla.components.feature.session.SessionFeature
|
import mozilla.components.feature.session.SessionFeature
|
||||||
import mozilla.components.feature.session.SessionUseCases
|
import mozilla.components.feature.session.SessionUseCases
|
||||||
|
@ -47,6 +48,7 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
private lateinit var promptsFeature: PromptFeature
|
private lateinit var promptsFeature: PromptFeature
|
||||||
private lateinit var sessionFeature: SessionFeature
|
private lateinit var sessionFeature: SessionFeature
|
||||||
private lateinit var toolbarComponent: ToolbarComponent
|
private lateinit var toolbarComponent: ToolbarComponent
|
||||||
|
private lateinit var customTabsToolbarFeature: CustomTabsToolbarFeature
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
@ -90,6 +92,8 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
val sessionId = arguments?.getString(SESSION_ID)
|
||||||
|
|
||||||
val sessionManager = requireComponents.core.sessionManager
|
val sessionManager = requireComponents.core.sessionManager
|
||||||
|
|
||||||
contextMenuFeature = ContextMenuFeature(
|
contextMenuFeature = ContextMenuFeature(
|
||||||
|
@ -122,18 +126,28 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
sessionFeature = SessionFeature(
|
sessionFeature = SessionFeature(
|
||||||
sessionManager,
|
sessionManager,
|
||||||
SessionUseCases(sessionManager),
|
SessionUseCases(sessionManager),
|
||||||
view.engineView
|
view.engineView,
|
||||||
|
sessionId
|
||||||
)
|
)
|
||||||
|
|
||||||
findInPageIntegration = FindInPageIntegration(requireComponents.core.sessionManager, view.findInPageView)
|
findInPageIntegration = FindInPageIntegration(requireComponents.core.sessionManager, view.findInPageView)
|
||||||
|
|
||||||
|
customTabsToolbarFeature = CustomTabsToolbarFeature(
|
||||||
|
sessionManager,
|
||||||
|
toolbar,
|
||||||
|
sessionId,
|
||||||
|
requireComponents.toolbar.menuBuilder
|
||||||
|
) { requireActivity().finish() }
|
||||||
|
|
||||||
|
|
||||||
lifecycle.addObservers(
|
lifecycle.addObservers(
|
||||||
contextMenuFeature,
|
contextMenuFeature,
|
||||||
downloadsFeature,
|
downloadsFeature,
|
||||||
findInPageIntegration,
|
findInPageIntegration,
|
||||||
promptsFeature,
|
promptsFeature,
|
||||||
sessionFeature,
|
sessionFeature,
|
||||||
(toolbarComponent.uiView as ToolbarUIView).toolbarIntegration
|
(toolbarComponent.uiView as ToolbarUIView).toolbarIntegration,
|
||||||
|
customTabsToolbarFeature
|
||||||
)
|
)
|
||||||
|
|
||||||
getSafeManagedObservable<SearchAction>()
|
getSafeManagedObservable<SearchAction>()
|
||||||
|
@ -176,8 +190,15 @@ class BrowserFragment : Fragment(), BackHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
private const val SESSION_ID = "session_id"
|
||||||
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
|
private const val REQUEST_CODE_DOWNLOAD_PERMISSIONS = 1
|
||||||
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
|
private const val REQUEST_CODE_PROMPT_PERMISSIONS = 2
|
||||||
private const val TOOLBAR_HEIGHT = 56f
|
private const val TOOLBAR_HEIGHT = 56f
|
||||||
|
|
||||||
|
fun create(sessionId: String? = null): BrowserFragment = BrowserFragment().apply {
|
||||||
|
arguments = Bundle().apply {
|
||||||
|
putString(SESSION_ID, sessionId)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,13 +14,7 @@ class Components(private val context: Context) {
|
||||||
val core by lazy { Core(context) }
|
val core by lazy { Core(context) }
|
||||||
val search by lazy { Search(context) }
|
val search by lazy { Search(context) }
|
||||||
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
|
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
|
||||||
val toolbar by lazy {
|
val toolbar by lazy { Toolbar(context, useCases.sessionUseCases, core.sessionManager) }
|
||||||
Toolbar(
|
|
||||||
context,
|
|
||||||
useCases.sessionUseCases,
|
|
||||||
core.sessionManager
|
|
||||||
)
|
|
||||||
}
|
|
||||||
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
|
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
|
||||||
val analytics by lazy { Analytics(context) }
|
val analytics by lazy { Analytics(context) }
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ class Toolbar(
|
||||||
ShippedDomainsProvider().also { it.initialize(context) }
|
ShippedDomainsProvider().also { it.initialize(context) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private val menuToolbar by lazy {
|
val menuToolbar by lazy {
|
||||||
val back = BrowserMenuItemToolbar.Button(
|
val back = BrowserMenuItemToolbar.Button(
|
||||||
mozilla.components.ui.icons.R.drawable.mozac_ic_back,
|
mozilla.components.ui.icons.R.drawable.mozac_ic_back,
|
||||||
iconTintColorResource = R.color.icons,
|
iconTintColorResource = R.color.icons,
|
||||||
|
|
|
@ -10,6 +10,8 @@ import androidx.lifecycle.LifecycleObserver
|
||||||
import androidx.lifecycle.OnLifecycleEvent
|
import androidx.lifecycle.OnLifecycleEvent
|
||||||
import androidx.navigation.Navigation
|
import androidx.navigation.Navigation
|
||||||
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider
|
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider
|
||||||
|
import mozilla.components.browser.session.SessionManager
|
||||||
|
import mozilla.components.browser.session.runWithSession
|
||||||
import mozilla.components.browser.toolbar.BrowserToolbar
|
import mozilla.components.browser.toolbar.BrowserToolbar
|
||||||
import mozilla.components.concept.storage.HistoryStorage
|
import mozilla.components.concept.storage.HistoryStorage
|
||||||
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
|
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
|
||||||
|
@ -23,16 +25,16 @@ class ToolbarIntegration(
|
||||||
toolbar: BrowserToolbar,
|
toolbar: BrowserToolbar,
|
||||||
domainAutocompleteProvider: DomainAutocompleteProvider,
|
domainAutocompleteProvider: DomainAutocompleteProvider,
|
||||||
historyStorage: HistoryStorage,
|
historyStorage: HistoryStorage,
|
||||||
|
sessionManager: SessionManager,
|
||||||
sessionId: String? = null
|
sessionId: String? = null
|
||||||
) : LifecycleObserver {
|
) : LifecycleObserver {
|
||||||
init {
|
init {
|
||||||
toolbar.setMenuBuilder(context.components.toolbar.menuBuilder)
|
toolbar.setMenuBuilder(context.components.toolbar.menuBuilder)
|
||||||
|
|
||||||
val home = BrowserToolbar.Button(
|
val home = BrowserToolbar.Button(
|
||||||
context.resources.getDrawable(
|
context.resources.getDrawable(R.drawable.ic_home, context.application.theme),
|
||||||
R.drawable.ic_home,
|
context.getString(R.string.browser_home_button),
|
||||||
context.application.theme
|
visible = { sessionManager.runWithSession(sessionId) { it.isCustomTabSession().not() } }
|
||||||
), context.getString(R.string.browser_home_button)
|
|
||||||
) {
|
) {
|
||||||
Navigation.findNavController(toolbar).navigate(R.id.action_browserFragment_to_homeFragment)
|
Navigation.findNavController(toolbar).navigate(R.id.action_browserFragment_to_homeFragment)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
/* 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/. */
|
||||||
|
|
||||||
|
package org.mozilla.fenix.customtabs
|
||||||
|
|
||||||
|
import org.mozilla.fenix.HomeActivity
|
||||||
|
|
||||||
|
class CustomTabActivity : HomeActivity()
|
|
@ -0,0 +1,15 @@
|
||||||
|
/*
|
||||||
|
* 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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.mozilla.fenix.customtabs
|
||||||
|
|
||||||
|
import mozilla.components.concept.engine.Engine
|
||||||
|
import mozilla.components.feature.customtabs.AbstractCustomTabsService
|
||||||
|
import org.mozilla.fenix.ext.components
|
||||||
|
|
||||||
|
class CustomTabsService : AbstractCustomTabsService() {
|
||||||
|
override val engine: Engine by lazy { applicationContext.components.core.engine }
|
||||||
|
}
|
|
@ -66,7 +66,8 @@ class ToolbarUIView(
|
||||||
this,
|
this,
|
||||||
view,
|
view,
|
||||||
ShippedDomainsProvider().also { it.initialize(this) },
|
ShippedDomainsProvider().also { it.initialize(this) },
|
||||||
components.core.historyStorage
|
components.core.historyStorage,
|
||||||
|
components.core.sessionManager
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,6 +46,7 @@
|
||||||
<action
|
<action
|
||||||
android:id="@+id/action_browserFragment_to_settingsActivity"
|
android:id="@+id/action_browserFragment_to_settingsActivity"
|
||||||
app:destination="@id/settingsActivity" />
|
app:destination="@id/settingsActivity" />
|
||||||
|
<argument android:name="session_id" app:argType="string" app:nullable="true" android:defaultValue="null"/>
|
||||||
</fragment>
|
</fragment>
|
||||||
<activity
|
<activity
|
||||||
android:id="@+id/settingsActivity"
|
android:id="@+id/settingsActivity"
|
||||||
|
|
Loading…
Reference in New Issue