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

Commit

Permalink
Closes #3843: Adding the site tracking protection icon on the toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
Amejia481 committed Jul 28, 2019
1 parent 7ffa3ad commit 6194303
Show file tree
Hide file tree
Showing 15 changed files with 612 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.view.View
import android.view.View.OnFocusChangeListener
import android.view.ViewGroup
import android.widget.ImageButton
import androidx.annotation.ColorInt
import androidx.annotation.DrawableRes
import androidx.annotation.VisibleForTesting
import androidx.core.view.forEach
Expand Down Expand Up @@ -210,6 +211,39 @@ class BrowserToolbar @JvmOverloads constructor(
editToolbar.urlView.setTextColor(value)
}

/**
* Sets the icon of the tracking protection the site has tracking protection enable, but none
* trackers have been blocked or detected.
*/
@get:DrawableRes
var trackingProtectionONIcon: Int
get() = displayToolbar.trackingProtectionONIcon
set(@DrawableRes value) {
displayToolbar.trackingProtectionONIcon = value
}

/**
* Sets the icon of the tracking protection icon when is active
* e.g (Trackers have been blocked or detected)
*/
@get:DrawableRes
var trackingProtectionActiveIcon: Int
get() = displayToolbar.trackingProtectionActiveIcon
set(@DrawableRes value) {
displayToolbar.trackingProtectionActiveIcon = value
}

/**
* Sets the colour of the vertical separator between the tracking protection icon and the
* security indicator icon.
*/
@get:ColorInt
var trackingProtectionAndSecurityIndicatorSeparatorColor: Int
get() = displayToolbar.trackingProtectionAndSecurityIndicatorSeparatorColor
set(@ColorInt value) {
displayToolbar.trackingProtectionAndSecurityIndicatorSeparatorColor = value
}

/**
* Sets the size of the text for the title displayed in the toolbar.
*/
Expand Down Expand Up @@ -285,6 +319,29 @@ class BrowserToolbar @JvmOverloads constructor(
}
}

/**
* Sets a listener to be invoked when the site tracking protection indicator icon is clicked.
*/
fun setOnTrackingProtectionClickedListener(listener: (() -> Unit)?) {
if (listener == null) {
displayToolbar.trackingProtectionIconView.setOnClickListener(null)
displayToolbar.trackingProtectionIconView.background = null
} else {
displayToolbar.trackingProtectionIconView.setOnClickListener {
listener.invoke()
}

val outValue = TypedValue()

context.theme.resolveAttribute(
android.R.attr.selectableItemBackgroundBorderless,
outValue,
true)

displayToolbar.trackingProtectionIconView.setBackgroundResource(outValue.resourceId)
}
}

override fun setOnEditListener(listener: Toolbar.OnEditListener) {
editToolbar.editListener = listener
}
Expand Down Expand Up @@ -336,6 +393,15 @@ class BrowserToolbar @JvmOverloads constructor(
field = value
}

override var siteTrackingProtection: Toolbar.SiteTrackingProtection =
Toolbar.SiteTrackingProtection.OFF
set(value) {
if (field != value) {
displayToolbar.setTrackingProtectionState(value)
field = value
}
}

init {
context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbar, defStyleAttr, 0).run {
attrs?.let {
Expand Down Expand Up @@ -363,6 +429,22 @@ class BrowserToolbar @JvmOverloads constructor(
R.styleable.BrowserToolbar_browserToolbarClearColor,
editToolbar.clearViewColor
)

trackingProtectionONIcon = getResourceId(
R.styleable.BrowserToolbar_browserToolbarTrackingProtectionONIcon,
displayToolbar.trackingProtectionONIcon
)

trackingProtectionActiveIcon = getResourceId(
R.styleable.BrowserToolbar_browserToolbarTrackingProtectionActiveIcon,
displayToolbar.trackingProtectionActiveIcon
)

trackingProtectionAndSecurityIndicatorSeparatorColor = getColor(
R.styleable.BrowserToolbar_browserToolbarTrackingProtectionAndSecurityIndicatorSeparatorColor,
displayToolbar.trackingProtectionAndSecurityIndicatorSeparatorColor
)

if (peekValue(R.styleable.BrowserToolbar_browserToolbarSuggestionForegroundColor) != null) {
suggestionForegroundColor = getColor(
R.styleable.BrowserToolbar_browserToolbarSuggestionForegroundColor,
Expand Down
Loading

0 comments on commit 6194303

Please sign in to comment.