feat: 优化代码

pull/95/head
kunfei 5 years ago
parent 853a43272d
commit b68063616f
  1. 20
      app/src/main/java/io/legado/app/help/http/EncodeConverter.kt
  2. 7
      app/src/main/res/color/selector_image.xml

@ -17,20 +17,22 @@ class EncodeConverter(private val encode: String? = null) : Converter.Factory()
): Converter<ResponseBody, String>? {
return Converter { value ->
val responseBytes = UTF8BOMFighter.removeUTF8BOM(value.bytes())
encode?.let { return@Converter String(responseBytes, Charset.forName(encode)) }
var charsetName: String? = encode
var charsetName: String? = null
val mediaType = value.contentType()
//根据http头判断
if (mediaType != null) {
val charset = mediaType.charset()
charsetName = charset?.displayName()
charsetName?.let {
try {
return@Converter String(responseBytes, Charset.forName(charsetName))
} catch (e: Exception) {
}
}
if (charsetName == null) {
charsetName = EncodingDetect.getHtmlEncode(responseBytes)
//根据http头判断
value.contentType()?.charset()?.let {
return@Converter String(responseBytes, it)
}
//根据内容判断
charsetName = EncodingDetect.getHtmlEncode(responseBytes)
String(responseBytes, Charset.forName(charsetName))
}
}

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@color/common_google_signin_btn_text_light_disabled" />
<item android:state_pressed="true" android:color="@color/common_google_signin_btn_text_light_pressed" />
<item android:state_focused="true" android:color="@color/common_google_signin_btn_text_light_focused" />
<item android:color="@color/common_google_signin_btn_text_light_default" />
</selector>
Loading…
Cancel
Save