Commit 083d78bb authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Use the correct preferences/listeners based on the current category

parent 41576dbb
......@@ -52,10 +52,23 @@ class SettingsFragment : PreferenceFragmentCompat() {
SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
context?.getPreferences()?.notifyPreferenceChangedFromExternal(key)
}
private val category:SettingsActivity.Category by lazy {
arguments!!.getSerializable("category") as SettingsActivity.Category
}
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
log("Adding preferences from resources...")
setPreferencesFromResource(R.xml.preferences, rootKey)
val resource = when(category) {
SettingsActivity.Category.GENERAL -> R.xml.preferences_general
SettingsActivity.Category.NOTIFICATION -> R.xml.preferences_notification
SettingsActivity.Category.PIN -> R.xml.preferences_pin
SettingsActivity.Category.CACHE -> R.xml.preferences_cache
SettingsActivity.Category.LOGGING -> R.xml.preferences_logging
SettingsActivity.Category.IP -> R.xml.preferences_ip
SettingsActivity.Category.NETWORK -> R.xml.preferences_network
SettingsActivity.Category.QUERIES -> R.xml.preferences_queries
}
setPreferencesFromResource(resource, rootKey)
log("Preferences added.")
werePreferencesAdded = true
createPreferenceListener()
......@@ -102,14 +115,16 @@ class SettingsFragment : PreferenceFragmentCompat() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
log("Fragment created")
processGeneralCategory()
processCacheCategory()
processLoggingCategory()
processIPCategory()
processNetworkCategory()
processQueryCategory()
processPinCategory()
processNotificationCategory()
when(category) {
SettingsActivity.Category.GENERAL -> processGeneralCategory()
SettingsActivity.Category.NOTIFICATION -> processNotificationCategory()
SettingsActivity.Category.PIN -> processPinCategory()
SettingsActivity.Category.CACHE -> processCacheCategory()
SettingsActivity.Category.LOGGING -> processLoggingCategory()
SettingsActivity.Category.IP -> processIPCategory()
SettingsActivity.Category.NETWORK -> processNetworkCategory()
SettingsActivity.Category.QUERIES -> processQueryCategory()
}
}
private fun processNotificationCategory() {
......
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/preference_category_general">
<ListPreference
android:defaultValue="1"
android:entries="@array/theme"
android:entryValues="@array/themeValues"
android:key="theme"
android:summary="@string/summary_theme"
android:title="@string/title_theme"/>
<CheckBoxPreference
android:defaultValue="true"
android:summary="@string/summary_start_on_boot"
android:title="@string/title_start_on_boot"
android:key="start_on_boot"/>
<CheckBoxPreference
android:key="start_after_update"
android:title="@string/title_start_after_update"
android:summary="@string/summary_start_after_update"
android:defaultValue="true"/>
<Preference
android:key="app_exclusion_list"
android:title="@string/title_excluded_apps"
android:summary="@string/summary_excluded_apps"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_notification">
<CheckBoxPreference
android:key="show_notification_on_lockscreen"
android:title="@string/title_show_notification_on_lockscreen"
android:defaultValue="true"
android:summary="@string/summary_show_notification_on_lockscreen"/>
<CheckBoxPreference
android:key="hide_notification_icon"
android:title="@string/title_notification_hide_icon"
android:summary="@string/summary_notification_hide_icon"
android:defaultValue="false"
/>
<CheckBoxPreference
android:key="notification_allow_stop"
android:title="@string/title_notification_allow_stop"
android:summary="@string/summary_notification_allow_stop"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="notification_allow_pause"
android:title="@string/title_notification_allow_pause"
android:summary="@string/summary_notification_allow_pause"
android:defaultValue="true"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_pin">
<CheckBoxPreference
android:key="enable_pin"
android:title="@string/title_preference_enable_pin"
android:defaultValue="false"
android:summary="@string/summary_preference_enable_pin"/>
<CheckBoxPreference
android:key="pin_allow_fingerprint"
android:dependency="enable_pin"
android:title="@string/title_preference_pin_use_fingerprint"
android:defaultValue="true"
android:summary="@string/summary_preference_pin_use_fingerprint"/>
<EditTextPreference
android:title="@string/title_preference_change_pin"
android:key="pin"
android:dependency="enable_pin"
android:inputType="number"
android:digits="012345789"
android:defaultValue="1234"
android:summary="@string/summary_preference_change_pin"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_cache">
<CheckBoxPreference
android:key="dnscache_enabled"
android:title="@string/title_dnscache_enabled"
android:summary="@string/summary_dnscache_enabled"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="dnscache_keepacrosslaunches"
android:title="@string/title_dnscache_keepacrosslaunches"
android:defaultValue="false"
android:summary="@string/summary_dnscache_keepacrosslaunches"/>
<EditTextPreference
android:key="dnscache_maxsize"
android:summary="@string/summary_dnscache_maxsize"
android:title="@string/title_dnscache_maxsize"
android:inputType="number"
android:digits="012345789"
android:defaultValue="1000"/>
<CheckBoxPreference
android:key="dnscache_use_default_time"
android:defaultValue="true"
android:summary="@string/summary_dnscache_usedefaulttimes"
android:title="@string/title_dnscache_usedefaulttimes"
/>
<EditTextPreference
android:title="@string/title_dnscache_minimum_cache_time"
android:summary="@string/summary_dnscache_minimum_cache_time"
android:key="dnscache_minimum_time"
android:inputType="number"
android:digits="012345789"
android:defaultValue="10"/>
<EditTextPreference
android:key="dnscache_custom_time"
android:inputType="number"
android:digits="012345789"
android:summary="@string/summary_dnscache_customcachetime"
android:title="@string/title_dnscache_customcachetime"
android:defaultValue="100"/>
<EditTextPreference
android:key="dnscache_nxdomain_cachetime"
android:inputType="number"
android:digits="0123456789"
android:summary="@string/summary_dnscache_nxdomaincachetime"
android:defaultValue="1800"
android:title="@string/title_dnscache_nxdomaincachetime"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_logging">
<CheckBoxPreference
android:title="@string/title_enable_logging"
android:summary="@string/summary_enable_logging"
android:key="logging_enabled"/>
<CheckBoxPreference
android:title="@string/title_advanced_logging"
android:summary="@string/summary_advanced_logging"
android:dependency="logging_enabled"
android:key="advanced_logging"/>
<Preference
android:key="send_logs"
android:title="@string/title_send_logs"
android:summary="@string/summary_send_logs"/>
<Preference
android:key="delete_logs"
android:title="@string/title_delete_all_logs"
android:summary="@string/summary_delete_all_logs"/>
<CheckBoxPreference
android:key="enable_sentry"
android:title="@string/title_enable_sentry"
android:defaultValue="false"
android:summary="@string/summary_enable_sentry"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_ip">
<CheckBoxPreference
android:key="ipv4_enabled"
android:title="@string/title_enable_ipv4"
android:defaultValue="true"
android:summary="@string/summary_enable_ipv4"/>
<CheckBoxPreference
android:key="allow_ipv4_traffic"
android:title="@string/title_allow_ipv4_traffic"
android:summary="@string/summary_allow_ipv4_traffic"
/>
<CheckBoxPreference
android:key="force_ipv4"
android:defaultValue="false"
android:title="@string/title_force_ipv4"
android:summary="@string/summary_force_ipv4"/>
<CheckBoxPreference
android:key="ipv6_enabled"
android:title="@string/title_enable_ipv6"
android:defaultValue="true"
android:summary="@string/summary_enable_ipv6"/>
<CheckBoxPreference
android:key="allow_ipv6_traffic"
android:title="@string/title_allow_ipv6_traffic"
android:summary="@string/summary_allow_ipv6_traffic"
/>
<CheckBoxPreference
android:key="force_ipv6"
android:defaultValue="false"
android:title="@string/title_force_ipv6"
android:summary="@string/summary_force_ipv6"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_network">
<CheckBoxPreference
android:key="disallow_other_vpns"
android:title="@string/title_disallow_other_vpns"
android:summary="@string/summary_disallow_other_vpns"
android:defaultValue="false"/>
<CheckBoxPreference
android:key="catch_known_servers"
android:title="@string/title_catch_other_dns_servers"
android:summary="@string/summary_catch_other_dns_servers"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="bypass_searchdomains"
android:title="@string/title_bypass_searchdomains"
android:defaultValue="true"
android:summary="@string/summary_bypass_searchdomains"/>
<CheckBoxPreference
android:key="pause_on_captive_portal"
android:defaultValue="true"
android:title="@string/title_pause_on_captiveportal"
android:summary="@string/summary_pause_on_captiveportal"/>
<CheckBoxPreference
android:key="show_no_connection_notification"
android:title="@string/title_show_noconnection_notification"
android:summary="@string/summary_show_noconnection_notification"
android:defaultValue="false"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/preference_category_querylogging">
<CheckBoxPreference
android:key="log_dns_queries"
android:title="@string/title_log_queries"
android:summary="@string/summary_log_queries"
android:defaultValue="false"/>
<Preference
android:key="generate_queries"
android:title="Generate queries"/>
<Preference
android:key="export_dns_queries"
android:title="@string/title_export_queries"
android:dependency="log_dns_queries"
android:summary="@string/summary_export_queries"/>
<Preference
android:key="clear_dns_queries"
android:title="@string/title_delete_queries"
android:summary="@string/summary_delete_queries"
android:dependency="log_dns_queries"
/>
</PreferenceCategory>
</PreferenceScreen>
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment