1
0
Fork 0

WIP: Integrate feature-customtabs component

master
Jonathan Almeida 2019-01-31 12:58:52 -05:00 committed by Jeff Boek
parent e358ea138a
commit 21508f49ca
13 changed files with 95 additions and 22 deletions

View File

@ -118,6 +118,7 @@ dependencies {
implementation Deps.mozilla_feature_awesomebar
implementation Deps.mozilla_feature_contextmenu
implementation Deps.mozilla_feature_customtabs
implementation Deps.mozilla_feature_downloads
implementation Deps.mozilla_feature_intent
implementation Deps.mozilla_feature_prompts

View File

@ -25,6 +25,15 @@
</intent-filter>
</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">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
@ -47,6 +56,15 @@
</intent-filter>
</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
android:name=".settings.SettingsActivity"
android:label="@string/settings"

View File

@ -1,7 +1,8 @@
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/. */
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
/**
* Interface for fragments that want to handle 'back' button presses.

View File

@ -10,12 +10,24 @@ 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
class HomeActivity : AppCompatActivity() {
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(
@ -25,10 +37,7 @@ class HomeActivity : AppCompatActivity() {
attrs: AttributeSet
): View? =
when (name) {
EngineView::class.java.name -> components.core.engine.createView(
context,
attrs
).asView()
EngineView::class.java.name -> components.core.engine.createView(context, attrs).asView()
else -> super.onCreateView(parent, name, context, attrs)
}

View File

@ -9,6 +9,7 @@ import android.content.Intent
import android.os.Bundle
import mozilla.components.browser.session.tab.CustomTabConfig
import mozilla.components.support.utils.SafeIntent
import org.mozilla.fenix.customtabs.CustomTabActivity
import org.mozilla.fenix.ext.components
class IntentReceiverActivity : Activity() {
@ -20,7 +21,7 @@ class IntentReceiverActivity : Activity() {
val intent = Intent(intent)
if (CustomTabConfig.isCustomTabIntent(SafeIntent(intent))) {
// TODO Enter CustomTabActivity here.
intent.setClassName(applicationContext, CustomTabActivity::class.java.name)
} else {
intent.setClassName(applicationContext, HomeActivity::class.java.name)
}

View File

@ -23,6 +23,7 @@ import kotlinx.android.synthetic.main.fragment_browser.view.*
import mozilla.components.browser.toolbar.behavior.BrowserToolbarBottomBehavior
import mozilla.components.feature.contextmenu.ContextMenuCandidate
import mozilla.components.feature.contextmenu.ContextMenuFeature
import mozilla.components.feature.customtabs.CustomTabsToolbarFeature
import mozilla.components.feature.downloads.DownloadsFeature
import mozilla.components.feature.session.SessionFeature
import mozilla.components.feature.session.SessionUseCases
@ -47,6 +48,7 @@ class BrowserFragment : Fragment(), BackHandler {
private lateinit var promptsFeature: PromptFeature
private lateinit var sessionFeature: SessionFeature
private lateinit var toolbarComponent: ToolbarComponent
private lateinit var customTabsToolbarFeature: CustomTabsToolbarFeature
override fun onCreateView(
inflater: LayoutInflater,
@ -90,6 +92,8 @@ class BrowserFragment : Fragment(), BackHandler {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
val sessionId = arguments?.getString(SESSION_ID)
val sessionManager = requireComponents.core.sessionManager
contextMenuFeature = ContextMenuFeature(
@ -122,18 +126,28 @@ class BrowserFragment : Fragment(), BackHandler {
sessionFeature = SessionFeature(
sessionManager,
SessionUseCases(sessionManager),
view.engineView
view.engineView,
sessionId
)
findInPageIntegration = FindInPageIntegration(requireComponents.core.sessionManager, view.findInPageView)
customTabsToolbarFeature = CustomTabsToolbarFeature(
sessionManager,
toolbar,
sessionId,
requireComponents.toolbar.menuBuilder
) { requireActivity().finish() }
lifecycle.addObservers(
contextMenuFeature,
downloadsFeature,
findInPageIntegration,
promptsFeature,
sessionFeature,
(toolbarComponent.uiView as ToolbarUIView).toolbarIntegration
(toolbarComponent.uiView as ToolbarUIView).toolbarIntegration,
customTabsToolbarFeature
)
getSafeManagedObservable<SearchAction>()
@ -176,8 +190,15 @@ class BrowserFragment : Fragment(), BackHandler {
}
companion object {
private 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)
}
}
}
}

View File

@ -14,13 +14,7 @@ class Components(private val context: Context) {
val core by lazy { Core(context) }
val search by lazy { Search(context) }
val useCases by lazy { UseCases(context, core.sessionManager, search.searchEngineManager) }
val toolbar by lazy {
Toolbar(
context,
useCases.sessionUseCases,
core.sessionManager
)
}
val toolbar by lazy { Toolbar(context, useCases.sessionUseCases, core.sessionManager) }
val utils by lazy { Utilities(context, core.sessionManager, useCases.sessionUseCases, useCases.searchUseCases) }
val analytics by lazy { Analytics(context) }
}

View File

@ -40,7 +40,7 @@ class Toolbar(
ShippedDomainsProvider().also { it.initialize(context) }
}
private val menuToolbar by lazy {
val menuToolbar by lazy {
val back = BrowserMenuItemToolbar.Button(
mozilla.components.ui.icons.R.drawable.mozac_ic_back,
iconTintColorResource = R.color.icons,

View File

@ -10,6 +10,8 @@ import androidx.lifecycle.LifecycleObserver
import androidx.lifecycle.OnLifecycleEvent
import androidx.navigation.Navigation
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.concept.storage.HistoryStorage
import mozilla.components.feature.toolbar.ToolbarAutocompleteFeature
@ -23,16 +25,16 @@ class ToolbarIntegration(
toolbar: BrowserToolbar,
domainAutocompleteProvider: DomainAutocompleteProvider,
historyStorage: HistoryStorage,
sessionManager: SessionManager,
sessionId: String? = null
) : LifecycleObserver {
init {
toolbar.setMenuBuilder(context.components.toolbar.menuBuilder)
val home = BrowserToolbar.Button(
context.resources.getDrawable(
R.drawable.ic_home,
context.application.theme
), context.getString(R.string.browser_home_button)
context.resources.getDrawable(R.drawable.ic_home, context.application.theme),
context.getString(R.string.browser_home_button),
visible = { sessionManager.runWithSession(sessionId) { it.isCustomTabSession().not() } }
) {
Navigation.findNavController(toolbar).navigate(R.id.action_browserFragment_to_homeFragment)
}

View File

@ -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()

View File

@ -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 }
}

View File

@ -66,7 +66,8 @@ class ToolbarUIView(
this,
view,
ShippedDomainsProvider().also { it.initialize(this) },
components.core.historyStorage
components.core.historyStorage,
components.core.sessionManager
)
}
}

View File

@ -46,6 +46,7 @@
<action
android:id="@+id/action_browserFragment_to_settingsActivity"
app:destination="@id/settingsActivity" />
<argument android:name="session_id" app:argType="string" app:nullable="true" android:defaultValue="null"/>
</fragment>
<activity
android:id="@+id/settingsActivity"