feat: AlarmManager option for notifications
This commit is contained in:
parent
deeefb8e35
commit
9471683501
17 changed files with 822 additions and 432 deletions
|
@ -1,9 +1,13 @@
|
|||
package ani.dantotsu.settings
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.AlarmManager
|
||||
import android.app.AlertDialog
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.graphics.drawable.Animatable
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Build.BRAND
|
||||
import android.os.Build.DEVICE
|
||||
import android.os.Build.SUPPORTED_ABIS
|
||||
|
@ -47,6 +51,7 @@ import ani.dantotsu.initActivity
|
|||
import ani.dantotsu.loadImage
|
||||
import ani.dantotsu.util.Logger
|
||||
import ani.dantotsu.navBarHeight
|
||||
import ani.dantotsu.notifications.TaskScheduler
|
||||
import ani.dantotsu.notifications.comment.CommentNotificationWorker
|
||||
import ani.dantotsu.notifications.anilist.AnilistNotificationWorker
|
||||
import ani.dantotsu.openLinkInBrowser
|
||||
|
@ -764,6 +769,40 @@ class SettingsActivity : AppCompatActivity(), SimpleDialog.OnDialogResultListene
|
|||
openSettings(this, null)
|
||||
}
|
||||
|
||||
binding.settingsNotificationsUseAlarmManager.isChecked =
|
||||
PrefManager.getVal(PrefName.UseAlarmManager)
|
||||
|
||||
binding.settingsNotificationsUseAlarmManager.setOnCheckedChangeListener { _, isChecked ->
|
||||
if (isChecked) {
|
||||
val alertDialog = AlertDialog.Builder(this, R.style.MyPopup)
|
||||
.setTitle("Use Alarm Manager")
|
||||
.setMessage("Using Alarm Manger can help fight against battery optimization, but may consume more battery. It also requires the Alarm Manager permission.")
|
||||
.setPositiveButton("Use") { dialog, _ ->
|
||||
PrefManager.setVal(PrefName.UseAlarmManager, true)
|
||||
if (SDK_INT >= Build.VERSION_CODES.S) {
|
||||
if (!(getSystemService(Context.ALARM_SERVICE) as AlarmManager).canScheduleExactAlarms()) {
|
||||
val intent = Intent("android.settings.REQUEST_SCHEDULE_EXACT_ALARM")
|
||||
startActivity(intent)
|
||||
binding.settingsNotificationsCheckingSubscriptions.isChecked = true
|
||||
}
|
||||
}
|
||||
dialog.dismiss()
|
||||
}
|
||||
.setNegativeButton("Cancel") { dialog, _ ->
|
||||
binding.settingsNotificationsCheckingSubscriptions.isChecked = false
|
||||
PrefManager.setVal(PrefName.UseAlarmManager, false)
|
||||
dialog.dismiss()
|
||||
}
|
||||
.create()
|
||||
alertDialog.window?.setDimAmount(0.8f)
|
||||
alertDialog.show()
|
||||
} else {
|
||||
PrefManager.setVal(PrefName.UseAlarmManager, false)
|
||||
TaskScheduler.create(this, true).cancelAllTasks()
|
||||
TaskScheduler.create(this, false).scheduleAllTasks(this)
|
||||
}
|
||||
}
|
||||
|
||||
if (!BuildConfig.FLAVOR.contains("fdroid")) {
|
||||
binding.settingsLogo.setOnLongClickListener {
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
|
|
|
@ -24,6 +24,7 @@ object PrefManager {
|
|||
private var protectedPreferences: SharedPreferences? = null
|
||||
|
||||
fun init(context: Context) { //must be called in Application class or will crash
|
||||
if (generalPreferences != null) return
|
||||
generalPreferences =
|
||||
context.getSharedPreferences(Location.General.location, Context.MODE_PRIVATE)
|
||||
uiPreferences =
|
||||
|
|
|
@ -38,6 +38,7 @@ enum class PrefName(val data: Pref) { //TODO: Split this into multiple files
|
|||
AnilistNotificationInterval(Pref(Location.General, Int::class, 3)),
|
||||
LastAnilistNotificationId(Pref(Location.General, Int::class, 0)),
|
||||
AnilistFilteredTypes(Pref(Location.General, Set::class, setOf<String>())),
|
||||
UseAlarmManager(Pref(Location.General, Boolean::class, false)),
|
||||
|
||||
//User Interface
|
||||
UseOLED(Pref(Location.UI, Boolean::class, false)),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue