mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 01:35:09 +01:00
Add shortcut to disabling battery optimization
This commit is contained in:
parent
0af41005f8
commit
a4178f5d28
@ -8,6 +8,7 @@
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
|
||||
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
|
||||
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES" />
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -510,6 +510,10 @@
|
||||
and read chapter folders</string>
|
||||
<string name="starting_cleanup">Starting cleanup</string>
|
||||
<string name="no_folders_to_cleanup">No folders to cleanup</string>
|
||||
<string name="disable_battery_optimization">Disable battery optimization</string>
|
||||
<string name="disable_if_issues_with_updating">Disable this if you are experiencing issues
|
||||
with updating or restoring your library</string>
|
||||
<string name="battery_optimization_disabled">Battery optimization is already disabled</string>
|
||||
<plurals name="cleanup_done">
|
||||
<item quantity="one">Cleanup done. Removed %d folder</item>
|
||||
<item quantity="other">Cleanup done. Removed %d folders</item>
|
||||
|
Loading…
Reference in New Issue
Block a user