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 19bb003eb..c3fd923bc 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 @@ -28,125 +28,108 @@ object RssParser { var eventType = xmlPullParser.eventType // Start parsing the xml - while (eventType != XmlPullParser.END_DOCUMENT) { + loop@ while (eventType != XmlPullParser.END_DOCUMENT) { // Start parsing the item if (eventType == XmlPullParser.START_TAG) { - if (xmlPullParser.name.equals(RSSKeywords.RSS_ITEM, ignoreCase = true)) { - insideItem = true - - } else if (xmlPullParser.name.equals( + when { + xmlPullParser.name.equals( + RSSKeywords.RSS_ITEM, + ignoreCase = true + ) -> insideItem = true + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_TITLE, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.title = xmlPullParser.nextText().trim() } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_LINK, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.link = xmlPullParser.nextText().trim() } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_AUTHOR, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.author = xmlPullParser.nextText().trim() } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_CATEGORY, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.categories.add(xmlPullParser.nextText().trim()) } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_THUMBNAIL, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.image = xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_URL) } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_ENCLOSURE, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { val type = xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_TYPE) if (type != null && type.contains("image/")) { currentArticle.image = xmlPullParser.getAttributeValue(null, RSSKeywords.RSS_ITEM_URL) } } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_DESCRIPTION, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { val description = xmlPullParser.nextText() currentArticle.description = description.trim() if (currentArticle.image == null) { currentArticle.image = getImageUrl(description) } } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_CONTENT, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { val content = xmlPullParser.nextText().trim() currentArticle.content = content if (currentArticle.image == null) { currentArticle.image = getImageUrl(content) } } - - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_PUB_DATE, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { val nextTokenType = xmlPullParser.next() if (nextTokenType == XmlPullParser.TEXT) { currentArticle.pubDate = xmlPullParser.text.trim() } // Skip to be able to find date inside 'tag' tag - continue + continue@loop } - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_TIME, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.pubDate = xmlPullParser.nextText() } - } else if (xmlPullParser.name.equals( + xmlPullParser.name.equals( RSSKeywords.RSS_ITEM_GUID, ignoreCase = true ) - ) { - if (insideItem) { + -> if (insideItem) { currentArticle.guid = xmlPullParser.nextText().trim() } }