feat: 修复bug

pull/241/head
gedoor 5 years ago
parent e7b90f0e31
commit 595edcb60d
  1. 2
      app/proguard-rules.pro
  2. 1
      app/src/main/java/io/legado/app/help/ReadBookConfig.kt
  3. 41
      app/src/main/java/io/legado/app/utils/GsonExtensions.kt
  4. 6
      app/src/main/res/values-zh-rHK/strings.xml
  5. 6
      app/src/main/res/values-zh-rTW/strings.xml
  6. 9
      app/src/main/res/values/strings.xml
  7. 66
      app/src/main/res/xml/pref_config_backup.xml

@ -164,6 +164,8 @@
-dontwarn org.conscrypt.** -dontwarn org.conscrypt.**
-dontwarn com.jeremyliao.liveeventbus.** -dontwarn com.jeremyliao.liveeventbus.**
-keep class com.google.gson.** { *; }
-keep class com.ke.gson.** { *; }
-keep class com.jeremyliao.liveeventbus.** { *; } -keep class com.jeremyliao.liveeventbus.** { *; }
-keep class okhttp3.**{*;} -keep class okhttp3.**{*;}
-keep class okio.**{*;} -keep class okio.**{*;}

@ -59,6 +59,7 @@ object ReadBookConfig {
val json = configFile.readText() val json = configFile.readText()
return GSON.fromJsonArray(json) return GSON.fromJsonArray(json)
} catch (e: Exception) { } catch (e: Exception) {
e.printStackTrace()
} }
} }
return null return null

@ -15,6 +15,7 @@ val GSON: Gson by lazy {
object : TypeToken<Map<String?, Any?>?>() {}.type, object : TypeToken<Map<String?, Any?>?>() {}.type,
MapDeserializerDoubleAsIntFix() MapDeserializerDoubleAsIntFix()
) )
.registerTypeAdapter(Int::class.java, IntJsonDeserializer())
.disableHtmlEscaping() .disableHtmlEscaping()
.setPrettyPrinting() .setPrettyPrinting()
.create() .create()
@ -44,6 +45,32 @@ class ParameterizedTypeImpl(private val clazz: Class<*>) : ParameterizedType {
override fun getActualTypeArguments(): Array<Type> = arrayOf(clazz) override fun getActualTypeArguments(): Array<Type> = arrayOf(clazz)
} }
/**
* int类型转化失败时跳过
*/
class IntJsonDeserializer : JsonDeserializer<Int?> {
override fun deserialize(
json: JsonElement,
typeOfT: Type?,
context: JsonDeserializationContext?
): Int? {
return when {
json.isJsonPrimitive -> {
val prim = json.asJsonPrimitive
if (prim.isNumber) {
prim.asNumber.toInt()
} else {
null
}
}
else -> null
}
}
}
/** /**
* 修复Int变为Double的问题 * 修复Int变为Double的问题
*/ */
@ -60,20 +87,20 @@ class MapDeserializerDoubleAsIntFix :
return read(jsonElement) as? Map<String, Any?> return read(jsonElement) as? Map<String, Any?>
} }
fun read(`in`: JsonElement): Any? { fun read(json: JsonElement): Any? {
when { when {
`in`.isJsonArray -> { json.isJsonArray -> {
val list: MutableList<Any?> = ArrayList() val list: MutableList<Any?> = ArrayList()
val arr = `in`.asJsonArray val arr = json.asJsonArray
for (anArr in arr) { for (anArr in arr) {
list.add(read(anArr)) list.add(read(anArr))
} }
return list return list
} }
`in`.isJsonObject -> { json.isJsonObject -> {
val map: MutableMap<String, Any?> = val map: MutableMap<String, Any?> =
LinkedTreeMap() LinkedTreeMap()
val obj = `in`.asJsonObject val obj = json.asJsonObject
val entitySet = val entitySet =
obj.entrySet() obj.entrySet()
for ((key, value) in entitySet) { for ((key, value) in entitySet) {
@ -81,8 +108,8 @@ class MapDeserializerDoubleAsIntFix :
} }
return map return map
} }
`in`.isJsonPrimitive -> { json.isJsonPrimitive -> {
val prim = `in`.asJsonPrimitive val prim = json.asJsonPrimitive
when { when {
prim.isBoolean -> { prim.isBoolean -> {
return prim.asBoolean return prim.asBoolean

@ -695,4 +695,10 @@
<string name="auto_page_speed">自動翻頁速度</string> <string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</string> <string name="sort_by_url">地址排序</string>
<string name="text_font_weight_converter">文章字體轉換</string> <string name="text_font_weight_converter">文章字體轉換</string>
<string name="select_backup_path">請選擇備份路徑</string>
<string name="other">其它</string>
<string name="official_account" translatable="false">legado-top</string>
<string name="backup_summary">本地和WebDav壹起備份</string>
<string name="restore_summary">優先從WebDav恢復,失敗時從本地恢復</string>
<string name="import_old_summary">選擇舊版備份文件夾</string>
</resources> </resources>

@ -664,7 +664,7 @@
<string name="contact">聯繫我們</string> <string name="contact">聯繫我們</string>
<string name="license">開源許可</string> <string name="license">開源許可</string>
<string name="other" translatable="false">其它</string> <string name="other" translatable="false">其它</string>
<string name="official_account" translatable="false">開源閱讀</string> <string name="official_account" translatable="false">legado-top</string>
<string name="follow_official_account">關注公眾號</string> <string name="follow_official_account">關注公眾號</string>
<string name="wechat">微信</string> <string name="wechat">微信</string>
<string name="thanks">您的支援是我更新的動力</string> <string name="thanks">您的支援是我更新的動力</string>
@ -697,5 +697,9 @@
<string name="auto_page_speed">自動翻頁速度</string> <string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</string> <string name="sort_by_url">地址排序</string>
<string name="text_font_weight_converter">文章字體轉換</string> <string name="text_font_weight_converter">文章字體轉換</string>
<string name="select_backup_path">請選擇備份路徑</string>
<string name="backup_summary">本地和WebDav壹起備份</string>
<string name="restore_summary">優先從WebDav恢復,失敗時從本地恢復</string>
<string name="import_old_summary">選擇舊版備份文件夾</string>
</resources> </resources>

@ -11,6 +11,7 @@
<string name="mkdirs">创建子文件夹</string> <string name="mkdirs">创建子文件夹</string>
<string name="mkdirs_description">创建legado文件夹作为备份文件夹</string> <string name="mkdirs_description">创建legado文件夹作为备份文件夹</string>
<string name="backup_path">备份路径</string> <string name="backup_path">备份路径</string>
<string name="select_backup_path">请选择备份路径</string>
<string name="menu_import_old_version">导入旧版数据</string> <string name="menu_import_old_version">导入旧版数据</string>
<string name="menu_import_github">导入Github数据</string> <string name="menu_import_github">导入Github数据</string>
<string name="menu_replace_rule">净化替换</string> <string name="menu_replace_rule">净化替换</string>
@ -663,8 +664,8 @@
<string name="contributors">开发人员</string> <string name="contributors">开发人员</string>
<string name="contact">联系我们</string> <string name="contact">联系我们</string>
<string name="license">开源许可</string> <string name="license">开源许可</string>
<string name="other" translatable="false">其它</string> <string name="other">其它</string>
<string name="official_account" translatable="false">开源阅读</string> <string name="official_account">开源阅读</string>
<string name="follow_official_account">关注公众号</string> <string name="follow_official_account">关注公众号</string>
<string name="wechat">微信</string> <string name="wechat">微信</string>
<string name="thanks">您的支持是我更新的动力</string> <string name="thanks">您的支持是我更新的动力</string>
@ -697,5 +698,7 @@
<string name="text_full_justify">文字两端对齐</string> <string name="text_full_justify">文字两端对齐</string>
<string name="auto_page_speed">自动翻页速度</string> <string name="auto_page_speed">自动翻页速度</string>
<string name="sort_by_url">地址排序</string> <string name="sort_by_url">地址排序</string>
<string name="backup_summary">本地和WebDav一起备份</string>
<string name="restore_summary">优先从WebDav恢复,失败时从本地恢复</string>
<string name="import_old_summary">选择旧版备份文件夹</string>
</resources> </resources>

@ -4,64 +4,68 @@
<io.legado.app.ui.widget.prefs.PreferenceCategory <io.legado.app.ui.widget.prefs.PreferenceCategory
android:title="@string/web_dav_set" android:title="@string/web_dav_set"
app:layout="@layout/view_preference_category"
app:allowDividerAbove="false" app:allowDividerAbove="false"
app:allowDividerBelow="false" app:allowDividerBelow="false"
app:iconSpaceReserved="false"> app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.EditTextPreference <io.legado.app.ui.widget.prefs.EditTextPreference
android:key="web_dav_url" android:key="web_dav_url"
android:title="@string/web_dav_url" android:title="@string/web_dav_url"
android:summary="@string/web_dav_url_s" android:summary="@string/web_dav_url_s"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.EditTextPreference <io.legado.app.ui.widget.prefs.EditTextPreference
android:key="web_dav_account" android:key="web_dav_account"
android:title="@string/web_dav_account" android:title="@string/web_dav_account"
android:summary="@string/web_dav_account_s" android:summary="@string/web_dav_account_s"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.EditTextPreference <io.legado.app.ui.widget.prefs.EditTextPreference
android:key="web_dav_password" android:key="web_dav_password"
android:title="@string/web_dav_pw" android:title="@string/web_dav_pw"
android:summary="@string/web_dav_pw_s" android:summary="@string/web_dav_pw_s"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.SwitchPreference <io.legado.app.ui.widget.prefs.SwitchPreference
android:key="webDavCreateDir" android:key="webDavCreateDir"
android:defaultValue="true" android:defaultValue="true"
android:title="@string/mkdirs" android:title="@string/mkdirs"
android:summary="@string/mkdirs_description" android:summary="@string/mkdirs_description"
app:allowDividerAbove="false" app:allowDividerAbove="false"
app:allowDividerBelow="false" app:allowDividerBelow="false"
app:iconSpaceReserved="false" /> app:iconSpaceReserved="false" />
</io.legado.app.ui.widget.prefs.PreferenceCategory> </io.legado.app.ui.widget.prefs.PreferenceCategory>
<io.legado.app.ui.widget.prefs.PreferenceCategory <io.legado.app.ui.widget.prefs.PreferenceCategory
app:layout="@layout/view_preference_category"
app:allowDividerBelow="false" app:allowDividerBelow="false"
app:iconSpaceReserved="false"> app:iconSpaceReserved="false"
app:layout="@layout/view_preference_category">
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="backupUri" android:key="backupUri"
android:title="@string/backup_path" android:title="@string/backup_path"
app:iconSpaceReserved="false" /> android:summary="@string/select_backup_path"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="web_dav_backup" android:key="web_dav_backup"
android:title="@string/backup" android:title="@string/backup"
app:iconSpaceReserved="false" /> android:summary="@string/backup_summary"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="web_dav_restore" android:key="web_dav_restore"
android:title="@string/restore" android:title="@string/restore"
app:iconSpaceReserved="false" /> android:summary="@string/restore_summary"
app:iconSpaceReserved="false" />
<io.legado.app.ui.widget.prefs.Preference <io.legado.app.ui.widget.prefs.Preference
android:key="import_old" android:key="import_old"
android:title="@string/menu_import_old_version" android:title="@string/menu_import_old_version"
app:iconSpaceReserved="false" /> android:summary="@string/import_old_summary"
app:iconSpaceReserved="false" />
</io.legado.app.ui.widget.prefs.PreferenceCategory> </io.legado.app.ui.widget.prefs.PreferenceCategory>

Loading…
Cancel
Save