|
|
|
@ -4,9 +4,9 @@ import android.app.Application |
|
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
import io.legado.app.model.rss.RssParser |
|
|
|
|
import io.legado.app.model.rss.RssParserByRule |
|
|
|
|
import java.net.URL |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RssArticlesViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
@ -19,14 +19,15 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application |
|
|
|
|
rssSource?.let { |
|
|
|
|
titleLiveData.postValue(rssSource.sourceName) |
|
|
|
|
} |
|
|
|
|
val xml = URL(url).readText() |
|
|
|
|
if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { |
|
|
|
|
RssParser.parseXML(xml, url).let { |
|
|
|
|
App.db.rssArtivleDao().insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
RssParserByRule.parseXML(xml, rssSource).let { |
|
|
|
|
App.db.rssArtivleDao().insert(*it.toTypedArray()) |
|
|
|
|
AnalyzeUrl(url).getResponseAsync().await().body()?.let { xml -> |
|
|
|
|
if (rssSource == null || rssSource.ruleArticles.isNullOrBlank()) { |
|
|
|
|
RssParser.parseXML(xml, url).let { |
|
|
|
|
App.db.rssArtivleDao().insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
RssParserByRule.parseXML(xml, rssSource).let { |
|
|
|
|
App.db.rssArtivleDao().insert(*it.toTypedArray()) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
}.onFinally { |
|
|
|
|