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: Undo Use View binding in quick Settings.

This commit is contained in:
Arturo Mejia 2021-08-03 15:09:54 -04:00
parent 68bef957b5
commit 724fb8b60f
4 changed files with 50 additions and 56 deletions

View File

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

View File

@ -5,12 +5,14 @@
package org.mozilla.fenix.settings.quicksettings
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat.getColor
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 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.
@ -21,12 +23,10 @@ import org.mozilla.fenix.databinding.QuicksettingsWebsiteInfoBinding
*/
class WebsiteInfoView(
container: ViewGroup
) {
val binding = QuicksettingsWebsiteInfoBinding.inflate(
LayoutInflater.from(container.context),
container,
false
)
) : LayoutContainer {
override val containerView: View = LayoutInflater.from(container.context)
.inflate(R.layout.quicksettings_website_info, container, true)
/**
* Allows changing what this View displays.
@ -41,25 +41,24 @@ class WebsiteInfoView(
}
private fun bindUrl(websiteUrl: String) {
binding.url.text = websiteUrl
url.text = websiteUrl
}
private fun bindTitle(websiteTitle: String) {
binding.title.text = websiteTitle
title.text = websiteTitle
}
private fun bindCertificateName(cert: String) {
val certificateLabel =
binding.root.context.getString(R.string.certificate_info_verified_by, cert)
binding.certificateInfo.text = certificateLabel
binding.certificateInfo.isVisible = cert.isNotEmpty()
val certificateLabel = containerView.context.getString(R.string.certificate_info_verified_by, cert)
certificateInfo.text = certificateLabel
certificateInfo.isVisible = cert.isNotEmpty()
}
private fun bindSecurityInfo(uiValues: WebsiteSecurityUiValues) {
val tint = getColor(binding.root.context, uiValues.iconTintRes)
binding.securityInfo.setText(uiValues.securityInfoRes)
binding.securityInfoIcon.setImageDrawable(
binding.root.context.getDrawableWithTint(uiValues.iconRes, tint)
val tint = getColor(containerView.context, uiValues.iconTintRes)
securityInfo.setText(uiValues.securityInfoRes)
securityInfoIcon.setImageDrawable(
containerView.context.getDrawableWithTint(uiValues.iconRes, tint)
)
}
}

View File

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

View File

@ -6,6 +6,9 @@ package org.mozilla.fenix.settings.quicksettings
import android.widget.FrameLayout
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 org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
@ -13,19 +16,16 @@ import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.mozilla.fenix.databinding.QuicksettingsWebsiteInfoBinding
import org.mozilla.fenix.helpers.FenixRobolectricTestRunner
@RunWith(FenixRobolectricTestRunner::class)
class WebsiteInfoViewTest {
private lateinit var view: WebsiteInfoView
private lateinit var binding: QuicksettingsWebsiteInfoBinding
@Before
fun setup() {
view = WebsiteInfoView(FrameLayout(testContext))
binding = view.binding
}
@Test
@ -39,10 +39,10 @@ class WebsiteInfoViewTest {
)
)
assertEquals("https://mozilla.org", binding.url.text)
assertEquals("Mozilla", binding.title.text)
assertEquals("Secure Connection", binding.securityInfo.text)
assertFalse(binding.certificateInfo.isVisible)
assertEquals("https://mozilla.org", view.url.text)
assertEquals("Mozilla", view.title.text)
assertEquals("Secure Connection", view.securityInfo.text)
assertFalse(view.certificateInfo.isVisible)
}
@Test
@ -56,8 +56,8 @@ class WebsiteInfoViewTest {
)
)
assertEquals("Insecure Connection", binding.securityInfo.text)
assertEquals("Verified By: Certificate", binding.certificateInfo.text)
assertTrue(binding.certificateInfo.isVisible)
assertEquals("Insecure Connection", view.securityInfo.text)
assertEquals("Verified By: Certificate", view.certificateInfo.text)
assertTrue(view.certificateInfo.isVisible)
}
}