Merge pull request #1677 from Bnyro/master

Fix for the formatShort crash
This commit is contained in:
Bnyro 2022-10-28 21:53:01 +02:00 committed by GitHub
commit 88bce6e11d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View File

@ -3,15 +3,17 @@ package com.github.libretube.extensions
import java.math.BigDecimal import java.math.BigDecimal
import java.math.RoundingMode import java.math.RoundingMode
@Suppress("KotlinConstantConditions")
fun Long?.formatShort(): String = when { fun Long?.formatShort(): String = when {
this!! < 1000 -> { this == null -> (0).toString()
this < 1000 -> {
this.toString() this.toString()
} }
this in 1000..999999 -> { this in (1000..999999) -> {
val decimal = BigDecimal(this / 1000).setScale(0, RoundingMode.HALF_EVEN) val decimal = BigDecimal(this / 1000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "K" decimal.toString() + "K"
} }
this in 1000000..10000000 -> { this in (1000000..10000000) -> {
val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN) val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN)
decimal.toString() + "M" decimal.toString() + "M"
} }

View File

@ -134,7 +134,7 @@
<string name="contributing">Contributing</string> <string name="contributing">Contributing</string>
<string name="donate">Donate</string> <string name="donate">Donate</string>
<string name="update">Look for new version</string> <string name="update">Look for new version</string>
<string name="update_summary">Click to find out if the app is up to date.</string> <string name="update_summary">Check for update</string>
<string name="app_uptodate">Running the latest version.</string> <string name="app_uptodate">Running the latest version.</string>
<string name="no_update_available">You are running the latest version.</string> <string name="no_update_available">You are running the latest version.</string>
<string name="playback_speed">Playback speed</string> <string name="playback_speed">Playback speed</string>