Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96a7bbda authored by Guillaume Jacquart's avatar Guillaume Jacquart
Browse files

feat:3271: Use bignumber formater in weeklyreports

parent 814016dd
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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 (e: Exception) {
            number
        }
    }
}
+10 −3
Original line number Diff line number Diff line
@@ -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
+4 −1
Original line number Diff line number Diff line
@@ -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 {