diff --git a/app/src/main/java/foundation/e/advancedprivacy/common/BigNumberFormatter.kt b/app/src/main/java/foundation/e/advancedprivacy/common/BigNumberFormatter.kt index a2ead00e076a8e2f6c12c86028bea3d6cd7dbb31..1aa3ffc88c031cc11c5fa36c16f7247b5bcd9f58 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/common/BigNumberFormatter.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/common/BigNumberFormatter.kt @@ -23,4 +23,16 @@ class BigNumberFormatter(context: Context) { private val formatter = NumberFormatter.withLocale(context.resources.configuration.locales[0]) fun format(number: Int): CharSequence = formatter.format(number) + + fun format(number: String?): CharSequence? { + if (number == null) { + return number + } + + return try { + formatter.format(number.toLong()) + } catch (_: NumberFormatException) { + number + } + } } diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsAndLeaksViewFactory.kt b/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsAndLeaksViewFactory.kt index 005b49ad46a58b3abe8594221722395073b45c67..5559410d15b8e2de35441e80e4e1a82e67be84c7 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsAndLeaksViewFactory.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsAndLeaksViewFactory.kt @@ -26,11 +26,14 @@ import android.view.ViewGroup import androidx.core.content.ContextCompat import androidx.core.view.isVisible import foundation.e.advancedprivacy.R +import foundation.e.advancedprivacy.common.BigNumberFormatter import foundation.e.advancedprivacy.databinding.WeeklyreportItemCallsAndLeaksBinding import foundation.e.advancedprivacy.domain.entities.weeklyreport.DisplayableReport import foundation.e.advancedprivacy.domain.entities.weeklyreport.WeeklyReport class CallsAndLeaksViewFactory(private val context: Context) { + private val numberFormatter: BigNumberFormatter by lazy { BigNumberFormatter(context) } + fun getShareTitle(): CharSequence { return context.getString(R.string.weeklyreport_call_and_leaks_share_title) } @@ -51,7 +54,7 @@ class CallsAndLeaksViewFactory(private val context: Context) { binding.secondaryValue.text = context.getString( R.string.weeklyreport_label_call_and_leaks_secondaryvalue, - report.report.secondaryValues.firstOrNull() + numberFormatter.format(report.report.secondaryValues.firstOrNull()) ) binding.description2.setText( @@ -81,7 +84,7 @@ class CallsAndLeaksViewFactory(private val context: Context) { binding.secondaryValue.text = context.getString( R.string.weeklyreport_label_call_and_leaks_secondaryvalue_sharing, - report.report.secondaryValues.firstOrNull() + numberFormatter.format(report.report.secondaryValues.firstOrNull()) ) binding.description2.setText( @@ -128,7 +131,11 @@ class CallsAndLeaksViewFactory(private val context: Context) { R.string.empty } - return context.getString(descriptionId, report.report.primaryValue, *report.report.secondaryValues.toTypedArray()) + return context.getString( + descriptionId, + report.report.primaryValue, + numberFormatter.format(report.report.secondaryValues.firstOrNull()) + ) } fun getIconForNotification(): Drawable? = null diff --git a/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsPerAppViewFactory.kt b/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsPerAppViewFactory.kt index 6f21a407869948326bf09809ffcaad22dd192f3c..3e643c460030e22dbd4fff7d811ae9002e1615e3 100644 --- a/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsPerAppViewFactory.kt +++ b/app/src/main/java/foundation/e/advancedprivacy/features/weeklyreport/CallsPerAppViewFactory.kt @@ -25,6 +25,7 @@ import android.view.ViewGroup import androidx.core.text.buildSpannedString import androidx.core.text.inSpans import foundation.e.advancedprivacy.R +import foundation.e.advancedprivacy.common.BigNumberFormatter import foundation.e.advancedprivacy.common.ChipSpan import foundation.e.advancedprivacy.databinding.WeeklyReportItemCallsPerAppBinding import foundation.e.advancedprivacy.databinding.WeeklyReportItemCallsPerAppForSharingBinding @@ -32,6 +33,8 @@ import foundation.e.advancedprivacy.domain.entities.weeklyreport.DisplayableRepo import foundation.e.advancedprivacy.domain.entities.weeklyreport.WeeklyReport class CallsPerAppViewFactory(private val context: Context) { + private val numberFormatter: BigNumberFormatter by lazy { BigNumberFormatter(context) } + fun getShareTitle(): CharSequence { return context.getString(R.string.weeklyreport_share_title_base) } @@ -107,7 +110,7 @@ class CallsPerAppViewFactory(private val context: Context) { report.app.label ) - val counts = report.report.secondaryValues.firstOrNull() ?: "" + val counts = numberFormatter.format(report.report.secondaryValues.firstOrNull()) ?: "" val desc2 = context.getString( when {