Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Adds Lottie Animated Drawable to TP as POC
Browse files Browse the repository at this point in the history
  • Loading branch information
ekager committed Jul 30, 2019
1 parent fca21fd commit 6a2ad67
Show file tree
Hide file tree
Showing 10 changed files with 4,786 additions and 54 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,8 @@ dependencies {

implementation Deps.autodispose

implementation Deps.lottie

implementation Deps.adjust
implementation Deps.installreferrer // Required by Adjust

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@
package org.mozilla.fenix.components.toolbar

import android.content.Context
import android.graphics.drawable.Animatable
import android.graphics.drawable.Drawable
import android.view.ViewGroup
import androidx.navigation.NavOptions
import androidx.navigation.Navigation
import com.airbnb.lottie.LottieCompositionFactory
import com.airbnb.lottie.LottieDrawable
import mozilla.components.browser.domains.autocomplete.DomainAutocompleteProvider
import mozilla.components.browser.session.SessionManager
import mozilla.components.browser.session.runWithSession
Expand Down Expand Up @@ -38,6 +42,7 @@ class ToolbarIntegration(
) : LifecycleAwareFeature {

private var renderStyle: ToolbarFeature.RenderStyle = ToolbarFeature.RenderStyle.UncoloredUrl
private lateinit var trackingProtectionAction: BrowserToolbar.Button

init {
toolbar.setMenuBuilder(toolbarMenu.menuBuilder)
Expand All @@ -52,6 +57,24 @@ class ToolbarIntegration(
return@run
}

val task = LottieCompositionFactory
.fromRawRes(
context,
ThemeManager.resolveAttribute(R.attr.shieldLottieFile, context)
)
task.addListener { result ->
val lottieDrawable = LottieDrawable()
lottieDrawable.composition = result
trackingProtectionAction = BrowserToolbar.Button(
(lottieDrawable as? Drawable)
?: context.getDrawable(R.drawable.ic_tracking_protection)!!,
context.getString(R.string.tracking_protection_on)
) {
animateTP()
}
toolbar.addBrowserAction(trackingProtectionAction)
}

val tabsAction = TabCounterToolbarButton(
sessionManager,
{
Expand Down Expand Up @@ -97,6 +120,12 @@ class ToolbarIntegration(
}
}

private fun animateTP() {
if (trackingProtectionAction.imageDrawable is Animatable) {
(trackingProtectionAction.imageDrawable as Animatable).start()
}
}

private val toolbarPresenter: ToolbarPresenter = ToolbarPresenter(
toolbar,
context.components.core.sessionManager,
Expand All @@ -106,7 +135,8 @@ class ToolbarIntegration(
ThemeManager.resolveAttribute(R.attr.primaryText, context), renderStyle = renderStyle
)
)
private var menuPresenter = MenuPresenter(toolbar, context.components.core.sessionManager, sessionId)
private var menuPresenter =
MenuPresenter(toolbar, context.components.core.sessionManager, sessionId)

override fun start() {
menuPresenter.start()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class QuickSettingsUIView(
private val blockedByAndroidPhoneFeatures = mutableListOf<PhoneFeature>()
private inline val context get() = view.context
private val settings: Settings = Settings.getInstance(context)
private val trackingProtectionSettingView = TrackingProtectionSettingView(view, actionEmitter)
private val labelAndActions = mapOf(
CAMERA to findLabelActionPair(R.id.camera_icon, R.id.camera_action_label),
LOCATION to findLabelActionPair(R.id.location_icon, R.id.location_action_label),
Expand Down

This file was deleted.

Loading

0 comments on commit 6a2ad67

Please sign in to comment.