Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ val AodBrightnessKey = floatPreferencesKey("aodBrightness")
val AodProximityBlackoutKey = booleanPreferencesKey("aodProximityBlackout")
val AodTrueAmbientModeKey = booleanPreferencesKey("aodTrueAmbientMode")
val AodAutoStartScreenOffKey = booleanPreferencesKey("aodAutoStartScreenOff")
val AodOnlyWhileChargingKey = booleanPreferencesKey("aodOnlyWhileCharging")
val AodLowBatteryCutoffKey = intPreferencesKey("aodLowBatteryCutoff")
val SeekExtraSeconds = booleanPreferencesKey("seekExtraSeconds")
val DisableBlurKey = booleanPreferencesKey("disableBlur")
val BlurRadiusKey = floatPreferencesKey("blurRadius")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import java.time.LocalDateTime
import java.time.ZoneOffset

enum class StatPeriod {
HOURS_48,
WEEK_1,
MONTH_1,
MONTH_3,
Expand All @@ -22,6 +23,14 @@ enum class StatPeriod {

fun toTimeMillis(): Long =
when (this) {
HOURS_48 -> {
LocalDateTime
.now()
.minusDays(2)
.toInstant(ZoneOffset.UTC)
.toEpochMilli()
}

WEEK_1 -> {
LocalDateTime
.now()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ class ExoDownloadService :
downloadManager.removeDownload(download.request.id)
}
}
return super.onStartCommand(intent, flags, startId)
return try {
super.onStartCommand(intent, flags, startId)
} catch (_: Exception) {
START_NOT_STICKY
}
}

override fun getDownloadManager() = downloadUtil.downloadManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,23 @@ class MusicService :
val autoStartAod = preferences[AodAutoStartScreenOffKey] ?: true
if (!aodEnabled || !autoStartAod || !player.isPlaying) return@launch

val onlyWhileCharging = dataStore.data.map { it[moe.rukamori.archivetune.constants.AodOnlyWhileChargingKey] ?: false }.first()
if (onlyWhileCharging) {
val batteryIntent = registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
val status = batteryIntent?.getIntExtra(android.os.BatteryManager.EXTRA_STATUS, -1) ?: -1
val isCharging = status == android.os.BatteryManager.BATTERY_STATUS_CHARGING || status == android.os.BatteryManager.BATTERY_STATUS_FULL
if (!isCharging) return@launch
}

val lowBatteryCutoff = dataStore.data.map { it[moe.rukamori.archivetune.constants.AodLowBatteryCutoffKey] ?: 0 }.first()
if (lowBatteryCutoff > 0) {
val batteryIntent = registerReceiver(null, IntentFilter(Intent.ACTION_BATTERY_CHANGED))
val level = batteryIntent?.getIntExtra(android.os.BatteryManager.EXTRA_LEVEL, -1) ?: -1
val scale = batteryIntent?.getIntExtra(android.os.BatteryManager.EXTRA_SCALE, -1) ?: -1
val percent = if (level >= 0 && scale > 0) (level * 100) / scale else 100
if (percent <= lowBatteryCutoff) return@launch
}

val pm = getSystemService(Context.POWER_SERVICE) as? PowerManager
val aodLaunchWl = pm?.newWakeLock(
PowerManager.PARTIAL_WAKE_LOCK,
Expand Down
Loading