Commit a5e362c4 authored by MozLando's avatar MozLando
Browse files

Merge #7438 #7466



7438: Custom relation checker r=jonalmeida a=NotWoods

Builds off #7436

The Digital Asset Links relation checker is now exposed to the server, so it can be customized. Apps using A-C can choose to use the pre-existing Google API code, or switch to the new local code that fetches with our HTTP client. They can also pass null to turn off this feature.

The API Key and HTTP client properties are now passed directly to the relation checker instance.



7466: Add asEffect helper to browser menu highlight r=psymoon a=NotWoods

Breaking this out from the main menu2 PR.



Co-authored-by: default avatarTiger Oakes <toakes@mozilla.com>
Loading
Loading
Loading
Loading
+24 −2
Original line number Diff line number Diff line
@@ -4,10 +4,15 @@

package mozilla.components.browser.menu

import android.content.Context
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.core.content.ContextCompat
import mozilla.components.browser.menu.item.NO_ID
import mozilla.components.concept.menu.candidate.HighPriorityHighlightEffect
import mozilla.components.concept.menu.candidate.LowPriorityHighlightEffect
import mozilla.components.concept.menu.candidate.MenuEffect

/**
 * Describes how to display a [mozilla.components.browser.menu.item.BrowserMenuHighlightableItem]
@@ -17,6 +22,11 @@ sealed class BrowserMenuHighlight {
    abstract val label: String?
    abstract val canPropagate: Boolean

    /**
     * Converts the highlight into a corresponding [MenuEffect] from concept-menu.
     */
    abstract fun asEffect(context: Context): MenuEffect

    /**
     * Displays a notification dot.
     * Used for highlighting new features to the user, such as what's new or a recommended feature.
@@ -30,7 +40,11 @@ sealed class BrowserMenuHighlight {
        @ColorInt val notificationTint: Int,
        override val label: String? = null,
        override val canPropagate: Boolean = true
    ) : BrowserMenuHighlight()
    ) : BrowserMenuHighlight() {
        override fun asEffect(context: Context) = LowPriorityHighlightEffect(
            notificationTint = notificationTint
        )
    }

    /**
     * Changes the background of the menu item.
@@ -48,7 +62,11 @@ sealed class BrowserMenuHighlight {
        override val label: String? = null,
        val endImageResource: Int = NO_ID,
        override val canPropagate: Boolean = true
    ) : BrowserMenuHighlight()
    ) : BrowserMenuHighlight() {
        override fun asEffect(context: Context) = HighPriorityHighlightEffect(
            backgroundTint = backgroundTint
        )
    }

    /**
     * Described how to display a highlightable menu item when it is highlighted.
@@ -68,6 +86,10 @@ sealed class BrowserMenuHighlight {
        override val canPropagate: Boolean = true
    ) : BrowserMenuHighlight() {
        override val label: String? = null

        override fun asEffect(context: Context) = HighPriorityHighlightEffect(
            backgroundTint = ContextCompat.getColor(context, colorResource)
        )
    }
}

+3 −1
Original line number Diff line number Diff line
@@ -3,6 +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/. -->
<androidx.appcompat.widget.AppCompatCheckBox xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/Mozac.Browser.Menu.Item.Text"
    android:layout_width="match_parent"
    android:layout_height="@dimen/mozac_browser_menu_item_container_layout_height"
@@ -11,4 +12,5 @@
    android:drawablePadding="@dimen/mozac_browser_menu_checkbox_padding"
    android:gravity="center_vertical"
    android:paddingStart="16dp"
    android:paddingEnd="16dp" />
    android:paddingEnd="16dp"
    tools:text="Item" />
+4 −4
Original line number Diff line number Diff line
@@ -8,8 +8,8 @@
    style="@style/Mozac.Browser.Menu.Item.Text"
    android:layout_width="match_parent"
    android:layout_height="@dimen/mozac_browser_menu_item_container_layout_height"
    android:gravity="center_vertical"
    android:textAlignment="viewStart"
    android:paddingEnd="16dp"
    android:gravity="start|center_vertical"
    android:paddingStart="16dp"
    tools:ignore="RtlCompat" />
    android:paddingEnd="16dp"
    android:textAlignment="viewStart"
    tools:text="Item" />
+0 −1
Original line number Diff line number Diff line
@@ -6,6 +6,5 @@
    style="@style/Mozac.Browser.Menu.Item.Text"
    android:layout_width="match_parent"
    android:layout_height="@dimen/mozac_browser_menu_item_container_layout_height"
    android:orientation="vertical"
    android:paddingStart="16dp"
    android:paddingEnd="16dp"/>
+47 −0
Original line number Diff line number Diff line
/* 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.components.browser.menu

import android.graphics.Color
import androidx.test.ext.junit.runners.AndroidJUnit4
import mozilla.components.concept.menu.candidate.HighPriorityHighlightEffect
import mozilla.components.concept.menu.candidate.LowPriorityHighlightEffect
import mozilla.components.support.test.mock
import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class BrowserMenuHighlightTest {

    @Test
    fun `low priority effect keeps notification tint`() {
        val highlight = BrowserMenuHighlight.LowPriority(
            notificationTint = Color.RED
        )
        assertEquals(LowPriorityHighlightEffect(Color.RED), highlight.asEffect(mock()))
    }

    @Test
    fun `high priority effect keeps background tint`() {
        val highlight = BrowserMenuHighlight.HighPriority(
            backgroundTint = Color.RED
        )
        assertEquals(HighPriorityHighlightEffect(Color.RED), highlight.asEffect(mock()))
    }

    @Suppress("Deprecation")
    @Test
    fun `classic highlight effect converts background tint`() {
        val highlight = BrowserMenuHighlight.ClassicHighlight(
            startImageResource = 0,
            endImageResource = 0,
            backgroundResource = 0,
            colorResource = R.color.photonRed50
        )
        assertEquals(HighPriorityHighlightEffect(0xffff0039L.toInt()), highlight.asEffect(testContext))
    }
}
Loading