Skip to content

Commit daf8983

Browse files
committed
Fix formatting
1 parent 4970ce3 commit daf8983

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

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)