From 4c47e4a24a020068abe70cfe021a1f904a1912e4 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 8 Mar 2022 14:32:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B9=A6=E7=B1=8D=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E4=BC=98=E5=85=88=E5=8C=B9=E9=85=8D=E5=90=AF=E7=94=A8?= =?UTF-8?q?=E7=9A=84=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt | 2 +- .../main/java/io/legado/app/model/rss/RssParserByRule.kt | 2 +- .../io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt index 4790cb5c3..f721dca47 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookSourceDao.kt @@ -74,7 +74,7 @@ interface BookSourceDao { @Query("select * from book_sources where enabled = 1 and bookSourceGroup like '%' || :group || '%'") fun getEnabledByGroup(group: String): List - @get:Query("select * from book_sources where trim(bookUrlPattern) <> ''") + @get:Query("select * from book_sources where trim(bookUrlPattern) <> '' order by enabled desc, customOrder") val hasBookUrlPattern: List @get:Query("select * from book_sources where bookSourceGroup is null or bookSourceGroup = ''") diff --git a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt index aabe26f98..f97f806aa 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParserByRule.kt @@ -117,7 +117,7 @@ object RssParserByRule { Debug.log(sourceUrl, "┌获取文章链接", log) rssArticle.link = NetworkUtils.getAbsoluteURL(sourceUrl, analyzeRule.getString(ruleLink)) Debug.log(sourceUrl, "└${rssArticle.link}", log) - rssArticle.variable = GSON.toJson(analyzeRule.ruleData.variableMap) + rssArticle.variable = analyzeRule.ruleData?.variableMap?.let { GSON.toJson(it) } if (rssArticle.title.isBlank()) { return null } diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt index c63b8c569..80d287fdf 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfViewModel.kt @@ -24,7 +24,9 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) fun addBookByUrl(bookUrls: String) { var successCount = 0 execute { - var hasBookUrlPattern: List? = null + val hasBookUrlPattern: List by lazy { + appDb.bookSourceDao.hasBookUrlPattern + } val urls = bookUrls.split("\n") for (url in urls) { val bookUrl = url.trim() @@ -33,9 +35,6 @@ class BookshelfViewModel(application: Application) : BaseViewModel(application) val baseUrl = NetworkUtils.getBaseUrl(bookUrl) ?: continue var source = appDb.bookSourceDao.getBookSource(baseUrl) if (source == null) { - if (hasBookUrlPattern == null) { - hasBookUrlPattern = appDb.bookSourceDao.hasBookUrlPattern - } hasBookUrlPattern.forEach { bookSource -> if (bookUrl.matches(bookSource.bookUrlPattern!!.toRegex())) { source = bookSource