File tree Expand file tree Collapse file tree 1 file changed +6
-6
lines changed
core/src/main/java/io/snabble/sdk Expand file tree Collapse file tree 1 file changed +6
-6
lines changed Original file line number Diff line number Diff line change @@ -6,23 +6,23 @@ import androidx.annotation.RestrictTo
66import okhttp3.Interceptor
77import okhttp3.Request
88import okhttp3.Response
9+ import java.text.DecimalFormat
10+ import java.text.DecimalFormatSymbols
911import java.util.*
1012
1113@RestrictTo(RestrictTo .Scope .LIBRARY )
1214internal 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
You can’t perform that action at this time.
0 commit comments