Issue #35: Integrate "engine" component.

Sebastian Kaspari 6 years ago
parent 5392c3aa11
commit 6338501222

@ -68,6 +68,15 @@ repositories {
dependencies {
implementation "io.sentry:sentry-android:${rootProject.ext.dependencies['sentry']}"
implementation "org.mozilla.components:engine:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:engine-gecko:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:session:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:abstract-toolbar:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:toolbar:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:feature-session:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:feature-toolbar:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:ktx:${rootProject.ext.dependencies['mozillaComponents']}"
armImplementation "org.mozilla:geckoview-nightly-armeabi-v7a:${rootProject.ext.gecko['version']}"
x86Implementation "org.mozilla:geckoview-nightly-x86:${rootProject.ext.gecko['version']}"
aarch64Implementation "org.mozilla:geckoview-nightly-arm64-v8a:${rootProject.ext.gecko['version']}"

@ -7,8 +7,11 @@ package mozilla.fenix
import android.app.Application
import io.sentry.Sentry
import io.sentry.android.AndroidSentryClientFactory
import mozilla.fenix.components.Components
class FenixApplication : Application() {
val components by lazy { Components(this) }
override fun onCreate() {
super.onCreate()

@ -4,13 +4,34 @@
package mozilla.fenix
import android.content.Context
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.util.AttributeSet
import android.view.View
import kotlinx.android.synthetic.main.activity_main.*
import mozilla.components.concept.engine.EngineView
import mozilla.components.feature.session.SessionFeature
import mozilla.fenix.components.FeatureLifecycleObserver
import mozilla.fenix.ext.components
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val sessionFeature = SessionFeature(components.sessionManager, components.sessionUseCases,
components.engine, engineView, components.sessionMapping)
lifecycle.addObserver(FeatureLifecycleObserver(sessionFeature))
}
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()
}
return super.onCreateView(parent, name, context, attrs)
}
}

@ -0,0 +1,33 @@
/* 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 mozilla.fenix.components
import android.content.Context
import mozilla.components.browser.engine.gecko.GeckoEngine
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.SessionProvider
import mozilla.components.concept.engine.Engine
import mozilla.components.feature.session.SessionMapping
import mozilla.components.feature.session.SessionUseCases
import mozilla.fenix.components.session.DefaultSessionProvider
import org.mozilla.geckoview.GeckoRuntime
import org.mozilla.geckoview.GeckoRuntimeSettings
/**
* Helper class for lazily instantiating components needed by the application.
*/
class Components(private val applicationContext: Context) {
private val geckoRuntime by lazy {
val settings = GeckoRuntimeSettings()
GeckoRuntime.create(applicationContext, settings)
}
val engine : Engine by lazy { GeckoEngine(geckoRuntime) }
private val sessionProvider: SessionProvider by lazy { DefaultSessionProvider() }
val sessionManager by lazy { SessionManager(sessionProvider) }
val sessionMapping by lazy { SessionMapping() }
val sessionUseCases by lazy { SessionUseCases(sessionManager, engine, sessionMapping) }
}

@ -0,0 +1,27 @@
/* 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 mozilla.fenix.components
import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.OnLifecycleEvent
import mozilla.components.feature.session.SessionFeature
/**
* LifecycleObserver implementation that will forward lifecycle callbacks to "feature" components.
*/
class FeatureLifecycleObserver(
private val sessionFeature: SessionFeature
): LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun startFeatures() {
sessionFeature.start()
}
@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun stopFeatures() {
sessionFeature.stop()
}
}

@ -0,0 +1,16 @@
/* 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 mozilla.fenix.components.session
import mozilla.components.browser.session.Session
import mozilla.components.browser.session.SessionProvider
class DefaultSessionProvider: SessionProvider {
override fun getInitialSessions(): Pair<List<Session>, Int> {
// For now we start with a very simple session provider that will always start with a session
// that contains mozilla.org.
return Pair(listOf(Session("https://www.mozilla.org")), 0)
}
}

@ -0,0 +1,21 @@
/* 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 mozilla.fenix.ext
import android.content.Context
import mozilla.fenix.components.Components
import mozilla.fenix.FenixApplication
/**
* Get the FenixApplication object from a context.
*/
val Context.application: FenixApplication
get() = applicationContext as FenixApplication
/**
* Get the components of this application.
*/
val Context.components: Components
get() = application.components

@ -2,24 +2,17 @@
<!-- 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/. -->
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<mozilla.components.concept.engine.EngineView
android:id="@+id/engineView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</android.support.constraint.ConstraintLayout>
</LinearLayout>

@ -7,9 +7,11 @@ buildscript {
kotlin: '1.2.40',
sentry: '1.7.3',
supportLibraries: '27.1.1',
junit: '4.12',
constraintLayout: '1.1.0',
mozillaComponents: '0.5'
// Testing
junit: '4.12',
// Mozilla
mozillaComponents: '0.5.1'
]
ext.gecko = [

Loading…
Cancel
Save