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 com.jeremyliao.liveeventbus.**
-keep class com.google.gson.** { *; }
-keep class com.ke.gson.** { *; }
-keep class com.jeremyliao.liveeventbus.** { *; }
-keep class okhttp3.**{*;}
-keep class okio.**{*;}

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

@ -15,6 +15,7 @@ val GSON: Gson by lazy {
object : TypeToken<Map<String?, Any?>?>() {}.type,
MapDeserializerDoubleAsIntFix()
)
.registerTypeAdapter(Int::class.java, IntJsonDeserializer())
.disableHtmlEscaping()
.setPrettyPrinting()
.create()
@ -44,6 +45,32 @@ class ParameterizedTypeImpl(private val clazz: Class<*>) : ParameterizedType {
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的问题
*/
@ -60,20 +87,20 @@ class MapDeserializerDoubleAsIntFix :
return read(jsonElement) as? Map<String, Any?>
}
fun read(`in`: JsonElement): Any? {
fun read(json: JsonElement): Any? {
when {
`in`.isJsonArray -> {
json.isJsonArray -> {
val list: MutableList<Any?> = ArrayList()
val arr = `in`.asJsonArray
val arr = json.asJsonArray
for (anArr in arr) {
list.add(read(anArr))
}
return list
}
`in`.isJsonObject -> {
json.isJsonObject -> {
val map: MutableMap<String, Any?> =
LinkedTreeMap()
val obj = `in`.asJsonObject
val obj = json.asJsonObject
val entitySet =
obj.entrySet()
for ((key, value) in entitySet) {
@ -81,8 +108,8 @@ class MapDeserializerDoubleAsIntFix :
}
return map
}
`in`.isJsonPrimitive -> {
val prim = `in`.asJsonPrimitive
json.isJsonPrimitive -> {
val prim = json.asJsonPrimitive
when {
prim.isBoolean -> {
return prim.asBoolean

@ -695,4 +695,10 @@
<string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</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>

@ -664,7 +664,7 @@
<string name="contact">聯繫我們</string>
<string name="license">開源許可</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="wechat">微信</string>
<string name="thanks">您的支援是我更新的動力</string>
@ -697,5 +697,9 @@
<string name="auto_page_speed">自動翻頁速度</string>
<string name="sort_by_url">地址排序</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>

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

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

Loading…
Cancel
Save