mirror of
https://github.com/advplyr/audiobookshelf-app.git
synced 2026-08-26 21:34:05 +02:00
fix float conversion, rounding for icons
This commit is contained in:
@@ -70,7 +70,8 @@ class MediaManager(private var apiHandler: ApiHandler, var ctx: Context) {
|
|||||||
if (userSettingsPref != null) {
|
if (userSettingsPref != null) {
|
||||||
try {
|
try {
|
||||||
val userSettings = JSObject(userSettingsPref)
|
val userSettings = JSObject(userSettingsPref)
|
||||||
userSettings.put("playbackRate", newRate.toDouble()) // TODO: Handle storing exact values? This actually comes out to something like 2.00000004432
|
// toString().toDouble() to prevent float conversion issues (ex 1.2f becomes 1.2000000476837158d)
|
||||||
|
userSettings.put("playbackRate", newRate.toString().toDouble())
|
||||||
sharedPrefEditor.putString("userSettings", userSettings.toString())
|
sharedPrefEditor.putString("userSettings", userSettings.toString())
|
||||||
sharedPrefEditor.apply()
|
sharedPrefEditor.apply()
|
||||||
userSettingsPlaybackRate = newRate
|
userSettingsPlaybackRate = newRate
|
||||||
@@ -82,7 +83,7 @@ class MediaManager(private var apiHandler: ApiHandler, var ctx: Context) {
|
|||||||
// Not sure if this is the best place for this, but if a user has not changed any user settings in the app
|
// Not sure if this is the best place for this, but if a user has not changed any user settings in the app
|
||||||
// the object will not exist yet, could be moved to a centralized place or created on first app load
|
// the object will not exist yet, could be moved to a centralized place or created on first app load
|
||||||
val userSettings = JSONObject()
|
val userSettings = JSONObject()
|
||||||
userSettings.put("playbackRate", newRate.toDouble())
|
userSettings.put("playbackRate", newRate.toString().toDouble())
|
||||||
sharedPrefEditor.putString("userSettings", userSettings.toString())
|
sharedPrefEditor.putString("userSettings", userSettings.toString())
|
||||||
userSettingsPlaybackRate = newRate
|
userSettingsPlaybackRate = newRate
|
||||||
Log.d(tag, "Created and saved userSettings JSON from Android Auto with playbackRate=$newRate")
|
Log.d(tag, "Created and saved userSettings JSON from Android Auto with playbackRate=$newRate")
|
||||||
|
|||||||
@@ -90,15 +90,15 @@ class MediaSessionCallback(var playerNotificationService:PlayerNotificationServi
|
|||||||
|
|
||||||
private fun onChangeSpeed() {
|
private fun onChangeSpeed() {
|
||||||
// cycle to next speed, only contains preset android app options, as each increment needs it's own icon
|
// cycle to next speed, only contains preset android app options, as each increment needs it's own icon
|
||||||
|
// Rounding values in the event a non preset value (.5, 1, 1.2, 1.5, 2, 3) is selected in the phone app
|
||||||
val mediaManager = playerNotificationService.mediaManager
|
val mediaManager = playerNotificationService.mediaManager
|
||||||
val currentSpeed = mediaManager.getSavedPlaybackRate()
|
val newSpeed = when (mediaManager.getSavedPlaybackRate()) {
|
||||||
val newSpeed = when (currentSpeed) {
|
in 0.5f..0.7f -> 1.0f
|
||||||
0.5f -> 1.0f
|
in 0.8f..1.0f -> 1.2f
|
||||||
1.0f -> 1.2f
|
in 1.1f..1.2f -> 1.5f
|
||||||
1.2f -> 1.5f
|
in 1.3f..1.5f -> 2.0f
|
||||||
1.5f -> 2.0f
|
in 1.6f..2.0f -> 3.0f
|
||||||
2.0f -> 3.0f
|
in 2.1f..3.0f -> 0.5f
|
||||||
3.0f -> 0.5f
|
|
||||||
// anything set above 3 (can happen in the android app) will be reset to 1
|
// anything set above 3 (can happen in the android app) will be reset to 1
|
||||||
else -> 1.0f
|
else -> 1.0f
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -1189,14 +1189,14 @@ class PlayerNotificationService : MediaBrowserServiceCompat() {
|
|||||||
override fun getCustomAction(player: Player): PlaybackStateCompat.CustomAction? {
|
override fun getCustomAction(player: Player): PlaybackStateCompat.CustomAction? {
|
||||||
val playbackRate = mediaManager.getSavedPlaybackRate()
|
val playbackRate = mediaManager.getSavedPlaybackRate()
|
||||||
|
|
||||||
// TODO: Handle custom playback rates like 0.7, 1.3, 1.4, etc
|
// Rounding values in the event a non preset value (.5, 1, 1.2, 1.5, 2, 3) is selected in the phone app
|
||||||
val drawable: Int = when (playbackRate) {
|
val drawable: Int = when (playbackRate) {
|
||||||
0.5f -> R.drawable.ic_play_speed_0_5x
|
in 0.5f..0.7f -> R.drawable.ic_play_speed_0_5x
|
||||||
1.0f -> R.drawable.ic_play_speed_1_0x
|
in 0.8f..1.0f -> R.drawable.ic_play_speed_1_0x
|
||||||
1.2f -> R.drawable.ic_play_speed_1_2x
|
in 1.1f..1.2f -> R.drawable.ic_play_speed_1_2x
|
||||||
1.5f -> R.drawable.ic_play_speed_1_5x
|
in 1.3f..1.5f -> R.drawable.ic_play_speed_1_5x
|
||||||
2.0f -> R.drawable.ic_play_speed_2_0x
|
in 1.6f..2.0f -> R.drawable.ic_play_speed_2_0x
|
||||||
3.0f -> R.drawable.ic_play_speed_3_0x
|
in 2.1f..3.0f -> R.drawable.ic_play_speed_3_0x
|
||||||
// anything set above 3 will be show the 3x to save from creating 100 icons
|
// anything set above 3 will be show the 3x to save from creating 100 icons
|
||||||
else -> R.drawable.ic_play_speed_3_0x
|
else -> R.drawable.ic_play_speed_3_0x
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user