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/. */
|
|
|
|
|
|
|
|
package org.mozilla.fenix.settings
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
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-04-02 05:40:40 +02:00
|
|
|
import org.mozilla.fenix.settings.PhoneFeature.CAMERA
|
2019-08-20 19:47:55 +02:00
|
|
|
import org.mozilla.fenix.settings.PhoneFeature.LOCATION
|
2019-04-02 05:40:40 +02:00
|
|
|
import org.mozilla.fenix.settings.PhoneFeature.MICROPHONE
|
2019-08-20 19:47:55 +02:00
|
|
|
import org.mozilla.fenix.settings.PhoneFeature.NOTIFICATION
|
2019-03-29 18:57:49 +01:00
|
|
|
import org.mozilla.fenix.utils.Settings
|
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-04-10 00:36:21 +02:00
|
|
|
(activity as AppCompatActivity).title = getString(R.string.preferences_site_permissions)
|
2019-02-25 23:05:19 +01:00
|
|
|
(activity as AppCompatActivity).supportActionBar?.show()
|
|
|
|
}
|
|
|
|
|
|
|
|
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() {
|
|
|
|
val keyExceptions = getString(R.string.pref_key_show_site_exceptions)
|
|
|
|
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() {
|
2019-03-29 18:57:49 +01:00
|
|
|
val settings = Settings.getInstance(requireContext())
|
|
|
|
|
|
|
|
val cameraAction = settings
|
2019-08-20 19:47:55 +02:00
|
|
|
.sitePermissionsPhoneFeatureCameraAction
|
2019-03-29 18:57:49 +01:00
|
|
|
.toString(requireContext())
|
|
|
|
|
|
|
|
val locationAction = settings
|
2019-08-20 19:47:55 +02:00
|
|
|
.sitePermissionsPhoneFeatureLocation
|
2019-03-29 18:57:49 +01:00
|
|
|
.toString(requireContext())
|
|
|
|
|
|
|
|
val microPhoneAction = settings
|
2019-08-20 19:47:55 +02:00
|
|
|
.sitePermissionsPhoneFeatureMicrophoneAction
|
2019-03-29 18:57:49 +01:00
|
|
|
.toString(requireContext())
|
|
|
|
|
|
|
|
val notificationAction = settings
|
2019-08-20 19:47:55 +02:00
|
|
|
.sitePermissionsPhoneFeatureNotificationAction
|
2019-03-29 18:57:49 +01:00
|
|
|
.toString(requireContext())
|
|
|
|
|
|
|
|
initPhoneFeature(CAMERA, cameraAction)
|
|
|
|
initPhoneFeature(LOCATION, locationAction)
|
|
|
|
initPhoneFeature(MICROPHONE, microPhoneAction)
|
|
|
|
initPhoneFeature(NOTIFICATION, notificationAction)
|
2019-03-27 17:18:37 +01:00
|
|
|
}
|
|
|
|
|
2019-03-29 18:57:49 +01:00
|
|
|
private fun initPhoneFeature(phoneFeature: PhoneFeature, summary: String) {
|
2019-04-11 22:04:51 +02:00
|
|
|
val keyPreference = phoneFeature.getPreferenceKey(requireContext())
|
2019-03-27 17:18:37 +01:00
|
|
|
val cameraPhoneFeatures: Preference = requireNotNull(findPreference(keyPreference))
|
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) {
|
|
|
|
val directions = SitePermissionsFragmentDirections.actionSitePermissionsToManagePhoneFeatures(phoneFeature.id)
|
|
|
|
Navigation.findNavController(view!!).navigate(directions)
|
2019-03-21 19:04:24 +01:00
|
|
|
}
|
2019-02-25 23:05:19 +01:00
|
|
|
}
|