Skip to content

Commit

Permalink
fix: fixed crash when EQ value is corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
timschneeb committed Mar 19, 2023
1 parent 4e3a665 commit 36f9a18
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class EqualizerDialogFragment : PreferenceDialogFragmentCompat() {
.split(";")
.drop(15)
.dropLastWhile(String::isEmpty)
.map(String::toDouble)
.map { it.toDoubleOrNull() ?: 0.0 }
.toDoubleArray()
.copyOf(15)
}
Expand Down Expand Up @@ -69,7 +69,7 @@ class EqualizerDialogFragment : PreferenceDialogFragmentCompat() {
(preference as EqualizerPreference).entryValues[index]
.split(";")
.dropLastWhile(String::isEmpty)
.map(String::toDouble)
.map { it.toDoubleOrNull() ?: 0.0 }
.forEachIndexed(::updateBand)
.also { applyCurrentSetting() }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import androidx.preference.PreferenceViewHolder
import me.timschneeberger.rootlessjamesdsp.view.EqualizerSurface
import me.timschneeberger.rootlessjamesdsp.R
import me.timschneeberger.rootlessjamesdsp.databinding.PreferenceEqualizerBinding
import me.timschneeberger.rootlessjamesdsp.utils.extensions.ContextExtensions.toast
import timber.log.Timber

class EqualizerPreference : DialogPreference {

Expand Down Expand Up @@ -74,6 +76,7 @@ class EqualizerPreference : DialogPreference {
.split(";")
.drop(15)
.dropLastWhile(String::isEmpty)
.forEachIndexed { index, s -> equalizerView?.setBand(index, s.toDouble()) }
.map(String::toDoubleOrNull)
.forEachIndexed { index, s -> equalizerView?.setBand(index, s ?: 0.0) }
}
}

0 comments on commit 36f9a18

Please sign in to comment.