forked from github/wulkanowy-mirror
Move default preferences values to separate file (#555)
This commit is contained in:
parent
360dfbcdb5
commit
b602657d55
@ -12,52 +12,60 @@ class PreferencesRepository @Inject constructor(
|
||||
val context: Context
|
||||
) {
|
||||
val startMenuIndex: Int
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_start_menu), "0")?.toIntOrNull() ?: 0
|
||||
get() = getString(R.string.pref_key_start_menu, R.string.pref_default_startup).toInt()
|
||||
|
||||
val isShowPresent: Boolean
|
||||
get() = sharedPref.getBoolean(context.getString(R.string.pref_key_attendance_present), true)
|
||||
get() = getBoolean(R.string.pref_key_attendance_present, R.bool.pref_default_attendance_present)
|
||||
|
||||
val gradeAverageMode: String
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_average_mode), "only_one_semester") ?: "only_one_semester"
|
||||
get() = getString(R.string.pref_key_grade_average_mode, R.string.pref_default_grade_average_mode)
|
||||
|
||||
val gradeAverageForceCalc: Boolean
|
||||
get() = sharedPref.getBoolean(context.getString(R.string.pref_key_grade_average_force_calc), false)
|
||||
get() = getBoolean(R.string.pref_key_grade_average_force_calc, R.bool.pref_default_grade_average_force_calc)
|
||||
|
||||
val isGradeExpandable: Boolean
|
||||
get() = !sharedPref.getBoolean(context.getString(R.string.pref_key_expand_grade), false)
|
||||
get() = !getBoolean(R.string.pref_key_expand_grade, R.bool.pref_default_expand_grade)
|
||||
|
||||
val appThemeKey: String = context.getString(R.string.pref_key_app_theme)
|
||||
val appThemeKey = context.getString(R.string.pref_key_app_theme)
|
||||
val appTheme: String
|
||||
get() = sharedPref.getString(appThemeKey, "light") ?: "light"
|
||||
get() = getString(appThemeKey, R.string.pref_default_app_theme)
|
||||
|
||||
val gradeColorTheme: String
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_color_scheme), "vulcan") ?: "vulcan"
|
||||
get() = getString(R.string.pref_key_grade_color_scheme, R.string.pref_default_grade_color_scheme)
|
||||
|
||||
val serviceEnableKey: String = context.getString(R.string.pref_key_services_enable)
|
||||
val serviceEnableKey = context.getString(R.string.pref_key_services_enable)
|
||||
val isServiceEnabled: Boolean
|
||||
get() = sharedPref.getBoolean(serviceEnableKey, true)
|
||||
get() = getBoolean(serviceEnableKey, R.bool.pref_default_services_enable)
|
||||
|
||||
val servicesIntervalKey: String = context.getString(R.string.pref_key_services_interval)
|
||||
val servicesIntervalKey = context.getString(R.string.pref_key_services_interval)
|
||||
val servicesInterval: Long
|
||||
get() = sharedPref.getString(servicesIntervalKey, "60")?.toLongOrNull() ?: 60
|
||||
get() = getString(servicesIntervalKey, R.string.pref_default_services_interval).toLong()
|
||||
|
||||
val servicesOnlyWifiKey: String = context.getString(R.string.pref_key_services_wifi_only)
|
||||
val servicesOnlyWifiKey = context.getString(R.string.pref_key_services_wifi_only)
|
||||
val isServicesOnlyWifi: Boolean
|
||||
get() = sharedPref.getBoolean(servicesOnlyWifiKey, false)
|
||||
get() = getBoolean(servicesOnlyWifiKey, R.bool.pref_default_services_wifi_only)
|
||||
|
||||
val isNotificationsEnable: Boolean
|
||||
get() = sharedPref.getBoolean(context.getString(R.string.pref_key_notifications_enable), true)
|
||||
get() = getBoolean(R.string.pref_key_notifications_enable, R.bool.pref_default_notifications_enable)
|
||||
|
||||
val isDebugNotificationEnableKey: String = context.getString(R.string.pref_key_notification_debug)
|
||||
val isDebugNotificationEnableKey = context.getString(R.string.pref_key_notification_debug)
|
||||
val isDebugNotificationEnable: Boolean
|
||||
get() = sharedPref.getBoolean(isDebugNotificationEnableKey, false)
|
||||
get() = getBoolean(isDebugNotificationEnableKey, R.bool.pref_default_notification_debug)
|
||||
|
||||
val gradePlusModifier: Double
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier_plus), "0.0")?.toDouble() ?: 0.0
|
||||
get() = getString(R.string.pref_key_grade_modifier_plus, R.string.pref_default_grade_modifier_plus).toDouble()
|
||||
|
||||
val gradeMinusModifier: Double
|
||||
get() = sharedPref.getString(context.getString(R.string.pref_key_grade_modifier_minus), "0.0")?.toDouble() ?: 0.0
|
||||
get() = getString(R.string.pref_key_grade_modifier_minus, R.string.pref_default_grade_modifier_minus).toDouble()
|
||||
|
||||
val fillMessageContent: Boolean
|
||||
get() = sharedPref.getBoolean(context.getString(R.string.pref_key_fill_message_content), true)
|
||||
get() = getBoolean(R.string.pref_key_fill_message_content, R.bool.pref_default_fill_message_content)
|
||||
|
||||
private fun getString(id: Int, default: Int) = getString(context.getString(id), default)
|
||||
|
||||
private fun getString(id: String, default: Int) = sharedPref.getString(id, context.getString(default)) ?: context.getString(default)
|
||||
|
||||
private fun getBoolean(id: Int, default: Int) = getBoolean(context.getString(id), default)
|
||||
|
||||
private fun getBoolean(id: String, default: Int) = sharedPref.getBoolean(id, context.resources.getBoolean(default))
|
||||
}
|
||||
|
18
app/src/main/res/values/preferences_defaults.xml
Normal file
18
app/src/main/res/values/preferences_defaults.xml
Normal file
@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
||||
<string name="pref_default_startup">0</string>
|
||||
<bool name="pref_default_attendance_present">true</bool>
|
||||
<string name="pref_default_grade_average_mode">only_one_semester</string>
|
||||
<bool name="pref_default_grade_average_force_calc">false</bool>
|
||||
<bool name="pref_default_expand_grade">false</bool>
|
||||
<string name="pref_default_app_theme">light</string>
|
||||
<string name="pref_default_grade_color_scheme">vulcan</string>
|
||||
<bool name="pref_default_services_enable">true</bool>
|
||||
<string name="pref_default_services_interval">60</string>
|
||||
<bool name="pref_default_services_wifi_only">false</bool>
|
||||
<bool name="pref_default_notifications_enable">true</bool>
|
||||
<bool name="pref_default_notification_debug">false</bool>
|
||||
<string name="pref_default_grade_modifier_plus">0.0</string>
|
||||
<string name="pref_default_grade_modifier_minus">0.0</string>
|
||||
<bool name="pref_default_fill_message_content">true</bool>
|
||||
</resources>
|
@ -4,7 +4,7 @@
|
||||
app:iconSpaceReserved="false"
|
||||
app:title="@string/pref_view_header">
|
||||
<ListPreference
|
||||
app:defaultValue="0"
|
||||
app:defaultValue="@string/pref_default_startup"
|
||||
app:entries="@array/startup_tab_entries"
|
||||
app:entryValues="@array/startup_tab_value"
|
||||
app:iconSpaceReserved="false"
|
||||
@ -12,7 +12,7 @@
|
||||
app:title="@string/pref_view_list"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
app:defaultValue="light"
|
||||
app:defaultValue="@string/pref_default_app_theme"
|
||||
app:entries="@array/app_theme_entries"
|
||||
app:entryValues="@array/app_theme_values"
|
||||
app:iconSpaceReserved="false"
|
||||
@ -20,17 +20,17 @@
|
||||
app:title="@string/pref_view_app_theme"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="true"
|
||||
app:defaultValue="@bool/pref_default_attendance_present"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_attendance_present"
|
||||
app:title="@string/pref_view_present" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:defaultValue="@bool/pref_default_expand_grade"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_expand_grade"
|
||||
app:title="@string/pref_view_expand_grade" />
|
||||
<ListPreference
|
||||
app:defaultValue="vulcan"
|
||||
app:defaultValue="@string/pref_default_grade_color_scheme"
|
||||
app:entries="@array/grade_color_scheme_entries"
|
||||
app:entryValues="@array/grade_color_scheme_values"
|
||||
app:iconSpaceReserved="false"
|
||||
@ -42,12 +42,12 @@
|
||||
app:iconSpaceReserved="false"
|
||||
app:title="@string/pref_services_header">
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="true"
|
||||
app:defaultValue="@bool/pref_default_services_enable"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_services_enable"
|
||||
app:title="@string/pref_services_switch" />
|
||||
<ListPreference
|
||||
app:defaultValue="60"
|
||||
app:defaultValue="@string/pref_default_services_interval"
|
||||
app:dependency="services_enable"
|
||||
app:entries="@array/services_interval_entries"
|
||||
app:entryValues="@array/services_interval_value"
|
||||
@ -56,7 +56,7 @@
|
||||
app:title="@string/pref_services_interval"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:defaultValue="@bool/pref_default_services_wifi_only"
|
||||
app:dependency="services_enable"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_services_wifi_only"
|
||||
@ -66,13 +66,13 @@
|
||||
app:iconSpaceReserved="false"
|
||||
app:title="@string/pref_notify_header">
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="true"
|
||||
app:defaultValue="@bool/pref_default_notifications_enable"
|
||||
app:dependency="services_enable"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_notifications_enable"
|
||||
app:title="@string/pref_notify_switch" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:defaultValue="@bool/pref_default_notification_debug"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_notification_debug"
|
||||
app:title="@string/pref_notify_debug_switch" />
|
||||
@ -81,7 +81,7 @@
|
||||
app:iconSpaceReserved="false"
|
||||
app:title="@string/pref_other_header">
|
||||
<ListPreference
|
||||
app:defaultValue="0.0"
|
||||
app:defaultValue="@string/pref_default_grade_modifier_plus"
|
||||
app:entries="@array/grade_modifier_entries"
|
||||
app:entryValues="@array/grade_modifier_value"
|
||||
app:iconSpaceReserved="false"
|
||||
@ -89,7 +89,7 @@
|
||||
app:title="@string/pref_other_grade_modifier_plus"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
app:defaultValue="0.0"
|
||||
app:defaultValue="@string/pref_default_grade_modifier_minus"
|
||||
app:entries="@array/grade_modifier_entries"
|
||||
app:entryValues="@array/grade_modifier_value"
|
||||
app:iconSpaceReserved="false"
|
||||
@ -97,7 +97,7 @@
|
||||
app:title="@string/pref_other_grade_modifier_minus"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<ListPreference
|
||||
app:defaultValue="only_one_semester"
|
||||
app:defaultValue="@string/pref_default_grade_average_mode"
|
||||
app:entries="@array/grade_average_mode_entries"
|
||||
app:entryValues="@array/grade_average_mode_values"
|
||||
app:iconSpaceReserved="false"
|
||||
@ -105,12 +105,12 @@
|
||||
app:title="@string/pref_view_grade_average_mode"
|
||||
app:useSimpleSummaryProvider="true" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="false"
|
||||
app:defaultValue="@bool/pref_default_grade_average_force_calc"
|
||||
app:key="@string/pref_key_grade_average_force_calc"
|
||||
app:title="@string/pref_view_grade_average_force_calc"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
app:defaultValue="true"
|
||||
app:defaultValue="@bool/pref_default_fill_message_content"
|
||||
app:iconSpaceReserved="false"
|
||||
app:key="@string/pref_key_fill_message_content"
|
||||
app:title="@string/pref_other_fill_message_content" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user