From 8324af33040e27e6d5e71d46746b1554b09c5d17 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 23 Feb 2023 14:38:34 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/data/entities/BookSource.kt | 7 +- .../io/legado/app/data/entities/RssSource.kt | 5 +- .../source/edit/BookSourceEditActivity.kt | 163 +++++++++--------- .../rss/source/edit/RssSourceEditActivity.kt | 61 +++---- .../res/layout/activity_book_source_edit.xml | 2 +- 5 files changed, 119 insertions(+), 119 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/entities/BookSource.kt b/app/src/main/java/io/legado/app/data/entities/BookSource.kt index 0d9a8255b..317579cee 100644 --- a/app/src/main/java/io/legado/app/data/entities/BookSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/BookSource.kt @@ -38,12 +38,12 @@ data class BookSource( // 是否启用 var enabled: Boolean = true, // 启用发现 - var enabledExplore: Boolean = false, + var enabledExplore: Boolean = true, // 启用段评 var enabledReview: Boolean? = false, // 启用okhttp CookieJAr 自动保存每次请求的cookie @ColumnInfo(defaultValue = "0") - override var enabledCookieJar: Boolean? = false, + override var enabledCookieJar: Boolean? = true, // 并发率 override var concurrentRate: String? = null, // 请求头 @@ -192,8 +192,7 @@ data class BookSource( } } - fun equal(source: BookSource?): Boolean { - source ?: return false + fun equal(source: BookSource): Boolean { return equal(bookSourceName, source.bookSourceName) && equal(bookSourceUrl, source.bookSourceUrl) && equal(bookSourceGroup, source.bookSourceGroup) diff --git a/app/src/main/java/io/legado/app/data/entities/RssSource.kt b/app/src/main/java/io/legado/app/data/entities/RssSource.kt index cc245a88a..71965fd28 100644 --- a/app/src/main/java/io/legado/app/data/entities/RssSource.kt +++ b/app/src/main/java/io/legado/app/data/entities/RssSource.kt @@ -26,7 +26,7 @@ data class RssSource( // 自定义变量说明 var variableComment: String? = null, @ColumnInfo(defaultValue = "0") - override var enabledCookieJar: Boolean? = false, + override var enabledCookieJar: Boolean? = true, /**并发率**/ override var concurrentRate: String? = null, /**请求头**/ @@ -101,8 +101,7 @@ data class RssSource( override fun hashCode() = sourceUrl.hashCode() - fun equal(source: RssSource?): Boolean { - source ?: return false + fun equal(source: RssSource): Boolean { return equal(sourceUrl, source.sourceUrl) && equal(sourceName, source.sourceName) && equal(sourceIcon, source.sourceIcon) diff --git a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt index e5bb4d25e..28b3df4d5 100644 --- a/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/source/edit/BookSourceEditActivity.kt @@ -103,7 +103,7 @@ class BookSourceEditActivity : override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { R.id.menu_save -> getSource().let { source -> - if (!source.equal(viewModel.bookSource)) { + if (!source.equal(viewModel.bookSource ?: BookSource())) { source.lastUpdateTime = System.currentTimeMillis() } if (checkSource(source)) { @@ -193,7 +193,7 @@ class BookSourceEditActivity : override fun finish() { val source = getSource() - if (!source.equal(viewModel.bookSource)) { + if (!source.equal(viewModel.bookSource ?: BookSource())) { alert(R.string.exit) { setMessage(R.string.exit_no_save) positiveButton(R.string.yes) @@ -224,8 +224,9 @@ class BookSourceEditActivity : binding.recyclerView.scrollToPosition(0) } - private fun upSourceView(source: BookSource? = viewModel.bookSource) { - source?.let { + private fun upSourceView(bookSource: BookSource? = viewModel.bookSource) { + val bs = bookSource ?: BookSource() + bs.let { binding.cbIsEnable.isChecked = it.enabled binding.cbIsEnableExplore.isChecked = it.enabledExplore binding.cbIsEnableCookie.isChecked = it.enabledCookieJar ?: false @@ -242,107 +243,107 @@ class BookSourceEditActivity : // 基本信息 sourceEntities.clear() sourceEntities.apply { - add(EditEntity("bookSourceUrl", source?.bookSourceUrl, R.string.source_url)) - add(EditEntity("bookSourceName", source?.bookSourceName, R.string.source_name)) - add(EditEntity("bookSourceGroup", source?.bookSourceGroup, R.string.source_group)) - add(EditEntity("bookSourceComment", source?.bookSourceComment, R.string.comment)) - add(EditEntity("loginUrl", source?.loginUrl, R.string.login_url)) - add(EditEntity("loginUi", source?.loginUi, R.string.login_ui)) - add(EditEntity("loginCheckJs", source?.loginCheckJs, R.string.login_check_js)) - add(EditEntity("coverDecodeJs", source?.coverDecodeJs, R.string.cover_decode_js)) - add(EditEntity("bookUrlPattern", source?.bookUrlPattern, R.string.book_url_pattern)) - add(EditEntity("header", source?.header, R.string.source_http_header)) - add(EditEntity("variableComment", source?.variableComment, R.string.variable_comment)) - add(EditEntity("concurrentRate", source?.concurrentRate, R.string.concurrent_rate)) + add(EditEntity("bookSourceUrl", bs.bookSourceUrl, R.string.source_url)) + add(EditEntity("bookSourceName", bs.bookSourceName, R.string.source_name)) + add(EditEntity("bookSourceGroup", bs.bookSourceGroup, R.string.source_group)) + add(EditEntity("bookSourceComment", bs.bookSourceComment, R.string.comment)) + add(EditEntity("loginUrl", bs.loginUrl, R.string.login_url)) + add(EditEntity("loginUi", bs.loginUi, R.string.login_ui)) + add(EditEntity("loginCheckJs", bs.loginCheckJs, R.string.login_check_js)) + add(EditEntity("coverDecodeJs", bs.coverDecodeJs, R.string.cover_decode_js)) + add(EditEntity("bookUrlPattern", bs.bookUrlPattern, R.string.book_url_pattern)) + add(EditEntity("header", bs.header, R.string.source_http_header)) + add(EditEntity("variableComment", bs.variableComment, R.string.variable_comment)) + add(EditEntity("concurrentRate", bs.concurrentRate, R.string.concurrent_rate)) } // 搜索 - val sr = source?.getSearchRule() + val sr = bs.getSearchRule() searchEntities.clear() searchEntities.apply { - add(EditEntity("searchUrl", source?.searchUrl, R.string.r_search_url)) - add(EditEntity("checkKeyWord", sr?.checkKeyWord, R.string.check_key_word)) - add(EditEntity("bookList", sr?.bookList, R.string.r_book_list)) - add(EditEntity("name", sr?.name, R.string.r_book_name)) - add(EditEntity("author", sr?.author, R.string.r_author)) - add(EditEntity("kind", sr?.kind, R.string.rule_book_kind)) - add(EditEntity("wordCount", sr?.wordCount, R.string.rule_word_count)) - add(EditEntity("lastChapter", sr?.lastChapter, R.string.rule_last_chapter)) - add(EditEntity("intro", sr?.intro, R.string.rule_book_intro)) - add(EditEntity("coverUrl", sr?.coverUrl, R.string.rule_cover_url)) - add(EditEntity("bookUrl", sr?.bookUrl, R.string.r_book_url)) + add(EditEntity("searchUrl", bs.searchUrl, R.string.r_search_url)) + add(EditEntity("checkKeyWord", sr.checkKeyWord, R.string.check_key_word)) + add(EditEntity("bookList", sr.bookList, R.string.r_book_list)) + add(EditEntity("name", sr.name, R.string.r_book_name)) + add(EditEntity("author", sr.author, R.string.r_author)) + add(EditEntity("kind", sr.kind, R.string.rule_book_kind)) + add(EditEntity("wordCount", sr.wordCount, R.string.rule_word_count)) + add(EditEntity("lastChapter", sr.lastChapter, R.string.rule_last_chapter)) + add(EditEntity("intro", sr.intro, R.string.rule_book_intro)) + add(EditEntity("coverUrl", sr.coverUrl, R.string.rule_cover_url)) + add(EditEntity("bookUrl", sr.bookUrl, R.string.r_book_url)) } // 发现 - val er = source?.getExploreRule() + val er = bs.getExploreRule() exploreEntities.clear() exploreEntities.apply { - add(EditEntity("exploreUrl", source?.exploreUrl, R.string.r_find_url)) - add(EditEntity("bookList", er?.bookList, R.string.r_book_list)) - add(EditEntity("name", er?.name, R.string.r_book_name)) - add(EditEntity("author", er?.author, R.string.r_author)) - add(EditEntity("kind", er?.kind, R.string.rule_book_kind)) - add(EditEntity("wordCount", er?.wordCount, R.string.rule_word_count)) - add(EditEntity("lastChapter", er?.lastChapter, R.string.rule_last_chapter)) - add(EditEntity("intro", er?.intro, R.string.rule_book_intro)) - add(EditEntity("coverUrl", er?.coverUrl, R.string.rule_cover_url)) - add(EditEntity("bookUrl", er?.bookUrl, R.string.r_book_url)) + add(EditEntity("exploreUrl", bs.exploreUrl, R.string.r_find_url)) + add(EditEntity("bookList", er.bookList, R.string.r_book_list)) + add(EditEntity("name", er.name, R.string.r_book_name)) + add(EditEntity("author", er.author, R.string.r_author)) + add(EditEntity("kind", er.kind, R.string.rule_book_kind)) + add(EditEntity("wordCount", er.wordCount, R.string.rule_word_count)) + add(EditEntity("lastChapter", er.lastChapter, R.string.rule_last_chapter)) + add(EditEntity("intro", er.intro, R.string.rule_book_intro)) + add(EditEntity("coverUrl", er.coverUrl, R.string.rule_cover_url)) + add(EditEntity("bookUrl", er.bookUrl, R.string.r_book_url)) } // 详情页 - val ir = source?.getBookInfoRule() + val ir = bs.getBookInfoRule() infoEntities.clear() infoEntities.apply { - add(EditEntity("init", ir?.init, R.string.rule_book_info_init)) - add(EditEntity("name", ir?.name, R.string.r_book_name)) - add(EditEntity("author", ir?.author, R.string.r_author)) - add(EditEntity("kind", ir?.kind, R.string.rule_book_kind)) - add(EditEntity("wordCount", ir?.wordCount, R.string.rule_word_count)) - add(EditEntity("lastChapter", ir?.lastChapter, R.string.rule_last_chapter)) - add(EditEntity("intro", ir?.intro, R.string.rule_book_intro)) - add(EditEntity("coverUrl", ir?.coverUrl, R.string.rule_cover_url)) - add(EditEntity("tocUrl", ir?.tocUrl, R.string.rule_toc_url)) - add(EditEntity("canReName", ir?.canReName, R.string.rule_can_re_name)) - add(EditEntity("downloadUrls", ir?.downloadUrls, R.string.download_url_rule)) + add(EditEntity("init", ir.init, R.string.rule_book_info_init)) + add(EditEntity("name", ir.name, R.string.r_book_name)) + add(EditEntity("author", ir.author, R.string.r_author)) + add(EditEntity("kind", ir.kind, R.string.rule_book_kind)) + add(EditEntity("wordCount", ir.wordCount, R.string.rule_word_count)) + add(EditEntity("lastChapter", ir.lastChapter, R.string.rule_last_chapter)) + add(EditEntity("intro", ir.intro, R.string.rule_book_intro)) + add(EditEntity("coverUrl", ir.coverUrl, R.string.rule_cover_url)) + add(EditEntity("tocUrl", ir.tocUrl, R.string.rule_toc_url)) + add(EditEntity("canReName", ir.canReName, R.string.rule_can_re_name)) + add(EditEntity("downloadUrls", ir.downloadUrls, R.string.download_url_rule)) } // 目录页 - val tr = source?.getTocRule() + val tr = bs.getTocRule() tocEntities.clear() tocEntities.apply { - add(EditEntity("preUpdateJs", tr?.preUpdateJs, R.string.pre_update_js)) - add(EditEntity("chapterList", tr?.chapterList, R.string.rule_chapter_list)) - add(EditEntity("chapterName", tr?.chapterName, R.string.rule_chapter_name)) - add(EditEntity("chapterUrl", tr?.chapterUrl, R.string.rule_chapter_url)) - add(EditEntity("isVolume", tr?.isVolume, R.string.rule_is_volume)) - add(EditEntity("updateTime", tr?.updateTime, R.string.rule_update_time)) - add(EditEntity("isVip", tr?.isVip, R.string.rule_is_vip)) - add(EditEntity("isPay", tr?.isPay, R.string.rule_is_pay)) - add(EditEntity("nextTocUrl", tr?.nextTocUrl, R.string.rule_next_toc_url)) + add(EditEntity("preUpdateJs", tr.preUpdateJs, R.string.pre_update_js)) + add(EditEntity("chapterList", tr.chapterList, R.string.rule_chapter_list)) + add(EditEntity("chapterName", tr.chapterName, R.string.rule_chapter_name)) + add(EditEntity("chapterUrl", tr.chapterUrl, R.string.rule_chapter_url)) + add(EditEntity("isVolume", tr.isVolume, R.string.rule_is_volume)) + add(EditEntity("updateTime", tr.updateTime, R.string.rule_update_time)) + add(EditEntity("isVip", tr.isVip, R.string.rule_is_vip)) + add(EditEntity("isPay", tr.isPay, R.string.rule_is_pay)) + add(EditEntity("nextTocUrl", tr.nextTocUrl, R.string.rule_next_toc_url)) } // 正文页 - val cr = source?.getContentRule() + val cr = bs.getContentRule() contentEntities.clear() contentEntities.apply { - add(EditEntity("content", cr?.content, R.string.rule_book_content)) - add(EditEntity("nextContentUrl", cr?.nextContentUrl, R.string.rule_next_content)) - add(EditEntity("webJs", cr?.webJs, R.string.rule_web_js)) - add(EditEntity("sourceRegex", cr?.sourceRegex, R.string.rule_source_regex)) - add(EditEntity("replaceRegex", cr?.replaceRegex, R.string.rule_replace_regex)) - add(EditEntity("imageStyle", cr?.imageStyle, R.string.rule_image_style)) - add(EditEntity("imageDecode", cr?.imageDecode, R.string.rule_image_decode)) - add(EditEntity("payAction", cr?.payAction, R.string.rule_pay_action)) + add(EditEntity("content", cr.content, R.string.rule_book_content)) + add(EditEntity("nextContentUrl", cr.nextContentUrl, R.string.rule_next_content)) + add(EditEntity("webJs", cr.webJs, R.string.rule_web_js)) + add(EditEntity("sourceRegex", cr.sourceRegex, R.string.rule_source_regex)) + add(EditEntity("replaceRegex", cr.replaceRegex, R.string.rule_replace_regex)) + add(EditEntity("imageStyle", cr.imageStyle, R.string.rule_image_style)) + add(EditEntity("imageDecode", cr.imageDecode, R.string.rule_image_decode)) + add(EditEntity("payAction", cr.payAction, R.string.rule_pay_action)) } // 段评 - val rr = source?.getReviewRule() + val rr = bs.getReviewRule() reviewEntities.clear() reviewEntities.apply { - add(EditEntity("reviewUrl", rr?.reviewUrl, R.string.rule_review_url)) - add(EditEntity("avatarRule", rr?.avatarRule, R.string.rule_avatar)) - add(EditEntity("contentRule", rr?.contentRule, R.string.rule_review_content)) - add(EditEntity("postTimeRule", rr?.postTimeRule, R.string.rule_post_time)) - add(EditEntity("reviewQuoteUrl", rr?.reviewQuoteUrl, R.string.rule_review_quote)) - add(EditEntity("voteUpUrl", rr?.voteUpUrl, R.string.review_vote_up)) - add(EditEntity("voteDownUrl", rr?.voteDownUrl, R.string.review_vote_down)) - add(EditEntity("postReviewUrl", rr?.postReviewUrl, R.string.post_review_url)) - add(EditEntity("postQuoteUrl", rr?.postQuoteUrl, R.string.post_quote_url)) - add(EditEntity("deleteUrl", rr?.deleteUrl, R.string.delete_review_url)) + add(EditEntity("reviewUrl", rr.reviewUrl, R.string.rule_review_url)) + add(EditEntity("avatarRule", rr.avatarRule, R.string.rule_avatar)) + add(EditEntity("contentRule", rr.contentRule, R.string.rule_review_content)) + add(EditEntity("postTimeRule", rr.postTimeRule, R.string.rule_post_time)) + add(EditEntity("reviewQuoteUrl", rr.reviewQuoteUrl, R.string.rule_review_quote)) + add(EditEntity("voteUpUrl", rr.voteUpUrl, R.string.review_vote_up)) + add(EditEntity("voteDownUrl", rr.voteDownUrl, R.string.review_vote_down)) + add(EditEntity("postReviewUrl", rr.postReviewUrl, R.string.post_review_url)) + add(EditEntity("postQuoteUrl", rr.postQuoteUrl, R.string.post_quote_url)) + add(EditEntity("deleteUrl", rr.deleteUrl, R.string.delete_review_url)) } binding.tabLayout.selectTab(binding.tabLayout.getTabAt(0)) setEditEntities(0) diff --git a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt index dde1893b0..b0b6372e7 100644 --- a/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/source/edit/RssSourceEditActivity.kt @@ -76,7 +76,7 @@ class RssSourceEditActivity : override fun finish() { val source = getRssSource() - if (!source.equal(viewModel.rssSource)) { + if (!source.equal(viewModel.rssSource ?: RssSource())) { alert(R.string.exit) { setMessage(R.string.exit_no_save) positiveButton(R.string.yes) @@ -190,44 +190,45 @@ class RssSourceEditActivity : binding.recyclerView.scrollToPosition(0) } - private fun upSourceView(rs: RssSource? = viewModel.rssSource) { - rs?.let { + private fun upSourceView(rssSource: RssSource? = viewModel.rssSource) { + val rs = rssSource ?: RssSource() + rs.let { binding.cbIsEnable.isChecked = rs.enabled binding.cbSingleUrl.isChecked = rs.singleUrl binding.cbIsEnableCookie.isChecked = rs.enabledCookieJar == true } sourceEntities.clear() sourceEntities.apply { - add(EditEntity("sourceName", rs?.sourceName, R.string.source_name)) - add(EditEntity("sourceUrl", rs?.sourceUrl, R.string.source_url)) - add(EditEntity("sourceIcon", rs?.sourceIcon, R.string.source_icon)) - add(EditEntity("sourceGroup", rs?.sourceGroup, R.string.source_group)) - add(EditEntity("sourceComment", rs?.sourceComment, R.string.comment)) - add(EditEntity("sortUrl", rs?.sortUrl, R.string.sort_url)) - add(EditEntity("loginUrl", rs?.loginUrl, R.string.login_url)) - add(EditEntity("loginUi", rs?.loginUi, R.string.login_ui)) - add(EditEntity("loginCheckJs", rs?.loginCheckJs, R.string.login_check_js)) - add(EditEntity("coverDecodeJs", rs?.coverDecodeJs, R.string.cover_decode_js)) - add(EditEntity("header", rs?.header, R.string.source_http_header)) - add(EditEntity("variableComment", rs?.variableComment, R.string.variable_comment)) - add(EditEntity("concurrentRate", rs?.concurrentRate, R.string.concurrent_rate)) + add(EditEntity("sourceName", rs.sourceName, R.string.source_name)) + add(EditEntity("sourceUrl", rs.sourceUrl, R.string.source_url)) + add(EditEntity("sourceIcon", rs.sourceIcon, R.string.source_icon)) + add(EditEntity("sourceGroup", rs.sourceGroup, R.string.source_group)) + add(EditEntity("sourceComment", rs.sourceComment, R.string.comment)) + add(EditEntity("sortUrl", rs.sortUrl, R.string.sort_url)) + add(EditEntity("loginUrl", rs.loginUrl, R.string.login_url)) + add(EditEntity("loginUi", rs.loginUi, R.string.login_ui)) + add(EditEntity("loginCheckJs", rs.loginCheckJs, R.string.login_check_js)) + add(EditEntity("coverDecodeJs", rs.coverDecodeJs, R.string.cover_decode_js)) + add(EditEntity("header", rs.header, R.string.source_http_header)) + add(EditEntity("variableComment", rs.variableComment, R.string.variable_comment)) + add(EditEntity("concurrentRate", rs.concurrentRate, R.string.concurrent_rate)) } listEntities.clear() listEntities.apply { - add(EditEntity("ruleArticles", rs?.ruleArticles, R.string.r_articles)) - add(EditEntity("ruleNextPage", rs?.ruleNextPage, R.string.r_next)) - add(EditEntity("ruleTitle", rs?.ruleTitle, R.string.r_title)) - add(EditEntity("rulePubDate", rs?.rulePubDate, R.string.r_date)) - add(EditEntity("ruleDescription", rs?.ruleDescription, R.string.r_description)) - add(EditEntity("ruleImage", rs?.ruleImage, R.string.r_image)) - add(EditEntity("ruleLink", rs?.ruleLink, R.string.r_link)) + add(EditEntity("ruleArticles", rs.ruleArticles, R.string.r_articles)) + add(EditEntity("ruleNextPage", rs.ruleNextPage, R.string.r_next)) + add(EditEntity("ruleTitle", rs.ruleTitle, R.string.r_title)) + add(EditEntity("rulePubDate", rs.rulePubDate, R.string.r_date)) + add(EditEntity("ruleDescription", rs.ruleDescription, R.string.r_description)) + add(EditEntity("ruleImage", rs.ruleImage, R.string.r_image)) + add(EditEntity("ruleLink", rs.ruleLink, R.string.r_link)) } webViewEntities.clear() webViewEntities.apply { add( EditEntity( "enableJs", - rs?.enableJs.toString(), + rs.enableJs.toString(), R.string.enable_js, EditEntity.ViewType.checkBox ) @@ -235,16 +236,16 @@ class RssSourceEditActivity : add( EditEntity( "loadWithBaseUrl", - rs?.loadWithBaseUrl.toString(), + rs.loadWithBaseUrl.toString(), R.string.load_with_base_url, EditEntity.ViewType.checkBox ) ) - add(EditEntity("ruleContent", rs?.ruleContent, R.string.r_content)) - add(EditEntity("style", rs?.style, R.string.r_style)) - add(EditEntity("injectJs", rs?.injectJs, R.string.r_inject_js)) - add(EditEntity("contentWhitelist", rs?.contentWhitelist, R.string.c_whitelist)) - add(EditEntity("contentBlacklist", rs?.contentBlacklist, R.string.c_blacklist)) + add(EditEntity("ruleContent", rs.ruleContent, R.string.r_content)) + add(EditEntity("style", rs.style, R.string.r_style)) + add(EditEntity("injectJs", rs.injectJs, R.string.r_inject_js)) + add(EditEntity("contentWhitelist", rs.contentWhitelist, R.string.c_whitelist)) + add(EditEntity("contentBlacklist", rs.contentBlacklist, R.string.c_blacklist)) } binding.tabLayout.selectTab(binding.tabLayout.getTabAt(0)) setEditEntities(0) diff --git a/app/src/main/res/layout/activity_book_source_edit.xml b/app/src/main/res/layout/activity_book_source_edit.xml index 2137f59bd..2fadcb544 100644 --- a/app/src/main/res/layout/activity_book_source_edit.xml +++ b/app/src/main/res/layout/activity_book_source_edit.xml @@ -67,7 +67,7 @@ android:id="@+id/cb_is_enable_review" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:checked="true" + android:checked="false" android:text="@string/review" android:visibility="gone" />