|
|
|
@ -5,6 +5,9 @@ import android.content.Intent |
|
|
|
|
import androidx.lifecycle.MutableLiveData |
|
|
|
|
import io.legado.app.App |
|
|
|
|
import io.legado.app.base.BaseViewModel |
|
|
|
|
import io.legado.app.data.entities.RssArticle |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeRule |
|
|
|
|
import io.legado.app.model.analyzeRule.AnalyzeUrl |
|
|
|
|
|
|
|
|
|
class ReadRssViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
@ -18,6 +21,17 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
if (rssArticle != null) { |
|
|
|
|
if (!rssArticle.description.isNullOrBlank()) { |
|
|
|
|
contentLiveData.postValue(rssArticle.description) |
|
|
|
|
} else { |
|
|
|
|
App.db.rssSourceDao().getByKey(rssArticle.origin)?.let { source -> |
|
|
|
|
val ruleContent = source.ruleContent |
|
|
|
|
if (!ruleContent.isNullOrBlank()) { |
|
|
|
|
loadContent(rssArticle, ruleContent) |
|
|
|
|
} else { |
|
|
|
|
urlLiveData.postValue(rssArticle.link) |
|
|
|
|
} |
|
|
|
|
} ?: let { |
|
|
|
|
urlLiveData.postValue(rssArticle.link) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
@ -25,4 +39,18 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun loadContent(rssArticle: RssArticle, ruleContent: String) { |
|
|
|
|
execute { |
|
|
|
|
rssArticle.link?.let { |
|
|
|
|
AnalyzeUrl(it).getResponseAsync().await().body()?.let { body -> |
|
|
|
|
AnalyzeRule().apply { |
|
|
|
|
setContent(body) |
|
|
|
|
getString(ruleContent)?.let { content -> |
|
|
|
|
contentLiveData.postValue(content) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |