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