Skip to content

Commit

Permalink
Issue mozilla-mobile#35: Integrate "browser-toolbar" component.
Browse files Browse the repository at this point in the history
  • Loading branch information
pocmo committed May 3, 2018
1 parent 546b2cd commit 8495b38
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 6 deletions.
11 changes: 11 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ android {
}

repositories {
maven {
// Temporary solution until all required packages are on JCenter
url "https://dl.bintray.com/pocmo/Mozilla-Mobile/"
}

// GeckoView ARM
maven {
url "https://index.taskcluster.net/v1/task/gecko.v2.mozilla-central.nightly.${rootProject.ext.gecko['nightlyDate']}.revision.${rootProject.ext.gecko['revision']}.mobile.android-api-16-opt/artifacts/public/android/maven"
Expand All @@ -75,8 +80,14 @@ dependencies {
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:autocomplete:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.components:ktx:${rootProject.ext.dependencies['mozillaComponents']}"

implementation "org.mozilla.photon:colors:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.photon:icons:${rootProject.ext.dependencies['mozillaComponents']}"
implementation "org.mozilla.photon:progress:${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']}"
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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/. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="mozilla.fenix">

Expand Down
16 changes: 13 additions & 3 deletions app/src/main/java/mozilla/fenix/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ 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.components.feature.toolbar.ToolbarFeature
import mozilla.fenix.components.FeatureLifecycleObserver
import mozilla.fenix.ext.components

Expand All @@ -21,10 +22,19 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val sessionFeature = SessionFeature(components.sessionManager, components.sessionUseCases,
components.engine, engineView, components.sessionMapping)
val toolbarFeature = ToolbarFeature(
components.sessionManager,
components.sessionUseCases.loadUrl,
toolbar)

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

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

override fun onCreateView(parent: View?, name: String?, context: Context?, attrs: AttributeSet?): View? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,24 @@ import android.arch.lifecycle.Lifecycle
import android.arch.lifecycle.LifecycleObserver
import android.arch.lifecycle.OnLifecycleEvent
import mozilla.components.feature.session.SessionFeature
import mozilla.components.feature.toolbar.ToolbarFeature

/**
* LifecycleObserver implementation that will forward lifecycle callbacks to "feature" components.
*/
class FeatureLifecycleObserver(
private val sessionFeature: SessionFeature
private val sessionFeature: SessionFeature,
private val toolbarFeature: ToolbarFeature
): LifecycleObserver {
@OnLifecycleEvent(Lifecycle.Event.ON_START)
fun startFeatures() {
sessionFeature.start()
toolbarFeature.start()
}

@OnLifecycleEvent(Lifecycle.Event.ON_STOP)
fun stopFeatures() {
sessionFeature.stop()
toolbarFeature.stop()
}
}
}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
android:orientation="vertical"
tools:context=".MainActivity">

<mozilla.components.browser.toolbar.BrowserToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary" />

<mozilla.components.concept.engine.EngineView
android:id="@+id/engineView"
android:layout_width="match_parent"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
- 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/. -->
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
Expand Down

0 comments on commit 8495b38

Please sign in to comment.