Skip to content

Commit 7da9681

Browse files
authored
Merge pull request #56 from snabble/fix_absurd_formatting_bug
Fix formatting
2 parents 90dd61a + 4e65bc9 commit 7da9681

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [0.68.4]
5+
6+
- Fixed a rare formatting bug in AcceptedLanguageInterceptor
7+
48
## [0.68.3]
59

610
- Fixed a regression when pre-weighed products to the shopping cart

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ allprojects {
3333
}
3434

3535
project.ext {
36-
sdkVersion='0.68.3'
36+
sdkVersion='0.68.4'
3737
versionCode=1
3838

3939
compileSdkVersion=31

core/src/main/java/io/snabble/sdk/AcceptedLanguageInterceptor.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,23 @@ import androidx.annotation.RestrictTo
66
import okhttp3.Interceptor
77
import okhttp3.Request
88
import okhttp3.Response
9+
import java.text.DecimalFormat
10+
import java.text.DecimalFormatSymbols
911
import java.util.*
1012

1113
@RestrictTo(RestrictTo.Scope.LIBRARY)
1214
internal class AcceptedLanguageInterceptor : Interceptor {
15+
private val formatter = DecimalFormat("#.##", DecimalFormatSymbols(Locale.US))
16+
1317
private val acceptedLanguagesHeader: String
1418
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
1519
val list = LocaleList.getDefault()
1620
val all = (0 until list.size()).map { i -> list.get(i) }
1721
val simplified = (all.map { it.toLanguageTag() } + all.map { it.language }).distinct()
1822
var str = simplified.first()
1923
for (i in 1 until simplified.size) {
20-
str += ",${simplified[i]};q=${
21-
"%.1f".format(
22-
Locale.US,
23-
1 - (1 / simplified.size.toFloat()) * i
24-
)
25-
}"
24+
val weight = formatter.format(1 - (1 / simplified.size.toFloat()) * i)
25+
str += ",${simplified[i]};q=$weight"
2626
}
2727
str
2828
} else Locale.getDefault().language

0 commit comments

Comments
 (0)