2
0
mirror of https://github.com/fork-maintainers/iceraven-browser synced 2024-11-19 09:25:34 +00:00

[fenix] For https://github.com/mozilla-mobile/fenix/issues/20601: Use View binding in quick settings.

This commit is contained in:
mcarare 2021-08-04 12:12:33 +03:00 committed by Arturo Mejia
parent bd036901ae
commit a710775406
4 changed files with 55 additions and 50 deletions

View File

@ -25,8 +25,6 @@ import androidx.navigation.fragment.findNavController
import androidx.navigation.fragment.navArgs import androidx.navigation.fragment.navArgs
import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog import com.google.android.material.bottomsheet.BottomSheetDialog
import kotlinx.android.synthetic.main.fragment_quick_settings_dialog_sheet.*
import kotlinx.android.synthetic.main.fragment_quick_settings_dialog_sheet.view.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.plus import kotlinx.coroutines.plus
@ -35,6 +33,7 @@ import org.mozilla.fenix.BuildConfig
import org.mozilla.fenix.HomeActivity import org.mozilla.fenix.HomeActivity
import org.mozilla.fenix.IntentReceiverActivity import org.mozilla.fenix.IntentReceiverActivity
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.FragmentQuickSettingsDialogSheetBinding
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.settings.PhoneFeature import org.mozilla.fenix.settings.PhoneFeature
import com.google.android.material.R as MaterialR import com.google.android.material.R as MaterialR
@ -55,6 +54,8 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
private var tryToRequestPermissions: Boolean = false private var tryToRequestPermissions: Boolean = false
private val args by navArgs<QuickSettingsSheetDialogFragmentArgs>() private val args by navArgs<QuickSettingsSheetDialogFragmentArgs>()
private lateinit var binding: FragmentQuickSettingsDialogSheetBinding
@Suppress("DEPRECATION") @Suppress("DEPRECATION")
// https://github.com/mozilla-mobile/fenix/issues/19920 // https://github.com/mozilla-mobile/fenix/issues/19920
override fun onCreateView( override fun onCreateView(
@ -64,7 +65,10 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
): View { ): View {
val context = requireContext() val context = requireContext()
val components = context.components val components = context.components
val rootView = inflateRootView(container) val rootView = inflateRootView(container)
binding = FragmentQuickSettingsDialogSheetBinding.bind(rootView)
quickSettingsStore = QuickSettingsFragmentStore.createStore( quickSettingsStore = QuickSettingsFragmentStore.createStore(
context = context, context = context,
websiteUrl = args.url, websiteUrl = args.url,
@ -98,9 +102,9 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
interactor = QuickSettingsInteractor(quickSettingsController) interactor = QuickSettingsInteractor(quickSettingsController)
websiteInfoView = WebsiteInfoView(rootView.websiteInfoLayout) websiteInfoView = WebsiteInfoView(binding.websiteInfoLayout)
websitePermissionsView = websitePermissionsView =
WebsitePermissionsView(rootView.websitePermissionsLayout, interactor) WebsitePermissionsView(binding.websitePermissionsLayout, interactor)
return rootView return rootView
} }
@ -152,7 +156,8 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
quickSettingsController.handleAndroidPermissionGranted(it) quickSettingsController.handleAndroidPermissionGranted(it)
} }
} else { } else {
val shouldShowRequestPermissionRationale = permissions.all { shouldShowRequestPermissionRationale(it) } val shouldShowRequestPermissionRationale =
permissions.all { shouldShowRequestPermissionRationale(it) }
if (!shouldShowRequestPermissionRationale && tryToRequestPermissions) { if (!shouldShowRequestPermissionRationale && tryToRequestPermissions) {
// The user has permanently blocked these permissions and he/she is trying to enabling them. // The user has permanently blocked these permissions and he/she is trying to enabling them.
@ -187,7 +192,7 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
requestCode == REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS && grantResults.all { it == PERMISSION_GRANTED } requestCode == REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS && grantResults.all { it == PERMISSION_GRANTED }
private fun showPermissionsView() { private fun showPermissionsView() {
websitePermissionsGroup.isVisible = true binding.websitePermissionsGroup.isVisible = true
} }
private fun launchIntentReceiver() { private fun launchIntentReceiver() {

View File

@ -5,14 +5,12 @@
package org.mozilla.fenix.settings.quicksettings package org.mozilla.fenix.settings.quicksettings
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat.getColor import androidx.core.content.ContextCompat.getColor
import androidx.core.view.isVisible import androidx.core.view.isVisible
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.quicksettings_website_info.*
import mozilla.components.support.ktx.android.content.getDrawableWithTint import mozilla.components.support.ktx.android.content.getDrawableWithTint
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.QuicksettingsWebsiteInfoBinding
/** /**
* MVI View that knows to display a whether the current website uses a secure connection or not. * MVI View that knows to display a whether the current website uses a secure connection or not.
@ -23,10 +21,12 @@ import org.mozilla.fenix.R
*/ */
class WebsiteInfoView( class WebsiteInfoView(
container: ViewGroup container: ViewGroup
) : LayoutContainer { ) {
val binding = QuicksettingsWebsiteInfoBinding.inflate(
override val containerView: View = LayoutInflater.from(container.context) LayoutInflater.from(container.context),
.inflate(R.layout.quicksettings_website_info, container, true) container,
true
)
/** /**
* Allows changing what this View displays. * Allows changing what this View displays.
@ -41,24 +41,25 @@ class WebsiteInfoView(
} }
private fun bindUrl(websiteUrl: String) { private fun bindUrl(websiteUrl: String) {
url.text = websiteUrl binding.url.text = websiteUrl
} }
private fun bindTitle(websiteTitle: String) { private fun bindTitle(websiteTitle: String) {
title.text = websiteTitle binding.title.text = websiteTitle
} }
private fun bindCertificateName(cert: String) { private fun bindCertificateName(cert: String) {
val certificateLabel = containerView.context.getString(R.string.certificate_info_verified_by, cert) val certificateLabel =
certificateInfo.text = certificateLabel binding.root.context.getString(R.string.certificate_info_verified_by, cert)
certificateInfo.isVisible = cert.isNotEmpty() binding.certificateInfo.text = certificateLabel
binding.certificateInfo.isVisible = cert.isNotEmpty()
} }
private fun bindSecurityInfo(uiValues: WebsiteSecurityUiValues) { private fun bindSecurityInfo(uiValues: WebsiteSecurityUiValues) {
val tint = getColor(containerView.context, uiValues.iconTintRes) val tint = getColor(binding.root.context, uiValues.iconTintRes)
securityInfo.setText(uiValues.securityInfoRes) binding.securityInfo.setText(uiValues.securityInfoRes)
securityInfoIcon.setImageDrawable( binding.securityInfoIcon.setImageDrawable(
containerView.context.getDrawableWithTint(uiValues.iconRes, tint) binding.root.context.getDrawableWithTint(uiValues.iconRes, tint)
) )
} }
} }

View File

@ -14,9 +14,8 @@ import androidx.annotation.VisibleForTesting
import androidx.appcompat.widget.AppCompatSpinner import androidx.appcompat.widget.AppCompatSpinner
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.core.view.isVisible import androidx.core.view.isVisible
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.main.quicksettings_permissions.view.*
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.databinding.QuicksettingsPermissionsBinding
import org.mozilla.fenix.settings.PhoneFeature import org.mozilla.fenix.settings.PhoneFeature
import org.mozilla.fenix.settings.PhoneFeature.AUTOPLAY import org.mozilla.fenix.settings.PhoneFeature.AUTOPLAY
import org.mozilla.fenix.settings.PhoneFeature.CAMERA import org.mozilla.fenix.settings.PhoneFeature.CAMERA
@ -65,38 +64,38 @@ interface WebsitePermissionInteractor {
* @param interactor [WebsitePermissionInteractor] which will have delegated to all user interactions. * @param interactor [WebsitePermissionInteractor] which will have delegated to all user interactions.
*/ */
class WebsitePermissionsView( class WebsitePermissionsView(
override val containerView: ViewGroup, containerView: ViewGroup,
val interactor: WebsitePermissionInteractor val interactor: WebsitePermissionInteractor
) : LayoutContainer { ) {
private val context = containerView.context private val context = containerView.context
val view: View = LayoutInflater.from(context) val binding =
.inflate(R.layout.quicksettings_permissions, containerView, true) QuicksettingsPermissionsBinding.inflate(LayoutInflater.from(context), containerView, true)
@VisibleForTesting @VisibleForTesting
internal var permissionViews: Map<PhoneFeature, PermissionViewHolder> = EnumMap( internal var permissionViews: Map<PhoneFeature, PermissionViewHolder> = EnumMap(
mapOf( mapOf(
CAMERA to ToggleablePermission(view.cameraLabel, view.cameraStatus), CAMERA to ToggleablePermission(binding.cameraLabel, binding.cameraStatus),
LOCATION to ToggleablePermission(view.locationLabel, view.locationStatus), LOCATION to ToggleablePermission(binding.locationLabel, binding.locationStatus),
MICROPHONE to ToggleablePermission( MICROPHONE to ToggleablePermission(
view.microphoneLabel, binding.microphoneLabel,
view.microphoneStatus binding.microphoneStatus
), ),
NOTIFICATION to ToggleablePermission( NOTIFICATION to ToggleablePermission(
view.notificationLabel, binding.notificationLabel,
view.notificationStatus binding.notificationStatus
), ),
PERSISTENT_STORAGE to ToggleablePermission( PERSISTENT_STORAGE to ToggleablePermission(
view.persistentStorageLabel, binding.persistentStorageLabel,
view.persistentStorageStatus binding.persistentStorageStatus
), ),
MEDIA_KEY_SYSTEM_ACCESS to ToggleablePermission( MEDIA_KEY_SYSTEM_ACCESS to ToggleablePermission(
view.mediaKeySystemAccessLabel, binding.mediaKeySystemAccessLabel,
view.mediaKeySystemAccessStatus binding.mediaKeySystemAccessStatus
), ),
AUTOPLAY to SpinnerPermission( AUTOPLAY to SpinnerPermission(
view.autoplayLabel, binding.autoplayLabel,
view.autoplayStatus binding.autoplayStatus
) )
) )
) )

View File

@ -6,9 +6,6 @@ package org.mozilla.fenix.settings.quicksettings
import android.widget.FrameLayout import android.widget.FrameLayout
import androidx.core.view.isVisible import androidx.core.view.isVisible
import kotlinx.android.synthetic.main.library_site_item.title
import kotlinx.android.synthetic.main.library_site_item.url
import kotlinx.android.synthetic.main.quicksettings_website_info.*
import mozilla.components.support.test.robolectric.testContext import mozilla.components.support.test.robolectric.testContext
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse import org.junit.Assert.assertFalse
@ -16,16 +13,19 @@ import org.junit.Assert.assertTrue
import org.junit.Before import org.junit.Before
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
import org.mozilla.fenix.databinding.QuicksettingsWebsiteInfoBinding
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class) @RunWith(FenixRobolectricTestRunner::class)
class WebsiteInfoViewTest { class WebsiteInfoViewTest {
private lateinit var view: WebsiteInfoView private lateinit var view: WebsiteInfoView
private lateinit var binding: QuicksettingsWebsiteInfoBinding
@Before @Before
fun setup() { fun setup() {
view = WebsiteInfoView(FrameLayout(testContext)) view = WebsiteInfoView(FrameLayout(testContext))
binding = view.binding
} }
@Test @Test
@ -39,10 +39,10 @@ class WebsiteInfoViewTest {
) )
) )
assertEquals("https://mozilla.org", view.url.text) assertEquals("https://mozilla.org", binding.url.text)
assertEquals("Mozilla", view.title.text) assertEquals("Mozilla", binding.title.text)
assertEquals("Secure Connection", view.securityInfo.text) assertEquals("Secure Connection", binding.securityInfo.text)
assertFalse(view.certificateInfo.isVisible) assertFalse(binding.certificateInfo.isVisible)
} }
@Test @Test
@ -56,8 +56,8 @@ class WebsiteInfoViewTest {
) )
) )
assertEquals("Insecure Connection", view.securityInfo.text) assertEquals("Insecure Connection", binding.securityInfo.text)
assertEquals("Verified By: Certificate", view.certificateInfo.text) assertEquals("Verified By: Certificate", binding.certificateInfo.text)
assertTrue(view.certificateInfo.isVisible) assertTrue(binding.certificateInfo.isVisible)
} }
} }