From 4d8b48299965ae17339a37bd17b87ee826b8f99c Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 8 Oct 2019 14:02:16 +0800 Subject: [PATCH] up --- .../java/io/legado/app/model/rss/RssParser.kt | 5 ++-- .../legado/app/model/rss/RssParserByRule.kt | 27 ++++++++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/app/src/main/java/io/legado/app/model/rss/RssParser.kt b/app/src/main/java/io/legado/app/model/rss/RssParser.kt index 7363a349e..8efa0d7c3 100644 --- a/app/src/main/java/io/legado/app/model/rss/RssParser.kt +++ b/app/src/main/java/io/legado/app/model/rss/RssParser.kt @@ -84,8 +84,6 @@ object RssParser { } xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_TIME, true) -> if (insideItem) currentArticle.pubDate = xmlPullParser.nextText() - xmlPullParser.name.equals(RSSKeywords.RSS_ITEM_GUID, true) -> - if (insideItem) currentArticle.guid = xmlPullParser.nextText().trim() } } else if (eventType == XmlPullParser.END_TAG && xmlPullParser.name.equals("item", true) @@ -99,6 +97,9 @@ object RssParser { } eventType = xmlPullParser.next() } + for ((index: Int, item: RssArticle) in articleList.withIndex()) { + item.order = System.currentTimeMillis() + index + } return articleList } 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 45bbaf637..8ff17f063 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 @@ -11,7 +11,6 @@ object RssParserByRule { @Throws(Exception::class) fun parseXML(response: Response, rssSource: RssSource): MutableList { - val articleList = mutableListOf() val xml = response.body() if (xml.isNullOrBlank()) { @@ -22,12 +21,19 @@ object RssParserByRule { ) ) } - - rssSource.ruleArticles?.let { ruleArticles -> + var ruleArticles = rssSource.ruleArticles + if (ruleArticles.isNullOrBlank()) { + return RssParser.parseXML(xml, rssSource.sourceUrl) + } else { + val articleList = mutableListOf() val analyzeRule = AnalyzeRule() analyzeRule.setContent(xml) + var reverse = false + if (ruleArticles.startsWith("-")) { + reverse = true + ruleArticles = ruleArticles.substring(1) + } val collections = analyzeRule.getElements(ruleArticles) - val ruleGuid = analyzeRule.splitSourceRule(rssSource.ruleGuid ?: "") val ruleTitle = analyzeRule.splitSourceRule(rssSource.ruleTitle ?: "") val ruleAuthor = analyzeRule.splitSourceRule(rssSource.ruleAuthor ?: "") val rulePubDate = analyzeRule.splitSourceRule(rssSource.rulePubDate ?: "") @@ -41,7 +47,6 @@ object RssParserByRule { item, analyzeRule, index == 0, - ruleGuid, ruleTitle, ruleAuthor, rulePubDate, @@ -55,17 +60,20 @@ object RssParserByRule { articleList.add(it) } } - } ?: let { - return RssParser.parseXML(xml, rssSource.sourceUrl) + if (reverse) { + articleList.reverse() + } + for ((index: Int, item: RssArticle) in articleList.withIndex()) { + item.order = System.currentTimeMillis() + index + } + return articleList } - return articleList } private fun getItem( item: Any, analyzeRule: AnalyzeRule, printLog: Boolean, - ruleGuid: List, ruleTitle: List, ruleAuthor: List, rulePubDate: List, @@ -77,7 +85,6 @@ object RssParserByRule { ): RssArticle? { val rssArticle = RssArticle() analyzeRule.setContent(item) - rssArticle.guid = analyzeRule.getString(ruleGuid) rssArticle.title = analyzeRule.getString(ruleTitle) rssArticle.author = analyzeRule.getString(ruleAuthor) rssArticle.pubDate = analyzeRule.getString(rulePubDate)