🛠️ Fix "NaN" for progress in Reader
* Fixed issue, where the value is NaN in Reader Resolves: #90
This commit is contained in:
parent
9854c2d845
commit
fbb3faa5b2
2 changed files with 11 additions and 4 deletions
|
|
@ -47,6 +47,11 @@ fun Float.calculateProgress(digits: Int): String {
|
||||||
.dropWhile { it == '-' }
|
.dropWhile { it == '-' }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Float.coerceAndPreventNaN(): Float {
|
||||||
|
if (isNaN()) return 0f
|
||||||
|
return this.coerceIn(0f, 1f)
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(ExperimentalFoundationApi::class)
|
@OptIn(ExperimentalFoundationApi::class)
|
||||||
fun Modifier.noRippleClickable(
|
fun Modifier.noRippleClickable(
|
||||||
enabled: Boolean = true,
|
enabled: Boolean = true,
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ import ua.acclorite.book_story.domain.util.Resource
|
||||||
import ua.acclorite.book_story.domain.util.UIText
|
import ua.acclorite.book_story.domain.util.UIText
|
||||||
import ua.acclorite.book_story.presentation.core.navigation.Screen
|
import ua.acclorite.book_story.presentation.core.navigation.Screen
|
||||||
import ua.acclorite.book_story.presentation.core.util.BaseViewModel
|
import ua.acclorite.book_story.presentation.core.util.BaseViewModel
|
||||||
|
import ua.acclorite.book_story.presentation.core.util.coerceAndPreventNaN
|
||||||
import ua.acclorite.book_story.presentation.core.util.launchActivity
|
import ua.acclorite.book_story.presentation.core.util.launchActivity
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
@ -617,8 +618,8 @@ class ReaderViewModel @Inject constructor(
|
||||||
|
|
||||||
val currentIndex = index - startIndex
|
val currentIndex = index - startIndex
|
||||||
val endIndex = endIndex - startIndex
|
val endIndex = endIndex - startIndex
|
||||||
(currentIndex / endIndex.toFloat()).coerceIn(0f, 1f)
|
(currentIndex / endIndex.toFloat())
|
||||||
}
|
}.coerceAndPreventNaN()
|
||||||
|
|
||||||
_state.update {
|
_state.update {
|
||||||
it.copy(
|
it.copy(
|
||||||
|
|
@ -647,8 +648,9 @@ class ReaderViewModel @Inject constructor(
|
||||||
return 1f
|
return 1f
|
||||||
}
|
}
|
||||||
|
|
||||||
return@run ((firstVisibleItemIndex ?: listState.firstVisibleItemIndex) /
|
return@run (firstVisibleItemIndex ?: listState.firstVisibleItemIndex)
|
||||||
(text.lastIndex).toFloat()).coerceIn(0f, 1f)
|
.div(text.lastIndex.toFloat())
|
||||||
|
.coerceAndPreventNaN()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue