Skip to content
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.68.4]

- Fixed a rare formatting bug in AcceptedLanguageInterceptor

## [0.68.3]

- Fixed a regression when pre-weighed products to the shopping cart
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ allprojects {
}

project.ext {
sdkVersion='0.68.3'
sdkVersion='0.68.4'
versionCode=1

compileSdkVersion=31
Expand Down
12 changes: 6 additions & 6 deletions core/src/main/java/io/snabble/sdk/AcceptedLanguageInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,23 @@ import androidx.annotation.RestrictTo
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import java.text.DecimalFormat
import java.text.DecimalFormatSymbols
import java.util.*

@RestrictTo(RestrictTo.Scope.LIBRARY)
internal class AcceptedLanguageInterceptor : Interceptor {
private val formatter = DecimalFormat("#.##", DecimalFormatSymbols(Locale.US))

private val acceptedLanguagesHeader: String
get() = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
val list = LocaleList.getDefault()
val all = (0 until list.size()).map { i -> list.get(i) }
val simplified = (all.map { it.toLanguageTag() } + all.map { it.language }).distinct()
var str = simplified.first()
for (i in 1 until simplified.size) {
str += ",${simplified[i]};q=${
"%.1f".format(
Locale.US,
1 - (1 / simplified.size.toFloat()) * i
)
}"
val weight = formatter.format(1 - (1 / simplified.size.toFloat()) * i)
str += ",${simplified[i]};q=$weight"
}
str
} else Locale.getDefault().language
Expand Down