pull/737/head
Robot 4 years ago
commit 65cc0d566e
  1. 18
      app/src/main/java/io/legado/app/help/http/AjaxWebView.kt
  2. 21
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  3. 21
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.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(params.url, url)
handler.obtainMessage(MSG_SUCCESS, response).sendToTarget()
} catch (e: Exception) {
handler.obtainMessage(MSG_ERROR, e).sendToTarget()
}
}
}
}

@ -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 {

@ -238,21 +238,24 @@ class SearchActivity : VMBaseActivity<ActivityBookSearchBinding, SearchViewModel
* 更新分组菜单
*/
private fun upGroupMenu() = menu?.let { 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
}
}
/**

Loading…
Cancel
Save