mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2025-08-29 14:28:34 +02:00
Add:Android sleep timer setting to disable vibrate on reset #552
This commit is contained in:
parent
39909a398e
commit
2f243787ce
3 changed files with 30 additions and 9 deletions
|
@ -103,7 +103,8 @@ data class DeviceSettings(
|
||||||
var autoSleepTimerStartTime: String,
|
var autoSleepTimerStartTime: String,
|
||||||
var autoSleepTimerEndTime: String,
|
var autoSleepTimerEndTime: String,
|
||||||
var sleepTimerLength: Long, // Time in milliseconds
|
var sleepTimerLength: Long, // Time in milliseconds
|
||||||
var disableSleepTimerFadeOut: Boolean
|
var disableSleepTimerFadeOut: Boolean,
|
||||||
|
var disableSleepTimerResetFeedback: Boolean
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
// Static method to get default device settings
|
// Static method to get default device settings
|
||||||
|
@ -121,7 +122,8 @@ data class DeviceSettings(
|
||||||
autoSleepTimerStartTime = "22:00",
|
autoSleepTimerStartTime = "22:00",
|
||||||
autoSleepTimerEndTime = "06:00",
|
autoSleepTimerEndTime = "06:00",
|
||||||
sleepTimerLength = 900000L, // 15 minutes
|
sleepTimerLength = 900000L, // 15 minutes
|
||||||
disableSleepTimerFadeOut = false
|
disableSleepTimerFadeOut = false,
|
||||||
|
disableSleepTimerResetFeedback = false
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,8 +156,10 @@ class SleepTimerManager constructor(private val playerNotificationService: Playe
|
||||||
playerNotificationService.clientEventEmitter?.onSleepTimerSet(0, false)
|
playerNotificationService.clientEventEmitter?.onSleepTimerSet(0, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Vibrate when extending sleep timer by shaking
|
// Vibrate when resetting sleep timer
|
||||||
private fun vibrate() {
|
private fun vibrateFeedback() {
|
||||||
|
if (DeviceManager.deviceData.deviceSettings?.disableSleepTimerResetFeedback == true) return
|
||||||
|
|
||||||
val context = playerNotificationService.getContext()
|
val context = playerNotificationService.getContext()
|
||||||
val vibrator:Vibrator
|
val vibrator:Vibrator
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
|
@ -207,7 +209,7 @@ class SleepTimerManager constructor(private val playerNotificationService: Playe
|
||||||
private fun resetChapterTimer() {
|
private fun resetChapterTimer() {
|
||||||
this.getChapterEndTime()?.let { chapterEndTime ->
|
this.getChapterEndTime()?.let { chapterEndTime ->
|
||||||
Log.d(tag, "Resetting stopped sleep timer to end of chapter $chapterEndTime")
|
Log.d(tag, "Resetting stopped sleep timer to end of chapter $chapterEndTime")
|
||||||
vibrate()
|
vibrateFeedback()
|
||||||
setSleepTimer(chapterEndTime, true)
|
setSleepTimer(chapterEndTime, true)
|
||||||
play()
|
play()
|
||||||
}
|
}
|
||||||
|
@ -232,7 +234,7 @@ class SleepTimerManager constructor(private val playerNotificationService: Playe
|
||||||
resetChapterTimer()
|
resetChapterTimer()
|
||||||
} else {
|
} else {
|
||||||
Log.d(tag, "Resetting stopped sleep timer to length $sleepTimerLength")
|
Log.d(tag, "Resetting stopped sleep timer to length $sleepTimerLength")
|
||||||
vibrate()
|
vibrateFeedback()
|
||||||
setSleepTimer(sleepTimerLength, false)
|
setSleepTimer(sleepTimerLength, false)
|
||||||
play()
|
play()
|
||||||
}
|
}
|
||||||
|
@ -242,14 +244,14 @@ class SleepTimerManager constructor(private val playerNotificationService: Playe
|
||||||
// Does not apply to chapter sleep timers and timer must be running for at least 3 seconds
|
// Does not apply to chapter sleep timers and timer must be running for at least 3 seconds
|
||||||
if (sleepTimerLength > 0L && sleepTimerElapsed > 3000L) {
|
if (sleepTimerLength > 0L && sleepTimerElapsed > 3000L) {
|
||||||
Log.d(tag, "Resetting running sleep timer to length $sleepTimerLength")
|
Log.d(tag, "Resetting running sleep timer to length $sleepTimerLength")
|
||||||
vibrate()
|
vibrateFeedback()
|
||||||
setSleepTimer(sleepTimerLength, false)
|
setSleepTimer(sleepTimerLength, false)
|
||||||
} else if (sleepTimerLength == 0L) {
|
} else if (sleepTimerLength == 0L) {
|
||||||
// When navigating to previous chapters make sure this is still the end of the current chapter
|
// When navigating to previous chapters make sure this is still the end of the current chapter
|
||||||
this.getChapterEndTime()?.let { chapterEndTime ->
|
this.getChapterEndTime()?.let { chapterEndTime ->
|
||||||
if (chapterEndTime != sleepTimerEndTime) {
|
if (chapterEndTime != sleepTimerEndTime) {
|
||||||
Log.d(tag, "Resetting chapter sleep timer to end of chapter $chapterEndTime from $sleepTimerEndTime")
|
Log.d(tag, "Resetting chapter sleep timer to end of chapter $chapterEndTime from $sleepTimerEndTime")
|
||||||
vibrate()
|
vibrateFeedback()
|
||||||
setSleepTimer(chapterEndTime, true)
|
setSleepTimer(chapterEndTime, true)
|
||||||
play()
|
play()
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,6 +65,13 @@
|
||||||
<p class="pl-4">Disable audio fade out</p>
|
<p class="pl-4">Disable audio fade out</p>
|
||||||
<span class="material-icons-outlined ml-2" @click.stop="showInfo('disableSleepTimerFadeOut')">info</span>
|
<span class="material-icons-outlined ml-2" @click.stop="showInfo('disableSleepTimerFadeOut')">info</span>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-center py-3" @click="toggleDisableSleepTimerResetFeedback">
|
||||||
|
<div class="w-10 flex justify-center">
|
||||||
|
<ui-toggle-switch v-model="settings.disableSleepTimerResetFeedback" @input="saveSettings" />
|
||||||
|
</div>
|
||||||
|
<p class="pl-4">Disable vibrate on reset</p>
|
||||||
|
<span class="material-icons-outlined ml-2" @click.stop="showInfo('disableSleepTimerResetFeedback')">info</span>
|
||||||
|
</div>
|
||||||
<div class="flex items-center py-3" @click="toggleAutoSleepTimer">
|
<div class="flex items-center py-3" @click="toggleAutoSleepTimer">
|
||||||
<div class="w-10 flex justify-center">
|
<div class="w-10 flex justify-center">
|
||||||
<ui-toggle-switch v-model="settings.autoSleepTimer" @input="saveSettings" />
|
<ui-toggle-switch v-model="settings.autoSleepTimer" @input="saveSettings" />
|
||||||
|
@ -117,7 +124,8 @@ export default {
|
||||||
autoSleepTimerStartTime: '22:00',
|
autoSleepTimerStartTime: '22:00',
|
||||||
autoSleepTimerEndTime: '06:00',
|
autoSleepTimerEndTime: '06:00',
|
||||||
sleepTimerLength: 900000, // 15 minutes
|
sleepTimerLength: 900000, // 15 minutes
|
||||||
disableSleepTimerFadeOut: false
|
disableSleepTimerFadeOut: false,
|
||||||
|
disableSleepTimerResetFeedback: false
|
||||||
},
|
},
|
||||||
lockCurrentOrientation: false,
|
lockCurrentOrientation: false,
|
||||||
settingInfo: {
|
settingInfo: {
|
||||||
|
@ -132,6 +140,10 @@ export default {
|
||||||
disableSleepTimerFadeOut: {
|
disableSleepTimerFadeOut: {
|
||||||
name: 'Disable audio fade out',
|
name: 'Disable audio fade out',
|
||||||
message: 'Audio volume will start decreasing when there is less than 1 minute remaining on the sleep timer. Enable this setting to not fade out.'
|
message: 'Audio volume will start decreasing when there is less than 1 minute remaining on the sleep timer. Enable this setting to not fade out.'
|
||||||
|
},
|
||||||
|
disableSleepTimerResetFeedback: {
|
||||||
|
name: 'Disable vibrate on reset',
|
||||||
|
message: 'When the sleep timer gets reset your device will vibrate. Enable this setting to not vibrate when the sleep timer resets.'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hapticFeedbackItems: [
|
hapticFeedbackItems: [
|
||||||
|
@ -283,6 +295,10 @@ export default {
|
||||||
this.settings.disableShakeToResetSleepTimer = !this.settings.disableShakeToResetSleepTimer
|
this.settings.disableShakeToResetSleepTimer = !this.settings.disableShakeToResetSleepTimer
|
||||||
this.saveSettings()
|
this.saveSettings()
|
||||||
},
|
},
|
||||||
|
toggleDisableSleepTimerResetFeedback() {
|
||||||
|
this.settings.disableSleepTimerResetFeedback = !this.settings.disableSleepTimerResetFeedback
|
||||||
|
this.saveSettings()
|
||||||
|
},
|
||||||
toggleDisableAutoRewind() {
|
toggleDisableAutoRewind() {
|
||||||
this.settings.disableAutoRewind = !this.settings.disableAutoRewind
|
this.settings.disableAutoRewind = !this.settings.disableAutoRewind
|
||||||
this.saveSettings()
|
this.saveSettings()
|
||||||
|
@ -347,6 +363,7 @@ export default {
|
||||||
this.settings.autoSleepTimerEndTime = deviceSettings.autoSleepTimerEndTime || '06:00'
|
this.settings.autoSleepTimerEndTime = deviceSettings.autoSleepTimerEndTime || '06:00'
|
||||||
this.settings.sleepTimerLength = !isNaN(deviceSettings.sleepTimerLength) ? deviceSettings.sleepTimerLength : 900000 // 15 minutes
|
this.settings.sleepTimerLength = !isNaN(deviceSettings.sleepTimerLength) ? deviceSettings.sleepTimerLength : 900000 // 15 minutes
|
||||||
this.settings.disableSleepTimerFadeOut = !!deviceSettings.disableSleepTimerFadeOut
|
this.settings.disableSleepTimerFadeOut = !!deviceSettings.disableSleepTimerFadeOut
|
||||||
|
this.settings.disableSleepTimerResetFeedback = !!deviceSettings.disableSleepTimerResetFeedback
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue