mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-03 23:15:31 +00:00
[fenix] For https://github.com/mozilla-mobile/fenix/issues/20601: Use View binding in quick settings.
This commit is contained in:
parent
bd036901ae
commit
a710775406
@ -25,8 +25,6 @@ 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
|
||||
@ -35,6 +33,7 @@ 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
|
||||
@ -55,6 +54,8 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
|
||||
private var tryToRequestPermissions: Boolean = false
|
||||
private val args by navArgs<QuickSettingsSheetDialogFragmentArgs>()
|
||||
|
||||
private lateinit var binding: FragmentQuickSettingsDialogSheetBinding
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
// https://github.com/mozilla-mobile/fenix/issues/19920
|
||||
override fun onCreateView(
|
||||
@ -64,7 +65,10 @@ 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,
|
||||
@ -98,9 +102,9 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
|
||||
|
||||
interactor = QuickSettingsInteractor(quickSettingsController)
|
||||
|
||||
websiteInfoView = WebsiteInfoView(rootView.websiteInfoLayout)
|
||||
websiteInfoView = WebsiteInfoView(binding.websiteInfoLayout)
|
||||
websitePermissionsView =
|
||||
WebsitePermissionsView(rootView.websitePermissionsLayout, interactor)
|
||||
WebsitePermissionsView(binding.websitePermissionsLayout, interactor)
|
||||
|
||||
return rootView
|
||||
}
|
||||
@ -152,7 +156,8 @@ 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.
|
||||
@ -187,7 +192,7 @@ class QuickSettingsSheetDialogFragment : AppCompatDialogFragment() {
|
||||
requestCode == REQUEST_CODE_QUICK_SETTINGS_PERMISSIONS && grantResults.all { it == PERMISSION_GRANTED }
|
||||
|
||||
private fun showPermissionsView() {
|
||||
websitePermissionsGroup.isVisible = true
|
||||
binding.websitePermissionsGroup.isVisible = true
|
||||
}
|
||||
|
||||
private fun launchIntentReceiver() {
|
||||
|
@ -5,14 +5,12 @@
|
||||
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.
|
||||
@ -23,10 +21,12 @@ import org.mozilla.fenix.R
|
||||
*/
|
||||
class WebsiteInfoView(
|
||||
container: ViewGroup
|
||||
) : LayoutContainer {
|
||||
|
||||
override val containerView: View = LayoutInflater.from(container.context)
|
||||
.inflate(R.layout.quicksettings_website_info, container, true)
|
||||
) {
|
||||
val binding = QuicksettingsWebsiteInfoBinding.inflate(
|
||||
LayoutInflater.from(container.context),
|
||||
container,
|
||||
true
|
||||
)
|
||||
|
||||
/**
|
||||
* Allows changing what this View displays.
|
||||
@ -41,24 +41,25 @@ class WebsiteInfoView(
|
||||
}
|
||||
|
||||
private fun bindUrl(websiteUrl: String) {
|
||||
url.text = websiteUrl
|
||||
binding.url.text = websiteUrl
|
||||
}
|
||||
|
||||
private fun bindTitle(websiteTitle: String) {
|
||||
title.text = websiteTitle
|
||||
binding.title.text = websiteTitle
|
||||
}
|
||||
|
||||
private fun bindCertificateName(cert: String) {
|
||||
val certificateLabel = containerView.context.getString(R.string.certificate_info_verified_by, cert)
|
||||
certificateInfo.text = certificateLabel
|
||||
certificateInfo.isVisible = cert.isNotEmpty()
|
||||
val certificateLabel =
|
||||
binding.root.context.getString(R.string.certificate_info_verified_by, cert)
|
||||
binding.certificateInfo.text = certificateLabel
|
||||
binding.certificateInfo.isVisible = cert.isNotEmpty()
|
||||
}
|
||||
|
||||
private fun bindSecurityInfo(uiValues: WebsiteSecurityUiValues) {
|
||||
val tint = getColor(containerView.context, uiValues.iconTintRes)
|
||||
securityInfo.setText(uiValues.securityInfoRes)
|
||||
securityInfoIcon.setImageDrawable(
|
||||
containerView.context.getDrawableWithTint(uiValues.iconRes, tint)
|
||||
val tint = getColor(binding.root.context, uiValues.iconTintRes)
|
||||
binding.securityInfo.setText(uiValues.securityInfoRes)
|
||||
binding.securityInfoIcon.setImageDrawable(
|
||||
binding.root.context.getDrawableWithTint(uiValues.iconRes, tint)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -14,9 +14,8 @@ 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
|
||||
@ -65,38 +64,38 @@ interface WebsitePermissionInteractor {
|
||||
* @param interactor [WebsitePermissionInteractor] which will have delegated to all user interactions.
|
||||
*/
|
||||
class WebsitePermissionsView(
|
||||
override val containerView: ViewGroup,
|
||||
containerView: ViewGroup,
|
||||
val interactor: WebsitePermissionInteractor
|
||||
) : LayoutContainer {
|
||||
) {
|
||||
private val context = containerView.context
|
||||
|
||||
val view: View = LayoutInflater.from(context)
|
||||
.inflate(R.layout.quicksettings_permissions, containerView, true)
|
||||
val binding =
|
||||
QuicksettingsPermissionsBinding.inflate(LayoutInflater.from(context), containerView, true)
|
||||
|
||||
@VisibleForTesting
|
||||
internal var permissionViews: Map<PhoneFeature, PermissionViewHolder> = EnumMap(
|
||||
mapOf(
|
||||
CAMERA to ToggleablePermission(view.cameraLabel, view.cameraStatus),
|
||||
LOCATION to ToggleablePermission(view.locationLabel, view.locationStatus),
|
||||
CAMERA to ToggleablePermission(binding.cameraLabel, binding.cameraStatus),
|
||||
LOCATION to ToggleablePermission(binding.locationLabel, binding.locationStatus),
|
||||
MICROPHONE to ToggleablePermission(
|
||||
view.microphoneLabel,
|
||||
view.microphoneStatus
|
||||
binding.microphoneLabel,
|
||||
binding.microphoneStatus
|
||||
),
|
||||
NOTIFICATION to ToggleablePermission(
|
||||
view.notificationLabel,
|
||||
view.notificationStatus
|
||||
binding.notificationLabel,
|
||||
binding.notificationStatus
|
||||
),
|
||||
PERSISTENT_STORAGE to ToggleablePermission(
|
||||
view.persistentStorageLabel,
|
||||
view.persistentStorageStatus
|
||||
binding.persistentStorageLabel,
|
||||
binding.persistentStorageStatus
|
||||
),
|
||||
MEDIA_KEY_SYSTEM_ACCESS to ToggleablePermission(
|
||||
view.mediaKeySystemAccessLabel,
|
||||
view.mediaKeySystemAccessStatus
|
||||
binding.mediaKeySystemAccessLabel,
|
||||
binding.mediaKeySystemAccessStatus
|
||||
),
|
||||
AUTOPLAY to SpinnerPermission(
|
||||
view.autoplayLabel,
|
||||
view.autoplayStatus
|
||||
binding.autoplayLabel,
|
||||
binding.autoplayStatus
|
||||
)
|
||||
)
|
||||
)
|
||||
|
@ -6,9 +6,6 @@ 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
|
||||
@ -16,16 +13,19 @@ 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", view.url.text)
|
||||
assertEquals("Mozilla", view.title.text)
|
||||
assertEquals("Secure Connection", view.securityInfo.text)
|
||||
assertFalse(view.certificateInfo.isVisible)
|
||||
assertEquals("https://mozilla.org", binding.url.text)
|
||||
assertEquals("Mozilla", binding.title.text)
|
||||
assertEquals("Secure Connection", binding.securityInfo.text)
|
||||
assertFalse(binding.certificateInfo.isVisible)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -56,8 +56,8 @@ class WebsiteInfoViewTest {
|
||||
)
|
||||
)
|
||||
|
||||
assertEquals("Insecure Connection", view.securityInfo.text)
|
||||
assertEquals("Verified By: Certificate", view.certificateInfo.text)
|
||||
assertTrue(view.certificateInfo.isVisible)
|
||||
assertEquals("Insecure Connection", binding.securityInfo.text)
|
||||
assertEquals("Verified By: Certificate", binding.certificateInfo.text)
|
||||
assertTrue(binding.certificateInfo.isVisible)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user