diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index f4cf12020a..0decbdd387 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -8,6 +8,7 @@
+
diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
index 37a360f27d..a51c0545f2 100644
--- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
+++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsAdvancedController.kt
@@ -1,7 +1,14 @@
package eu.kanade.tachiyomi.ui.setting
+import android.annotation.SuppressLint
import android.app.Dialog
+import android.content.Context
+import android.content.Intent
+import android.net.Uri
+import android.os.Build
import android.os.Bundle
+import android.os.PowerManager
+import android.provider.Settings
import android.widget.Toast
import androidx.preference.PreferenceScreen
import com.afollestad.materialdialogs.MaterialDialog
@@ -36,6 +43,7 @@ class SettingsAdvancedController : SettingsController() {
private val db: DatabaseHelper by injectLazy()
+ @SuppressLint("BatteryLife")
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
titleRes = R.string.advanced
@@ -83,6 +91,26 @@ class SettingsAdvancedController : SettingsController() {
onClick { cleanupDownloads() }
}
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
+ val pm = context.getSystemService(Context.POWER_SERVICE) as? PowerManager?
+ if (pm != null) preference {
+ titleRes = R.string.disable_battery_optimization
+ summaryRes = R.string.disable_if_issues_with_updating
+
+ onClick {
+ val packageName: String = context.packageName
+ if (!pm.isIgnoringBatteryOptimizations(packageName)) {
+ val intent = Intent().apply {
+ action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
+ data = Uri.parse("package:$packageName")
+ }
+ startActivity(intent)
+ } else {
+ context.toast(R.string.battery_optimization_disabled)
+ }
+ }
+ }
+ }
}
private fun cleanupDownloads() {
@@ -141,10 +169,10 @@ class SettingsAdvancedController : SettingsController() {
override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialDialog(activity!!)
.message(R.string.clear_database_confirmation)
- .positiveButton(android.R.string.yes) {
+ .positiveButton(android.R.string.ok) {
(targetController as? SettingsAdvancedController)?.clearDatabase()
}
- .negativeButton(android.R.string.no)
+ .negativeButton(android.R.string.cancel)
}
}
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index fcf046a6c2..02c1011af3 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -510,6 +510,10 @@
and read chapter folders
Starting cleanup
No folders to cleanup
+ Disable battery optimization
+ Disable this if you are experiencing issues
+ with updating or restoring your library
+ Battery optimization is already disabled
- Cleanup done. Removed %d folder
- Cleanup done. Removed %d folders