Commit 8357fe93 authored by Tiger Oakes's avatar Tiger Oakes
Browse files

Add NestedMenuCandidate concept item

parent 552b63f5
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@

package mozilla.components.browser.menu.ext

import android.content.Context
import mozilla.components.browser.menu.BrowserMenuHighlight
import mozilla.components.browser.menu.BrowserMenuItem
import mozilla.components.browser.menu.HighlightableMenuItem
@@ -26,3 +27,9 @@ fun List<BrowserMenuItem>.getHighlight() = asSequence()
            is BrowserMenuHighlight.ClassicHighlight -> 0
        }
    }

/**
 * Converts the menu items into a menu candidate list.
 */
fun List<BrowserMenuItem>.asCandidateList(context: Context) =
    mapNotNull { it.asCandidate(context) }
+15 −0
Original line number Diff line number Diff line
@@ -4,10 +4,13 @@

package mozilla.components.browser.menu.item

import android.content.Context
import android.view.View
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import mozilla.components.browser.menu.BrowserMenu
import mozilla.components.concept.menu.candidate.NestedMenuCandidate
import mozilla.components.concept.menu.candidate.TextMenuCandidate

/**
 * A back press menu item for a nested sub menu entry.
@@ -42,4 +45,16 @@ class BackPressMenuItem(
    fun setListener(onClickListener: () -> Unit) {
        backPressListener = onClickListener
    }

    override fun asCandidate(context: Context): NestedMenuCandidate {
        val parentCandidate = super.asCandidate(context) as TextMenuCandidate
        return NestedMenuCandidate(
            id = hashCode(),
            text = parentCandidate.text,
            start = parentCandidate.start,
            subMenuItems = null,
            textStyle = parentCandidate.textStyle,
            containerStyle = parentCandidate.containerStyle
        )
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ class BrowserMenuHighlightableItem(
    }

    override fun asCandidate(context: Context): TextMenuCandidate {
        val base = super.asCandidate(context)
        val base = super.asCandidate(context) as TextMenuCandidate
        if (!isHighlighted()) return base

        @Suppress("Deprecation")
+2 −1
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ import mozilla.components.browser.menu.BrowserMenuItem
import mozilla.components.browser.menu.R
import mozilla.components.concept.menu.candidate.ContainerStyle
import mozilla.components.concept.menu.candidate.DrawableMenuIcon
import mozilla.components.concept.menu.candidate.MenuCandidate
import mozilla.components.concept.menu.candidate.TextMenuCandidate
import mozilla.components.concept.menu.candidate.TextStyle

@@ -84,7 +85,7 @@ open class BrowserMenuImageText(
        }
    }

    override fun asCandidate(context: Context) = TextMenuCandidate(
    override fun asCandidate(context: Context): MenuCandidate = TextMenuCandidate(
        label,
        start = DrawableMenuIcon(
            context,
+6 −3
Original line number Diff line number Diff line
@@ -13,9 +13,10 @@ import androidx.appcompat.widget.AppCompatImageView
import androidx.core.content.ContextCompat
import mozilla.components.browser.menu.BrowserMenu
import mozilla.components.browser.menu.R
import mozilla.components.browser.menu.ext.asCandidateList
import mozilla.components.concept.menu.candidate.ContainerStyle
import mozilla.components.concept.menu.candidate.DrawableMenuIcon
import mozilla.components.concept.menu.candidate.TextMenuCandidate
import mozilla.components.concept.menu.candidate.NestedMenuCandidate
import mozilla.components.concept.menu.candidate.TextStyle

/**
@@ -81,13 +82,15 @@ class ParentBrowserMenuItem(
        }
    }

    override fun asCandidate(context: Context) = TextMenuCandidate(
        label,
    override fun asCandidate(context: Context) = NestedMenuCandidate(
        id = hashCode(),
        text = label,
        start = DrawableMenuIcon(
            context,
            resource = imageResource,
            tint = if (iconTintColorResource == NO_ID) null else ContextCompat.getColor(context, iconTintColorResource)
        ),
        subMenuItems = subMenu.adapter.visibleItems.asCandidateList(context),
        textStyle = TextStyle(
            color = if (textColorResource == NO_ID) null else ContextCompat.getColor(context, textColorResource)
        ),
Loading