mirror of
https://github.com/fork-maintainers/iceraven-browser
synced 2024-11-17 15:26:23 +00:00
[fenix] Replace PhoneFeature.getPreferenceKey
This commit is contained in:
parent
068d14a923
commit
5d852c326c
@ -85,17 +85,27 @@ enum class PhoneFeature(val androidPermissionsList: Array<String>) : Parcelable
|
||||
}
|
||||
}
|
||||
|
||||
fun getPreferenceKey(context: Context): String {
|
||||
/**
|
||||
* Returns a resource ID from preference_keys representing the preference corresponding
|
||||
* to this phone feature.
|
||||
*/
|
||||
@StringRes
|
||||
fun getPreferenceId(): Int {
|
||||
return when (this) {
|
||||
CAMERA -> context.getPreferenceKey(R.string.pref_key_phone_feature_camera)
|
||||
LOCATION -> context.getPreferenceKey(R.string.pref_key_phone_feature_location)
|
||||
MICROPHONE -> context.getPreferenceKey(R.string.pref_key_phone_feature_microphone)
|
||||
NOTIFICATION -> context.getPreferenceKey(R.string.pref_key_phone_feature_notification)
|
||||
AUTOPLAY_AUDIBLE -> context.getPreferenceKey(R.string.pref_key_browser_feature_autoplay_audible)
|
||||
AUTOPLAY_INAUDIBLE -> context.getPreferenceKey(R.string.pref_key_browser_feature_autoplay_inaudible)
|
||||
CAMERA -> R.string.pref_key_phone_feature_camera
|
||||
LOCATION -> R.string.pref_key_phone_feature_location
|
||||
MICROPHONE -> R.string.pref_key_phone_feature_microphone
|
||||
NOTIFICATION -> R.string.pref_key_phone_feature_notification
|
||||
AUTOPLAY_AUDIBLE -> R.string.pref_key_browser_feature_autoplay_audible
|
||||
AUTOPLAY_INAUDIBLE -> R.string.pref_key_browser_feature_autoplay_inaudible
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the key representing the preference corresponding to this phone feature.
|
||||
*/
|
||||
fun getPreferenceKey(context: Context): String = context.getPreferenceKey(getPreferenceId())
|
||||
|
||||
fun getAction(settings: Settings): SitePermissionsRules.Action =
|
||||
settings.getSitePermissionsPhoneFeatureAction(this, getDefault())
|
||||
|
||||
|
@ -64,8 +64,7 @@ class SitePermissionsDetailsExceptionsFragment : PreferenceFragmentCompat() {
|
||||
|
||||
private fun initPhoneFeature(phoneFeature: PhoneFeature) {
|
||||
val summary = phoneFeature.getActionLabel(requireContext(), sitePermissions)
|
||||
val keyPreference = phoneFeature.getPreferenceKey(requireContext())
|
||||
val cameraPhoneFeatures: Preference = requireNotNull(findPreference(keyPreference))
|
||||
val cameraPhoneFeatures = requirePreference<Preference>(phoneFeature.getPreferenceId())
|
||||
cameraPhoneFeatures.summary = summary
|
||||
|
||||
cameraPhoneFeatures.onPreferenceClickListener = Preference.OnPreferenceClickListener {
|
||||
|
@ -14,6 +14,7 @@ import org.mozilla.fenix.ext.getPreferenceKey
|
||||
import org.mozilla.fenix.ext.settings
|
||||
import org.mozilla.fenix.ext.showToolbar
|
||||
import org.mozilla.fenix.settings.PhoneFeature
|
||||
import org.mozilla.fenix.settings.requirePreference
|
||||
|
||||
@SuppressWarnings("TooManyFunctions")
|
||||
class SitePermissionsFragment : PreferenceFragmentCompat() {
|
||||
@ -64,9 +65,8 @@ class SitePermissionsFragment : PreferenceFragmentCompat() {
|
||||
} else {
|
||||
null
|
||||
}
|
||||
val preferenceKey = phoneFeature.getPreferenceKey(context)
|
||||
|
||||
val cameraPhoneFeatures: Preference = requireNotNull(findPreference(preferenceKey))
|
||||
val cameraPhoneFeatures = requirePreference<Preference>(phoneFeature.getPreferenceId())
|
||||
cameraPhoneFeatures.summary = autoplaySummary ?: summary
|
||||
|
||||
cameraPhoneFeatures.onPreferenceClickListener = OnPreferenceClickListener {
|
||||
|
Loading…
Reference in New Issue
Block a user