From 75ffce292c948217c5f2d9d82dbb712045022ece Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 28 Oct 2022 21:52:26 +0200 Subject: [PATCH] Fix format short when the count is null --- .../java/com/github/libretube/extensions/FormatShort.kt | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/github/libretube/extensions/FormatShort.kt b/app/src/main/java/com/github/libretube/extensions/FormatShort.kt index f0751db56..bb010765b 100644 --- a/app/src/main/java/com/github/libretube/extensions/FormatShort.kt +++ b/app/src/main/java/com/github/libretube/extensions/FormatShort.kt @@ -3,15 +3,17 @@ package com.github.libretube.extensions import java.math.BigDecimal import java.math.RoundingMode +@Suppress("KotlinConstantConditions") fun Long?.formatShort(): String = when { - this!! < 1000 -> { + this == null -> (0).toString() + this < 1000 -> { this.toString() } - this in 1000..999999 -> { + this in (1000..999999) -> { val decimal = BigDecimal(this / 1000).setScale(0, RoundingMode.HALF_EVEN) decimal.toString() + "K" } - this in 1000000..10000000 -> { + this in (1000000..10000000) -> { val decimal = BigDecimal(this / 1000000).setScale(0, RoundingMode.HALF_EVEN) decimal.toString() + "M" }