2019-02-25 23:05:19 +01:00
|
|
|
/* 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/. */
|
|
|
|
|
2019-09-14 06:29:11 +02:00
|
|
|
package org.mozilla.fenix.settings.sitepermissions
|
2019-02-25 23:05:19 +01:00
|
|
|
|
|
|
|
import android.os.Bundle
|
2019-03-27 17:18:37 +01:00
|
|
|
import androidx.navigation.Navigation
|
2019-03-22 15:23:16 +01:00
|
|
|
import androidx.preference.Preference
|
2019-03-27 17:18:37 +01:00
|
|
|
import androidx.preference.Preference.OnPreferenceClickListener
|
2019-02-25 23:05:19 +01:00
|
|
|
import androidx.preference.PreferenceFragmentCompat
|
|
|
|
import org.mozilla.fenix.R
|
2019-08-21 17:38:14 +02:00
|
|
|
import org.mozilla.fenix.ext.getPreferenceKey
|
2019-09-10 19:11:58 +02:00
|
|
|
import org.mozilla.fenix.ext.settings
|
2019-11-25 21:36:47 +01:00
|
|
|
import org.mozilla.fenix.ext.showToolbar
|
2019-09-14 06:29:11 +02:00
|
|
|
import org.mozilla.fenix.settings.PhoneFeature
|
2019-02-25 23:05:19 +01:00
|
|
|
|
2019-03-27 17:18:37 +01:00
|
|
|
@SuppressWarnings("TooManyFunctions")
|
2019-02-25 23:05:19 +01:00
|
|
|
class SitePermissionsFragment : PreferenceFragmentCompat() {
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
super.onCreate(savedInstanceState)
|
2019-11-25 21:36:47 +01:00
|
|
|
showToolbar(getString(R.string.preferences_site_permissions))
|
2019-02-25 23:05:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
|
|
|
setPreferencesFromResource(R.xml.site_permissions_preferences, rootKey)
|
|
|
|
}
|
2019-03-21 19:04:24 +01:00
|
|
|
|
2019-03-22 15:23:16 +01:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
setupPreferences()
|
|
|
|
}
|
|
|
|
|
2019-03-21 19:04:24 +01:00
|
|
|
private fun setupPreferences() {
|
2019-03-22 15:23:16 +01:00
|
|
|
bindCategoryPhoneFeatures()
|
2019-04-11 22:04:51 +02:00
|
|
|
bindExceptions()
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun bindExceptions() {
|
2019-08-21 17:38:14 +02:00
|
|
|
val keyExceptions = getPreferenceKey(R.string.pref_key_show_site_exceptions)
|
2019-04-11 22:04:51 +02:00
|
|
|
val exceptionsCategory = requireNotNull<Preference>(findPreference(keyExceptions))
|
|
|
|
|
|
|
|
exceptionsCategory.onPreferenceClickListener = OnPreferenceClickListener {
|
|
|
|
val directions = SitePermissionsFragmentDirections.actionSitePermissionsToExceptions()
|
|
|
|
Navigation.findNavController(view!!).navigate(directions)
|
|
|
|
true
|
|
|
|
}
|
2019-03-22 15:23:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private fun bindCategoryPhoneFeatures() {
|
2020-02-25 16:36:19 +01:00
|
|
|
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)
|
2019-08-21 17:38:14 +02:00
|
|
|
}
|
2019-03-29 18:57:49 +01:00
|
|
|
|
2019-08-21 17:38:14 +02:00
|
|
|
private fun initPhoneFeature(phoneFeature: PhoneFeature) {
|
|
|
|
val context = requireContext()
|
2019-09-24 19:33:46 +02:00
|
|
|
val settings = context.settings()
|
2019-03-29 18:57:49 +01:00
|
|
|
|
2019-08-21 17:38:14 +02:00
|
|
|
val summary = phoneFeature.getActionLabel(context, settings = settings)
|
|
|
|
val preferenceKey = phoneFeature.getPreferenceKey(context)
|
2019-03-27 17:18:37 +01:00
|
|
|
|
2019-08-21 17:38:14 +02:00
|
|
|
val cameraPhoneFeatures: Preference = requireNotNull(findPreference(preferenceKey))
|
2019-03-29 18:57:49 +01:00
|
|
|
cameraPhoneFeatures.summary = summary
|
2019-03-27 17:18:37 +01:00
|
|
|
|
|
|
|
cameraPhoneFeatures.onPreferenceClickListener = OnPreferenceClickListener {
|
|
|
|
navigateToPhoneFeature(phoneFeature)
|
|
|
|
true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private fun navigateToPhoneFeature(phoneFeature: PhoneFeature) {
|
2019-09-14 06:29:11 +02:00
|
|
|
val directions = SitePermissionsFragmentDirections
|
|
|
|
.actionSitePermissionsToManagePhoneFeatures(phoneFeature.id)
|
2019-03-27 17:18:37 +01:00
|
|
|
Navigation.findNavController(view!!).navigate(directions)
|
2019-03-21 19:04:24 +01:00
|
|
|
}
|
2019-02-25 23:05:19 +01:00
|
|
|
}
|