use synthetic binding instead of findviewbyid

nightly-build-test
Nikit Bhandari 5 years ago committed by Emily Kager
parent 8ebd7cd744
commit f110ba2861

@ -12,9 +12,8 @@ import android.util.AttributeSet
import android.util.TypedValue import android.util.TypedValue
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.ViewTreeObserver import android.view.ViewTreeObserver
import android.widget.ImageView
import android.widget.RelativeLayout import android.widget.RelativeLayout
import android.widget.TextView import kotlinx.android.synthetic.main.mozac_ui_tabcounter_layout.view.*
import mozilla.components.ui.tabcounter.R import mozilla.components.ui.tabcounter.R
import java.text.NumberFormat import java.text.NumberFormat
@ -24,9 +23,6 @@ open class TabCounter @JvmOverloads constructor(
defStyle: Int = 0 defStyle: Int = 0
) : RelativeLayout(context, attrs, defStyle) { ) : RelativeLayout(context, attrs, defStyle) {
private val box: ImageView
private val text: TextView
private val animationSet: AnimatorSet private val animationSet: AnimatorSet
private var count: Int = 0 private var count: Int = 0
private var currentTextRatio: Float = 0.toFloat() private var currentTextRatio: Float = 0.toFloat()
@ -35,13 +31,11 @@ open class TabCounter @JvmOverloads constructor(
val inflater = LayoutInflater.from(context) val inflater = LayoutInflater.from(context)
inflater.inflate(R.layout.mozac_ui_tabcounter_layout, this) inflater.inflate(R.layout.mozac_ui_tabcounter_layout, this)
box = findViewById(R.id.counter_box) counter_text.text = DEFAULT_TABS_COUNTER_TEXT
text = findViewById(R.id.counter_text)
text.text = DEFAULT_TABS_COUNTER_TEXT
val shiftThreeDp = TypedValue.applyDimension( val shiftThreeDp = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_PADDING, context.resources.displayMetrics TypedValue.COMPLEX_UNIT_DIP, TWO_DIGIT_PADDING, context.resources.displayMetrics
).toInt() ).toInt()
text.setPadding(0, shiftThreeDp, shiftThreeDp, 0) counter_text.setPadding(0, shiftThreeDp, shiftThreeDp, 0)
animationSet = createAnimatorSet() animationSet = createAnimatorSet()
} }
@ -65,7 +59,7 @@ open class TabCounter @JvmOverloads constructor(
adjustTextSize(count) adjustTextSize(count)
text.text = formatForDisplay(count) counter_text.text = formatForDisplay(count)
this.count = count this.count = count
// Cancel previous animations if necessary. // Cancel previous animations if necessary.
@ -79,7 +73,7 @@ open class TabCounter @JvmOverloads constructor(
fun setCount(count: Int) { fun setCount(count: Int) {
adjustTextSize(count) adjustTextSize(count)
text.text = formatForDisplay(count) counter_text.text = formatForDisplay(count)
this.count = count this.count = count
} }
@ -93,56 +87,56 @@ open class TabCounter @JvmOverloads constructor(
private fun createBoxAnimatorSet(animatorSet: AnimatorSet) { private fun createBoxAnimatorSet(animatorSet: AnimatorSet) {
// The first animator, fadeout in 33 ms (49~51, 2 frames). // The first animator, fadeout in 33 ms (49~51, 2 frames).
val fadeOut = ObjectAnimator.ofFloat( val fadeOut = ObjectAnimator.ofFloat(
box, "alpha", counter_box, "alpha",
ANIM_BOX_FADEOUT_FROM, ANIM_BOX_FADEOUT_TO ANIM_BOX_FADEOUT_FROM, ANIM_BOX_FADEOUT_TO
).setDuration(ANIM_BOX_FADEOUT_DURATION) ).setDuration(ANIM_BOX_FADEOUT_DURATION)
// Move up on y-axis, from 0.0 to -5.3 in 50ms, with fadeOut (49~52, 3 frames). // Move up on y-axis, from 0.0 to -5.3 in 50ms, with fadeOut (49~52, 3 frames).
val moveUp1 = ObjectAnimator.ofFloat( val moveUp1 = ObjectAnimator.ofFloat(
box, "translationY", counter_box, "translationY",
ANIM_BOX_MOVEUP1_TO, ANIM_BOX_MOVEUP1_FROM ANIM_BOX_MOVEUP1_TO, ANIM_BOX_MOVEUP1_FROM
).setDuration(ANIM_BOX_MOVEUP1_DURATION) ).setDuration(ANIM_BOX_MOVEUP1_DURATION)
// Move down on y-axis, from -5.3 to -1.0 in 116ms, after moveUp1 (52~59, 7 frames). // Move down on y-axis, from -5.3 to -1.0 in 116ms, after moveUp1 (52~59, 7 frames).
val moveDown2 = ObjectAnimator.ofFloat( val moveDown2 = ObjectAnimator.ofFloat(
box, "translationY", counter_box, "translationY",
ANIM_BOX_MOVEDOWN2_FROM, ANIM_BOX_MOVEDOWN2_TO ANIM_BOX_MOVEDOWN2_FROM, ANIM_BOX_MOVEDOWN2_TO
).setDuration(ANIM_BOX_MOVEDOWN2_DURATION) ).setDuration(ANIM_BOX_MOVEDOWN2_DURATION)
// FadeIn in 66ms, with moveDown2 (52~56, 4 frames). // FadeIn in 66ms, with moveDown2 (52~56, 4 frames).
val fadeIn = ObjectAnimator.ofFloat( val fadeIn = ObjectAnimator.ofFloat(
box, "alpha", counter_box, "alpha",
ANIM_BOX_FADEIN_FROM, ANIM_BOX_FADEIN_TO ANIM_BOX_FADEIN_FROM, ANIM_BOX_FADEIN_TO
).setDuration(ANIM_BOX_FADEIN_DURATION) ).setDuration(ANIM_BOX_FADEIN_DURATION)
// Move down on y-axis, from -1.0 to 2.7 in 116ms, after moveDown2 (59~66, 7 frames). // Move down on y-axis, from -1.0 to 2.7 in 116ms, after moveDown2 (59~66, 7 frames).
val moveDown3 = ObjectAnimator.ofFloat( val moveDown3 = ObjectAnimator.ofFloat(
box, "translationY", counter_box, "translationY",
ANIM_BOX_MOVEDOWN3_FROM, ANIM_BOX_MOVEDOWN3_TO ANIM_BOX_MOVEDOWN3_FROM, ANIM_BOX_MOVEDOWN3_TO
).setDuration(ANIM_BOX_MOVEDOWN3_DURATION) ).setDuration(ANIM_BOX_MOVEDOWN3_DURATION)
// Move up on y-axis, from 2.7 to 0 in 133ms, after moveDown3 (66~74, 8 frames). // Move up on y-axis, from 2.7 to 0 in 133ms, after moveDown3 (66~74, 8 frames).
val moveUp4 = ObjectAnimator.ofFloat( val moveUp4 = ObjectAnimator.ofFloat(
box, "translationY", counter_box, "translationY",
ANIM_BOX_MOVEDOWN4_FROM, ANIM_BOX_MOVEDOWN4_TO ANIM_BOX_MOVEDOWN4_FROM, ANIM_BOX_MOVEDOWN4_TO
).setDuration(ANIM_BOX_MOVEDOWN4_DURATION) ).setDuration(ANIM_BOX_MOVEDOWN4_DURATION)
// Scale up height from 2% to 105% in 100ms, after moveUp1 and delay 16ms (53~59, 6 frames). // Scale up height from 2% to 105% in 100ms, after moveUp1 and delay 16ms (53~59, 6 frames).
val scaleUp1 = ObjectAnimator.ofFloat( val scaleUp1 = ObjectAnimator.ofFloat(
box, "scaleY", counter_box, "scaleY",
ANIM_BOX_SCALEUP1_FROM, ANIM_BOX_SCALEUP1_TO ANIM_BOX_SCALEUP1_FROM, ANIM_BOX_SCALEUP1_TO
).setDuration(ANIM_BOX_SCALEUP1_DURATION) ).setDuration(ANIM_BOX_SCALEUP1_DURATION)
scaleUp1.startDelay = ANIM_BOX_SCALEUP1_DELAY // delay 1 frame after moveUp1 scaleUp1.startDelay = ANIM_BOX_SCALEUP1_DELAY // delay 1 frame after moveUp1
// Scale down height from 105% to 99% in 116ms, after scaleUp1 (59~66, 7 frames). // Scale down height from 105% to 99% in 116ms, after scaleUp1 (59~66, 7 frames).
val scaleDown2 = ObjectAnimator.ofFloat( val scaleDown2 = ObjectAnimator.ofFloat(
box, "scaleY", counter_box, "scaleY",
ANIM_BOX_SCALEDOWN2_FROM, ANIM_BOX_SCALEDOWN2_TO ANIM_BOX_SCALEDOWN2_FROM, ANIM_BOX_SCALEDOWN2_TO
).setDuration(ANIM_BOX_SCALEDOWN2_DURATION) ).setDuration(ANIM_BOX_SCALEDOWN2_DURATION)
// Scale up height from 99% to 100% in 133ms, after scaleDown2 (66~74, 8 frames). // Scale up height from 99% to 100% in 133ms, after scaleDown2 (66~74, 8 frames).
val scaleUp3 = ObjectAnimator.ofFloat( val scaleUp3 = ObjectAnimator.ofFloat(
box, "scaleY", counter_box, "scaleY",
ANIM_BOX_SCALEUP3_FROM, ANIM_BOX_SCALEUP3_TO ANIM_BOX_SCALEUP3_FROM, ANIM_BOX_SCALEUP3_TO
).setDuration(ANIM_BOX_SCALEUP3_DURATION) ).setDuration(ANIM_BOX_SCALEUP3_DURATION)
@ -162,27 +156,27 @@ open class TabCounter @JvmOverloads constructor(
// Fadeout in 100ms, with firstAnimator (49~51, 2 frames). // Fadeout in 100ms, with firstAnimator (49~51, 2 frames).
val fadeOut = ObjectAnimator.ofFloat( val fadeOut = ObjectAnimator.ofFloat(
text, "alpha", counter_text, "alpha",
ANIM_TEXT_FADEOUT_FROM, ANIM_TEXT_FADEOUT_TO ANIM_TEXT_FADEOUT_FROM, ANIM_TEXT_FADEOUT_TO
).setDuration(ANIM_TEXT_FADEOUT_DURATION) ).setDuration(ANIM_TEXT_FADEOUT_DURATION)
// FadeIn in 66 ms, after fadeOut with delay 96ms (57~61, 4 frames). // FadeIn in 66 ms, after fadeOut with delay 96ms (57~61, 4 frames).
val fadeIn = ObjectAnimator.ofFloat( val fadeIn = ObjectAnimator.ofFloat(
text, "alpha", counter_text, "alpha",
ANIM_TEXT_FADEIN_FROM, ANIM_TEXT_FADEIN_TO ANIM_TEXT_FADEIN_FROM, ANIM_TEXT_FADEIN_TO
).setDuration(ANIM_TEXT_FADEIN_DURATION) ).setDuration(ANIM_TEXT_FADEIN_DURATION)
fadeIn.startDelay = (ANIM_TEXT_FADEIN_DELAY).toLong() // delay 6 frames after fadeOut fadeIn.startDelay = (ANIM_TEXT_FADEIN_DELAY).toLong() // delay 6 frames after fadeOut
// Move down on y-axis, from 0 to 4.4 in 66ms, with fadeIn (57~61, 4 frames). // Move down on y-axis, from 0 to 4.4 in 66ms, with fadeIn (57~61, 4 frames).
val moveDown = ObjectAnimator.ofFloat( val moveDown = ObjectAnimator.ofFloat(
text, "translationY", counter_text, "translationY",
ANIM_TEXT_MOVEDOWN_FROM, ANIM_TEXT_MOVEDOWN_TO ANIM_TEXT_MOVEDOWN_FROM, ANIM_TEXT_MOVEDOWN_TO
).setDuration(ANIM_TEXT_MOVEDOWN_DURATION) ).setDuration(ANIM_TEXT_MOVEDOWN_DURATION)
moveDown.startDelay = (ANIM_TEXT_MOVEDOWN_DELAY) // delay 6 frames after fadeOut moveDown.startDelay = (ANIM_TEXT_MOVEDOWN_DELAY) // delay 6 frames after fadeOut
// Move up on y-axis, from 0 to 4.4 in 66ms, after moveDown (61~69, 8 frames). // Move up on y-axis, from 0 to 4.4 in 66ms, after moveDown (61~69, 8 frames).
val moveUp = ObjectAnimator.ofFloat( val moveUp = ObjectAnimator.ofFloat(
text, "translationY", counter_text, "translationY",
ANIM_TEXT_MOVEUP_FROM, ANIM_TEXT_MOVEUP_TO ANIM_TEXT_MOVEUP_FROM, ANIM_TEXT_MOVEUP_TO
).setDuration(ANIM_TEXT_MOVEUP_DURATION) ).setDuration(ANIM_TEXT_MOVEUP_DURATION)
@ -207,21 +201,21 @@ open class TabCounter @JvmOverloads constructor(
if (newRatio != currentTextRatio) { if (newRatio != currentTextRatio) {
currentTextRatio = newRatio currentTextRatio = newRatio
text.viewTreeObserver.addOnGlobalLayoutListener(object : counter_text.viewTreeObserver.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener { ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() { override fun onGlobalLayout() {
text.viewTreeObserver.removeOnGlobalLayoutListener(this) counter_text.viewTreeObserver.removeOnGlobalLayoutListener(this)
val sizeInPixel = (box.width * newRatio).toInt() val sizeInPixel = (counter_box.width * newRatio).toInt()
if (sizeInPixel > 0) { if (sizeInPixel > 0) {
// Only apply the size when we calculate a valid value. // Only apply the size when we calculate a valid value.
text.setTextSize(TypedValue.COMPLEX_UNIT_PX, sizeInPixel.toFloat()) counter_text.setTextSize(TypedValue.COMPLEX_UNIT_PX, sizeInPixel.toFloat())
text.setTypeface(null, Typeface.BOLD) counter_text.setTypeface(null, Typeface.BOLD)
val shiftDp = TypedValue.applyDimension( val shiftDp = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, TypedValue.COMPLEX_UNIT_DIP,
if (newRatio == TWO_DIGITS_SIZE_RATIO) TWO_DIGIT_PADDING else ONE_DIGIT_PADDING, if (newRatio == TWO_DIGITS_SIZE_RATIO) TWO_DIGIT_PADDING else ONE_DIGIT_PADDING,
context.resources.displayMetrics context.resources.displayMetrics
).toInt() ).toInt()
text.setPadding(0, shiftDp, shiftDp, 0) counter_text.setPadding(0, shiftDp, shiftDp, 0)
} }
} }
}) })

@ -8,7 +8,6 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.Navigation import androidx.navigation.Navigation
@ -32,7 +31,7 @@ class CrashReporterFragment : Fragment() {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val crash = Crash.fromIntent(CrashReporterFragmentArgs.fromBundle(arguments!!).crashIntent) val crash = Crash.fromIntent(CrashReporterFragmentArgs.fromBundle(arguments!!).crashIntent)
view.findViewById<TextView>(R.id.title).text = title.text =
getString(R.string.tab_crash_title_2, context!!.getString(R.string.app_name)) getString(R.string.tab_crash_title_2, context!!.getString(R.string.app_name))
requireContext().components.analytics.metrics.track(Event.CrashReporterOpened) requireContext().components.analytics.metrics.track(Event.CrashReporterOpened)

@ -16,7 +16,7 @@ import org.mozilla.fenix.R
import android.os.Bundle import android.os.Bundle
import android.view.accessibility.AccessibilityEvent import android.view.accessibility.AccessibilityEvent
import android.view.accessibility.AccessibilityNodeInfo import android.view.accessibility.AccessibilityNodeInfo
import android.widget.ImageButton import kotlinx.android.synthetic.main.layout_quick_action_sheet.view.*
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@ -39,8 +39,6 @@ class QuickActionSheet @JvmOverloads constructor(
override val coroutineContext: CoroutineContext override val coroutineContext: CoroutineContext
get() = Dispatchers.Main + job get() = Dispatchers.Main + job
private lateinit var handle: ImageButton
private lateinit var linearLayout: LinearLayout
private lateinit var quickActionSheetBehavior: QuickActionSheetBehavior private lateinit var quickActionSheetBehavior: QuickActionSheetBehavior
init { init {
@ -50,9 +48,8 @@ class QuickActionSheet @JvmOverloads constructor(
override fun onAttachedToWindow() { override fun onAttachedToWindow() {
super.onAttachedToWindow() super.onAttachedToWindow()
job = Job() job = Job()
handle = findViewById(R.id.quick_action_sheet_handle) quickActionSheetBehavior = BottomSheetBehavior.from(quick_action_sheet.parent as View)
linearLayout = findViewById(R.id.quick_action_sheet) as QuickActionSheetBehavior
quickActionSheetBehavior = BottomSheetBehavior.from(linearLayout.parent as View) as QuickActionSheetBehavior
quickActionSheetBehavior.isHideable = false quickActionSheetBehavior.isHideable = false
setupHandle() setupHandle()
} }
@ -63,14 +60,14 @@ class QuickActionSheet @JvmOverloads constructor(
} }
private fun setupHandle() { private fun setupHandle() {
handle.setOnClickListener { quick_action_sheet_handle.setOnClickListener {
quickActionSheetBehavior.state = when (quickActionSheetBehavior.state) { quickActionSheetBehavior.state = when (quickActionSheetBehavior.state) {
BottomSheetBehavior.STATE_EXPANDED -> BottomSheetBehavior.STATE_COLLAPSED BottomSheetBehavior.STATE_EXPANDED -> BottomSheetBehavior.STATE_COLLAPSED
else -> BottomSheetBehavior.STATE_EXPANDED else -> BottomSheetBehavior.STATE_EXPANDED
} }
} }
handle.setAccessibilityDelegate(HandleAccessibilityDelegate(quickActionSheetBehavior)) quick_action_sheet_handle.setAccessibilityDelegate(HandleAccessibilityDelegate(quickActionSheetBehavior))
} }
fun bounceSheet() { fun bounceSheet() {

@ -8,11 +8,11 @@ import android.os.Bundle
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.core.text.HtmlCompat import androidx.core.text.HtmlCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.navigation.fragment.NavHostFragment.findNavController import androidx.navigation.fragment.NavHostFragment.findNavController
import kotlinx.android.synthetic.main.fragment_pair.*
import mozilla.components.feature.qr.QrFeature import mozilla.components.feature.qr.QrFeature
import mozilla.components.support.base.feature.BackHandler import mozilla.components.support.base.feature.BackHandler
import mozilla.components.support.base.feature.ViewBoundFeatureWrapper import mozilla.components.support.base.feature.ViewBoundFeatureWrapper
@ -33,13 +33,8 @@ class PairFragment : Fragment(), BackHandler {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState) super.onViewCreated(view, savedInstanceState)
val instructionsText = view.findViewById(R.id.pair_instructions) as TextView pair_instructions.text = HtmlCompat.fromHtml(getString(R.string.pair_instructions),
instructionsText.setText( HtmlCompat.FROM_HTML_MODE_LEGACY)
HtmlCompat.fromHtml(
getString(R.string.pair_instructions),
HtmlCompat.FROM_HTML_MODE_LEGACY
)
)
qrFeature.set( qrFeature.set(
QrFeature( QrFeature(

@ -9,15 +9,14 @@ import android.view.View
import android.view.View.GONE import android.view.View.GONE
import android.view.View.VISIBLE import android.view.View.VISIBLE
import android.view.ViewGroup import android.view.ViewGroup
import android.widget.Switch
import android.widget.TextView import android.widget.TextView
import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.content.res.AppCompatResources
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.net.toUri import androidx.core.net.toUri
import io.reactivex.Observable import io.reactivex.Observable
import io.reactivex.Observer import io.reactivex.Observer
import io.reactivex.functions.Consumer import io.reactivex.functions.Consumer
import kotlinx.android.synthetic.main.fragment_quick_settings_dialog_sheet.*
import mozilla.components.feature.sitepermissions.SitePermissions import mozilla.components.feature.sitepermissions.SitePermissions
import mozilla.components.feature.sitepermissions.SitePermissions.Status.BLOCKED import mozilla.components.feature.sitepermissions.SitePermissions.Status.BLOCKED
import mozilla.components.feature.sitepermissions.SitePermissions.Status.NO_DECISION import mozilla.components.feature.sitepermissions.SitePermissions.Status.NO_DECISION
@ -40,39 +39,10 @@ class QuickSettingsUIView(
) : UIView<QuickSettingsState, QuickSettingsAction, QuickSettingsChange>( ) : UIView<QuickSettingsState, QuickSettingsAction, QuickSettingsChange>(
container, actionEmitter, changesObservable container, actionEmitter, changesObservable
) { ) {
private val securityInfoLabel: TextView
private val urlLabel: TextView
private val trackingProtectionSwitch: Switch
private val trackingProtectionAction: TextView
private val reportSiteIssueAction: TextView
private val cameraActionLabel: TextView
private val cameraLabel: TextView
private val microphoneActionLabel: TextView
private val microphoneLabel: TextView
private val locationActionLabel: TextView
private val locationLabel: TextView
private val notificationActionLabel: TextView
private val notificationLabel: TextView
private val blockedByAndroidPhoneFeatures = mutableListOf<PhoneFeature>() private val blockedByAndroidPhoneFeatures = mutableListOf<PhoneFeature>()
private val context get() = view.context private val context get() = view.context
private val settings: Settings = Settings.getInstance(context) private val settings: Settings = Settings.getInstance(context)
init {
urlLabel = view.findViewById<AppCompatTextView>(R.id.url)
securityInfoLabel = view.findViewById<AppCompatTextView>(R.id.security_info)
trackingProtectionSwitch = view.findViewById(R.id.tracking_protection)
trackingProtectionAction = view.findViewById(R.id.tracking_protection_action)
reportSiteIssueAction = view.findViewById(R.id.report_site_issue_action)
cameraActionLabel = view.findViewById<AppCompatTextView>(R.id.camera_action_label)
cameraLabel = view.findViewById<AppCompatTextView>(R.id.camera_icon)
microphoneActionLabel = view.findViewById<AppCompatTextView>(R.id.microphone_action_label)
microphoneLabel = view.findViewById<AppCompatTextView>(R.id.microphone_icon)
locationLabel = view.findViewById<AppCompatTextView>(R.id.location_icon)
locationActionLabel = view.findViewById<AppCompatTextView>(R.id.location_action_label)
notificationActionLabel = view.findViewById<AppCompatTextView>(R.id.notification_action_label)
notificationLabel = view.findViewById<AppCompatTextView>(R.id.notification_icon)
}
override fun updateView() = Consumer<QuickSettingsState> { state -> override fun updateView() = Consumer<QuickSettingsState> { state ->
when (state.mode) { when (state.mode) {
is QuickSettingsState.Mode.Normal -> { is QuickSettingsState.Mode.Normal -> {
@ -96,7 +66,7 @@ class QuickSettingsUIView(
} }
private fun bindUrl(url: String) { private fun bindUrl(url: String) {
urlLabel.text = url.toUri().hostWithoutCommonPrefixes this.url.text = url.toUri().hostWithoutCommonPrefixes
} }
private fun bindTrackingProtectionInfo(isTrackingProtectionOn: Boolean) { private fun bindTrackingProtectionInfo(isTrackingProtectionOn: Boolean) {
@ -105,11 +75,11 @@ class QuickSettingsUIView(
if (isTrackingProtectionOn) R.drawable.ic_tracking_protection else if (isTrackingProtectionOn) R.drawable.ic_tracking_protection else
R.drawable.ic_tracking_protection_disabled R.drawable.ic_tracking_protection_disabled
val icon = AppCompatResources.getDrawable(context, drawableId) val icon = AppCompatResources.getDrawable(context, drawableId)
trackingProtectionSwitch.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) tracking_protection.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
trackingProtectionSwitch.isChecked = isTrackingProtectionOn tracking_protection.isChecked = isTrackingProtectionOn
trackingProtectionSwitch.isEnabled = globalTPSetting tracking_protection.isEnabled = globalTPSetting
trackingProtectionSwitch.setOnCheckedChangeListener { _, isChecked -> tracking_protection.setOnCheckedChangeListener { _, isChecked ->
actionEmitter.onNext( actionEmitter.onNext(
QuickSettingsAction.ToggleTrackingProtection( QuickSettingsAction.ToggleTrackingProtection(
isChecked isChecked
@ -120,8 +90,8 @@ class QuickSettingsUIView(
private fun bindTrackingProtectionAction() { private fun bindTrackingProtectionAction() {
val globalTPSetting = Settings.getInstance(context).shouldUseTrackingProtection val globalTPSetting = Settings.getInstance(context).shouldUseTrackingProtection
trackingProtectionAction.visibility = if (globalTPSetting) View.GONE else View.VISIBLE tracking_protection_action.visibility = if (globalTPSetting) View.GONE else View.VISIBLE
trackingProtectionAction.setOnClickListener { tracking_protection_action.setOnClickListener {
actionEmitter.onNext( actionEmitter.onNext(
QuickSettingsAction.SelectTrackingProtectionSettings QuickSettingsAction.SelectTrackingProtectionSettings
) )
@ -129,7 +99,7 @@ class QuickSettingsUIView(
} }
private fun bindReportSiteIssueAction(url: String) { private fun bindReportSiteIssueAction(url: String) {
reportSiteIssueAction.setOnClickListener { report_site_issue_action.setOnClickListener {
actionEmitter.onNext( actionEmitter.onNext(
QuickSettingsAction.SelectReportProblem(url) QuickSettingsAction.SelectReportProblem(url)
) )
@ -153,8 +123,8 @@ class QuickSettingsUIView(
val icon = AppCompatResources.getDrawable(context, drawableId) val icon = AppCompatResources.getDrawable(context, drawableId)
icon?.setTint(ContextCompat.getColor(context, drawableTint)) icon?.setTint(ContextCompat.getColor(context, drawableTint))
securityInfoLabel.setText(stringId) security_info.setText(stringId)
securityInfoLabel.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null) security_info.setCompoundDrawablesWithIntrinsicBounds(icon, null, null, null)
} }
private fun bindPhoneFeatureItem(phoneFeature: PhoneFeature, sitePermissions: SitePermissions? = null) { private fun bindPhoneFeatureItem(phoneFeature: PhoneFeature, sitePermissions: SitePermissions? = null) {
@ -249,10 +219,10 @@ class QuickSettingsUIView(
private val PhoneFeature.labelAndAction private val PhoneFeature.labelAndAction
get(): Pair<TextView, TextView> { get(): Pair<TextView, TextView> {
return when (this) { return when (this) {
CAMERA -> cameraLabel to cameraActionLabel CAMERA -> camera_icon to camera_action_label
LOCATION -> locationLabel to locationActionLabel LOCATION -> location_icon to location_action_label
MICROPHONE -> microphoneLabel to microphoneActionLabel MICROPHONE -> microphone_icon to microphone_action_label
NOTIFICATION -> notificationLabel to notificationActionLabel NOTIFICATION -> notification_icon to notification_action_label
} }
} }

Loading…
Cancel
Save