Skip to content
This repository has been archived by the owner on Jul 16, 2024. It is now read-only.

Add formatCurrency extensions #216

Merged
merged 4 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
distribution: 'zulu'
java-version: 17
- uses: gradle/gradle-build-action@v2
- run: ./gradlew test
- run: ./gradlew testDebugUnitTest
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FAILURE: Build failed with an exception.
5 problems were found storing the configuration cache, 3 of which seem unique.
- Task `:common:generateDevDebugUnitTestStubRFile` of type `com.android.build.gradle.internal.res.GenerateLibraryRFileTask`: value 'file collection' failed to visit file collection
- Task `:common:kspDevDebugUnitTestKotlin` of type `com.google.devtools.ksp.gradle.KspTaskJvm`: value 'configuration ':common:devDebugUnitTestCompileClasspath' files' failed to visit file collection
- Task `:common:kspDevDebugUnitTestKotlin` of type `com.google.devtools.ksp.gradle.KspTaskJvm`: value 'file collection' failed to visit file collection

See the complete report at file:///home/runner/work/DemoApp/DemoApp/build/reports/configuration-cache/cb3uuogikbyxf6v16cp20imp1/2ujnzkrxp2l7ikqaskce4205l/configuration-cache-report.html

* What went wrong:
Configuration cache state could not be cached: field '__compileKotlinArgumentsContributor$gradle_plugin__' from type 'com.google.devtools.ksp.gradle.KspTaskJvm': error writing value of type 'org.gradle.api.internal.provider.DefaultProperty'
> Configuration cache state could not be cached: field 'friendPaths' from type 'org.jetbrains.kotlin.gradle.internal.KotlinJvmCompilerArgumentsContributor': error writing value of type 'org.gradle.api.internal.file.collections.DefaultConfigurableFileCollection'
   > Configuration cache state could not be cached: field 'provider' from type 'org.gradle.configurationcache.serialization.codecs.ProviderBackedFileCollectionSpec': error writing value of type 'org.gradle.api.internal.provider.DefaultProperty'
      > Configuration cache state could not be cached: field 'filter' from type 'org.gradle.configurationcache.serialization.codecs.FilteredFileCollectionSpec': error writing value of type 'org.jetbrains.kotlin.gradle.plugin.AndroidTestedVariantArtifactsFilter'
         > Configuration cache state could not be cached: field 'artifactCollection' from type 'org.jetbrains.kotlin.gradle.plugin.AndroidTestedVariantArtifactsFilter': error writing value of type 'com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact'
            > Configuration cache state could not be cached: field 'parentArtifacts' from type 'com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact': error writing value of type 'com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact'
               > Configuration cache state could not be cached: field 'parentArtifacts' from type 'com.android.build.gradle.internal.dependency.ArtifactCollectionWithExtraArtifact': error writing value of type 'org.gradle.api.internal.artifacts.configurations.DefaultConfiguration$ConfigurationArtifactCollection'
                  > Configuration cache state could not be cached: field 'causes' from type 'org.gradle.internal.resolve.ModuleVersionNotFoundException': error writing value of type 'java.util.concurrent.CopyOnWriteArrayList'
                     > Unable to make private void java.util.concurrent.CopyOnWriteArrayList.writeObject(java.io.ObjectOutputStream) throws java.io.IOException accessible: module java.base does not "opens java.util.concurrent" to unnamed module @4e7[26](https://github.com/Goooler/DemoApp/actions/runs/3055126386/jobs/4927833428#step:5:27)e73


instrumentation-tests:
runs-on: macos-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import io.goooler.demoapp.base.util.ToastUtil
import io.goooler.demoapp.common.BuildConfig
import io.goooler.demoapp.common.CommonApplication
import io.goooler.demoapp.common.type.SpKeys
import java.text.NumberFormat
import java.util.Locale
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.asExecutor
Expand Down Expand Up @@ -171,3 +172,11 @@ fun SmartRefreshLayout.enableRefreshAndLoadMore(enable: Boolean = true) {
fun SmartRefreshLayout.disableRefreshAndLoadMore() {
enableRefreshAndLoadMore(false)
}

// ---------------------Number-------------------------------//

fun Number.formatCurrency(locale: Locale = Locale.getDefault()): String = runCatching {
NumberFormat.getCurrencyInstance(locale).format(this)
}.getOrDefault("0.00")

fun Number.formatCurrency(locale: String): String = formatCurrency(Locale.forLanguageTag(locale))
14 changes: 14 additions & 0 deletions common/src/test/kotlin/io/goooler/demoapp/common/CurrencyTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.goooler.demoapp.common

import io.goooler.demoapp.common.util.formatCurrency
import kotlin.test.assertEquals
import org.junit.jupiter.api.Test

class CurrencyTest {

@Test
fun formatCurrency() {
assertEquals(1000000.formatCurrency("zh-CN"), "¥1,000,000.00")
assertEquals(1000000.formatCurrency("en-US"), "$1,000,000.00")
}
}