From d6429d35b6b0c26d54b3711bceef9b5ab58b6011 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 22:22:19 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/help/http/AjaxWebView.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index b57409671..f495024b2 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -160,8 +160,12 @@ class AjaxWebView { if (it.isNotEmpty() && it != "null") { val content = StringEscapeUtils.unescapeJson(it) .replace("^\"|\"$".toRegex(), "") - handler.obtainMessage(MSG_SUCCESS, StrResponse(url, content)) - .sendToTarget() + try { + val response = StrResponse(url, content) + handler.obtainMessage(MSG_SUCCESS, response).sendToTarget() + } catch (e: Exception) { + handler.obtainMessage(MSG_ERROR, e).sendToTarget() + } handler.removeCallbacks(this) return@evaluateJavascript } @@ -186,10 +190,12 @@ class AjaxWebView { override fun onLoadResource(view: WebView, url: String) { params.sourceRegex?.let { if (url.matches(it.toRegex())) { - handler.obtainMessage( - MSG_SUCCESS, - StrResponse(view.url ?: params.url, url) - ).sendToTarget() + try { + val response = StrResponse(view.url ?: params.url, url) + handler.obtainMessage(MSG_SUCCESS, response).sendToTarget() + } catch (e: Exception) { + handler.obtainMessage(MSG_ERROR, e).sendToTarget() + } } } } From e99cfe10835c2b6f18e10152344203631640a6be Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 22:39:20 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dbug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../book/changesource/ChangeSourceDialog.kt | 21 +++++++++++-------- .../app/ui/book/search/SearchActivity.kt | 21 +++++++++++-------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index d0f79f980..ef0d4661f 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -208,21 +208,24 @@ class ChangeSourceDialog : BaseDialogFragment(), */ private fun upGroupMenu() { val menu: Menu = binding.toolBar.menu - val selectedGroup = getPrefString("searchGroup") ?: "" + val selectedGroup = getPrefString("searchGroup") menu.removeGroup(R.id.source_group) - var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) - if (selectedGroup == "") { - item?.isChecked = true - } + val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) + var hasSelectedGroup = false groups.sortedWith { o1, o2 -> o1.cnCompare(o2) - }.map { - item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - if (it == selectedGroup) { - item.isChecked = true + }.forEach { group -> + menu.add(R.id.source_group, Menu.NONE, Menu.NONE, group)?.let { + if (group == selectedGroup) { + it.isChecked = true + hasSelectedGroup = true + } } } menu.setGroupCheckable(R.id.source_group, true, true) + if (!hasSelectedGroup) { + allItem.isChecked = true + } } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 0db6df716..74bd36c27 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -238,21 +238,24 @@ class SearchActivity : VMBaseActivity - val selectedGroup = getPrefString("searchGroup") ?: "" + val selectedGroup = getPrefString("searchGroup") menu.removeGroup(R.id.source_group) - var item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) - if (selectedGroup == "") { - item?.isChecked = true - } + val allItem = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, R.string.all_source) + var hasSelectedGroup = false groups.sortedWith { o1, o2 -> o1.cnCompare(o2) - }.map { - item = menu.add(R.id.source_group, Menu.NONE, Menu.NONE, it) - if (it == selectedGroup) { - item?.isChecked = true + }.forEach { group -> + menu.add(R.id.source_group, Menu.NONE, Menu.NONE, group)?.let { + if (group == selectedGroup) { + it.isChecked = true + hasSelectedGroup = true + } } } menu.setGroupCheckable(R.id.source_group, true, true) + if (!hasSelectedGroup) { + allItem.isChecked = true + } } /** From d80e70ca8de47d820e0f2d2ec85311f124aee0e2 Mon Sep 17 00:00:00 2001 From: gedoor Date: Mon, 14 Dec 2020 22:46:16 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/help/http/AjaxWebView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt index f495024b2..3c9f0c8b6 100644 --- a/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt +++ b/app/src/main/java/io/legado/app/help/http/AjaxWebView.kt @@ -191,7 +191,7 @@ class AjaxWebView { params.sourceRegex?.let { if (url.matches(it.toRegex())) { try { - val response = StrResponse(view.url ?: params.url, url) + val response = StrResponse(params.url, url) handler.obtainMessage(MSG_SUCCESS, response).sendToTarget() } catch (e: Exception) { handler.obtainMessage(MSG_ERROR, e).sendToTarget()