You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
3.2 KiB
Kotlin
83 lines
3.2 KiB
Kotlin
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
package org.mozilla.fenix.settings.sitepermissions
|
|
|
|
import android.os.Bundle
|
|
import androidx.navigation.Navigation
|
|
import androidx.preference.Preference
|
|
import androidx.preference.Preference.OnPreferenceClickListener
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
import org.mozilla.fenix.R
|
|
import org.mozilla.fenix.components.metrics.Event
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
|
import org.mozilla.fenix.ext.navigateBlockingForAsyncNavGraph
|
|
import org.mozilla.fenix.ext.requireComponents
|
|
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() {
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
setPreferencesFromResource(R.xml.site_permissions_preferences, rootKey)
|
|
}
|
|
|
|
override fun onResume() {
|
|
super.onResume()
|
|
showToolbar(getString(R.string.preferences_site_permissions))
|
|
setupPreferences()
|
|
}
|
|
|
|
private fun setupPreferences() {
|
|
bindCategoryPhoneFeatures()
|
|
bindExceptions()
|
|
}
|
|
|
|
private fun bindExceptions() {
|
|
val keyExceptions = getPreferenceKey(R.string.pref_key_show_site_exceptions)
|
|
val exceptionsCategory = requireNotNull<Preference>(findPreference(keyExceptions))
|
|
|
|
exceptionsCategory.onPreferenceClickListener = OnPreferenceClickListener {
|
|
val directions = SitePermissionsFragmentDirections.actionSitePermissionsToExceptions()
|
|
Navigation.findNavController(requireView()).navigateBlockingForAsyncNavGraph(directions)
|
|
true
|
|
}
|
|
}
|
|
|
|
private fun bindCategoryPhoneFeatures() {
|
|
PhoneFeature.values()
|
|
// Autoplay inaudible should be set in the same menu as autoplay audible, so it does
|
|
// not need to be bound
|
|
.filter { it != PhoneFeature.AUTOPLAY_INAUDIBLE }
|
|
.forEach(::initPhoneFeature)
|
|
}
|
|
|
|
private fun initPhoneFeature(phoneFeature: PhoneFeature) {
|
|
val context = requireContext()
|
|
val settings = context.settings()
|
|
|
|
val cameraPhoneFeatures = requirePreference<Preference>(phoneFeature.getPreferenceId())
|
|
cameraPhoneFeatures.summary = phoneFeature.getActionLabel(context, settings = settings)
|
|
|
|
cameraPhoneFeatures.onPreferenceClickListener = OnPreferenceClickListener {
|
|
navigateToPhoneFeature(phoneFeature)
|
|
true
|
|
}
|
|
}
|
|
|
|
private fun navigateToPhoneFeature(phoneFeature: PhoneFeature) {
|
|
val directions = SitePermissionsFragmentDirections
|
|
.actionSitePermissionsToManagePhoneFeatures(phoneFeature)
|
|
|
|
if (phoneFeature == PhoneFeature.AUTOPLAY_AUDIBLE) {
|
|
requireComponents.analytics.metrics.track(Event.AutoPlaySettingVisited)
|
|
}
|
|
|
|
Navigation.findNavController(requireView()).navigateBlockingForAsyncNavGraph(directions)
|
|
}
|
|
}
|