forked from mozilla-mobile/android-components
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Closes mozilla-mobile#9131: Add site permission indicators
in the toolbar.
- Loading branch information
Showing
21 changed files
with
478 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...src/main/java/mozilla/components/browser/state/state/content/PermissionHighlightsState.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* 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.state.state.content | ||
|
||
/** | ||
* Value type that represents any information about permissions that should | ||
* be brought to user's attention. | ||
* | ||
* @property isAutoPlayBlocking indicates if the autoplay setting | ||
* disabled some web content from playing. | ||
*/ | ||
data class PermissionHighlightsState( | ||
val isAutoPlayBlocking: Boolean = false | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
.../src/main/java/mozilla/components/browser/toolbar/display/PermissionHighlightsIconView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* 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.toolbar.display | ||
|
||
import android.content.Context | ||
import android.graphics.drawable.Drawable | ||
import android.util.AttributeSet | ||
import androidx.annotation.VisibleForTesting | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.appcompat.widget.AppCompatImageView | ||
import androidx.core.view.isVisible | ||
import mozilla.components.browser.toolbar.R | ||
import mozilla.components.concept.toolbar.Toolbar.PermissionHighlights | ||
import mozilla.components.concept.toolbar.Toolbar.PermissionHighlights.AUTOPLAY_BLOCKED | ||
import mozilla.components.concept.toolbar.Toolbar.PermissionHighlights.NONE | ||
|
||
/** | ||
* Internal widget to display the different icons of site permission. | ||
*/ | ||
internal class PermissionHighlightsIconView @JvmOverloads constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyleAttr: Int = 0 | ||
) : AppCompatImageView(context, attrs, defStyleAttr) { | ||
|
||
init { | ||
visibility = GONE | ||
} | ||
|
||
var permissionHighlights: PermissionHighlights = NONE | ||
set(value) { | ||
if (value != field) { | ||
field = value | ||
updateIcon() | ||
} | ||
} | ||
|
||
@VisibleForTesting | ||
internal var permissionTint: Int? = null | ||
|
||
private var iconAutoplayBlocked: Drawable = | ||
requireNotNull(AppCompatResources.getDrawable(context, DEFAULT_ICON_AUTOPLAY_BLOCKED)) | ||
|
||
fun setTint(tint: Int) { | ||
permissionTint = tint | ||
setColorFilter(tint) | ||
} | ||
|
||
fun setIcons(icons: DisplayToolbar.Icons.PermissionHighlights) { | ||
this.iconAutoplayBlocked = icons.autoPlayBlocked | ||
|
||
updateIcon() | ||
} | ||
|
||
@Synchronized | ||
@VisibleForTesting | ||
internal fun updateIcon() { | ||
val update = permissionHighlights.toUpdate() | ||
|
||
isVisible = update.visible | ||
|
||
contentDescription = if (update.contentDescription != null) { | ||
context.getString(update.contentDescription) | ||
} else { | ||
null | ||
} | ||
|
||
permissionTint?.let { setColorFilter(it) } | ||
setImageDrawable(update.drawable) | ||
} | ||
|
||
companion object { | ||
val DEFAULT_ICON_AUTOPLAY_BLOCKED = | ||
R.drawable.mozac_ic_autoplay_blocked | ||
} | ||
|
||
private fun PermissionHighlights.toUpdate(): Update = when (this) { | ||
AUTOPLAY_BLOCKED -> Update( | ||
iconAutoplayBlocked, | ||
R.string.mozac_browser_toolbar_content_description_autoplay_blocked, | ||
true) | ||
|
||
NONE -> Update( | ||
null, | ||
null, | ||
false | ||
) | ||
} | ||
} |
Oops, something went wrong.