Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Latest commit

 

History

History
67 lines (48 loc) · 3.25 KB

File metadata and controls

67 lines (48 loc) · 3.25 KB

Android Components > Feature > Session

A component that connects an (concept) engine implementation with the browser session module. A HistoryTrackingDelegate implementation is also provided, which allows tying together an engine implementation with a storage module.

Usage

Setting up the dependency

Use Gradle to download the library from maven.mozilla.org (Setup repository):

implementation "org.mozilla.components:feature-session:{latest-version}"

SwipeRefreshFeature

Sample code can be found in Sample Browser app.

Class to add pull to refresh functionality to browsers. You should pass it a reference to a SwipeRefreshLayout and the SessionManager.

Your layout should have a SwipeRefreshLayout with an EngineView as its only child view.

<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <mozilla.components.concept.engine.EngineView
        android:id="@+id/engineView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

In your fragment code, use SwipeRefreshFeature to connect the SwipeRefreshLayout with your SessionManager and ReloadUrlUseCase.

    val feature = BrowserSwipeRefresh(sessionManager, sessionUseCases.reload, swipeRefreshLayout)
    lifecycle.addObserver(feature)

SwipeRefreshFeature provides its own SwipeRefreshLayout.OnChildScrollUpCallback and SwipeRefreshLayout.OnRefreshListener implementations that you should not override.

ThumbnailsFeature

Feature implementation for automatically taking thumbnails of sites. The feature will take a screenshot when the page finishes loading, and will add it to the Session.thumbnail property.

    val feature = ThumbnailsFeature(context, engineView, sessionManager)
    lifecycle.addObserver(feature)

If the OS is under low memory conditions, the screenshot will be not taken. Ideally, this should be used in conjunction with SessionManager.onLowMemory to allow free up some Session.thumbnail from memory.

// Wherever you implement ComponentCallbacks2
 override fun onTrimMemory(level: Int) {
     sessionManager.onLowMemory()
 }

License

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/