Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Slider crash due to IllegalStateException #515

Merged
merged 5 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
@@ -0,0 +1,9 @@
package dev.anilbeesetti.nextplayer.core.common.extensions

import kotlin.math.pow
import kotlin.math.roundToInt

fun Float.round(decimalPlaces: Int): Float {
return (this * 10.0.pow(decimalPlaces.toDouble()))
.roundToInt() / 10.0.pow(decimalPlaces.toDouble()).toFloat()
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Dialog
import android.os.Bundle
import androidx.fragment.app.DialogFragment
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dev.anilbeesetti.nextplayer.core.common.extensions.round
import dev.anilbeesetti.nextplayer.core.ui.R as coreUiR
import dev.anilbeesetti.nextplayer.feature.player.databinding.PlaybackSpeedBinding

Expand All @@ -20,9 +21,9 @@ class PlaybackSpeedControlsDialogFragment(
return activity?.let { activity ->
binding.apply {
speedText.text = currentSpeed.toString()
speed.value = currentSpeed
speed.value = currentSpeed.round(1)
speed.addOnChangeListener { _, _, _ ->
val newSpeed = String.format("%.1f", speed.value).toFloat()
val newSpeed = speed.value.round(1)
onChange(newSpeed)
speedText.text = newSpeed.toString()
}
Expand All @@ -31,12 +32,12 @@ class PlaybackSpeedControlsDialogFragment(
}
incSpeed.setOnClickListener {
if (speed.value < 4.0f) {
speed.value += 0.1f
speed.value = (speed.value + 0.1f).round(1)
}
}
decSpeed.setOnClickListener {
if (speed.value > 0.2f) {
speed.value -= 0.1f
speed.value = (speed.value - 0.1f).round(1)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import dev.anilbeesetti.nextplayer.core.common.extensions.round
import dev.anilbeesetti.nextplayer.core.model.DoubleTapGesture
import dev.anilbeesetti.nextplayer.core.model.FastSeek
import dev.anilbeesetti.nextplayer.core.model.Resume
Expand All @@ -41,7 +42,6 @@ import dev.anilbeesetti.nextplayer.core.ui.designsystem.NextIcons
import dev.anilbeesetti.nextplayer.settings.composables.OptionsDialog
import dev.anilbeesetti.nextplayer.settings.composables.PreferenceSubtitle
import dev.anilbeesetti.nextplayer.settings.extensions.name
import java.lang.Exception
import java.util.Locale

@OptIn(ExperimentalMaterial3Api::class)
Expand Down Expand Up @@ -259,11 +259,8 @@ fun PlayerPreferencesScreen(
)
Slider(
value = defaultPlaybackSpeed,
onValueChange = {
defaultPlaybackSpeed = String.format("%.1f", it).toFloat()
},
valueRange = 0.2f..4.0f,
steps = 37
onValueChange = { defaultPlaybackSpeed = it.round(1) },
valueRange = 0.2f..4.0f
)
}
)
Expand Down Expand Up @@ -293,8 +290,7 @@ fun PlayerPreferencesScreen(
Slider(
value = controllerAutoHideSec.toFloat(),
onValueChange = { controllerAutoHideSec = it.toInt() },
valueRange = 1.0f..60.0f,
steps = 60
valueRange = 1.0f..60.0f
)
}
)
Expand Down Expand Up @@ -324,8 +320,7 @@ fun PlayerPreferencesScreen(
Slider(
value = seekIncrement.toFloat(),
onValueChange = { seekIncrement = it.toInt() },
valueRange = 1.0f..60.0f,
steps = 60
valueRange = 1.0f..60.0f
)
}
)
Expand Down Expand Up @@ -437,7 +432,9 @@ fun LazyListScope.autoplaySetting(
isChecked = isChecked,
onClick = onClick
)
} fun LazyListScope.rememberBrightnessSetting(
}

fun LazyListScope.rememberBrightnessSetting(
isChecked: Boolean,
onClick: () -> Unit
) = item {
Expand Down