Group advanced battery optimization setting entries

This commit is contained in:
arkon 2021-08-05 17:47:52 -04:00
parent dfec0e45ed
commit b5e118e2b4
2 changed files with 29 additions and 24 deletions

View file

@ -67,36 +67,40 @@ class SettingsAdvancedController : SettingsController() {
} }
} }
preference { preferenceCategory {
key = "pref_disable_battery_optimization" titleRes = R.string.label_background_activity
titleRes = R.string.pref_disable_battery_optimization
summaryRes = R.string.pref_disable_battery_optimization_summary
onClick { preference {
val packageName: String = context.packageName key = "pref_disable_battery_optimization"
if (!context.powerManager.isIgnoringBatteryOptimizations(packageName)) { titleRes = R.string.pref_disable_battery_optimization
try { summaryRes = R.string.pref_disable_battery_optimization_summary
val intent = Intent().apply {
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS onClick {
data = "package:$packageName".toUri() val packageName: String = context.packageName
if (!context.powerManager.isIgnoringBatteryOptimizations(packageName)) {
try {
val intent = Intent().apply {
action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
data = "package:$packageName".toUri()
}
startActivity(intent)
} catch (e: ActivityNotFoundException) {
context.toast(R.string.battery_optimization_setting_activity_not_found)
} }
startActivity(intent) } else {
} catch (e: ActivityNotFoundException) { context.toast(R.string.battery_optimization_disabled)
context.toast(R.string.battery_optimization_setting_activity_not_found)
} }
} else {
context.toast(R.string.battery_optimization_disabled)
} }
} }
}
preference { preference {
key = "pref_dont_kill_my_app" key = "pref_dont_kill_my_app"
title = "Don't kill my app!" title = "Don't kill my app!"
summaryRes = R.string.about_dont_kill_my_app summaryRes = R.string.about_dont_kill_my_app
onClick { onClick {
openInBrowser("https://dontkillmyapp.com/") openInBrowser("https://dontkillmyapp.com/")
}
} }
} }

View file

@ -448,11 +448,12 @@
<string name="pref_dump_crash_logs">Dump crash logs</string> <string name="pref_dump_crash_logs">Dump crash logs</string>
<string name="pref_dump_crash_logs_summary">Saves error logs to a file for sharing with the developers</string> <string name="pref_dump_crash_logs_summary">Saves error logs to a file for sharing with the developers</string>
<string name="crash_log_saved">Crash logs saved</string> <string name="crash_log_saved">Crash logs saved</string>
<string name="label_background_activity">Background activity</string>
<string name="pref_disable_battery_optimization">Disable battery optimization</string> <string name="pref_disable_battery_optimization">Disable battery optimization</string>
<string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string> <string name="pref_disable_battery_optimization_summary">Helps with background library updates and backups</string>
<string name="about_dont_kill_my_app">Some manufacturers have additional app restrictions that kill background services. This website has more info on how to fix it.</string>
<string name="battery_optimization_disabled">Battery optimization is already disabled</string> <string name="battery_optimization_disabled">Battery optimization is already disabled</string>
<string name="battery_optimization_setting_activity_not_found">Couldn\'t open device settings</string> <string name="battery_optimization_setting_activity_not_found">Couldn\'t open device settings</string>
<string name="about_dont_kill_my_app">Some manufacturers have additional app restrictions that kill background services. This website has more info on how to fix it.</string>
<!-- About section --> <!-- About section -->
<string name="website">Website</string> <string name="website">Website</string>