|
@@ -14,6 +14,7 @@ import io.legado.app.data.appDb
|
|
|
import io.legado.app.data.entities.RssArticle
|
|
import io.legado.app.data.entities.RssArticle
|
|
|
import io.legado.app.data.entities.RssSource
|
|
import io.legado.app.data.entities.RssSource
|
|
|
import io.legado.app.data.entities.RssStar
|
|
import io.legado.app.data.entities.RssStar
|
|
|
|
|
+import io.legado.app.exception.NoStackTraceException
|
|
|
import io.legado.app.help.TTS
|
|
import io.legado.app.help.TTS
|
|
|
import io.legado.app.help.http.newCallResponseBody
|
|
import io.legado.app.help.http.newCallResponseBody
|
|
|
import io.legado.app.help.http.okHttpClient
|
|
import io.legado.app.help.http.okHttpClient
|
|
@@ -42,38 +43,35 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|
|
|
|
|
|
|
fun initData(intent: Intent) {
|
|
fun initData(intent: Intent) {
|
|
|
execute {
|
|
execute {
|
|
|
- val origin = intent.getStringExtra("origin")
|
|
|
|
|
|
|
+ val origin = intent.getStringExtra("origin") ?: return@execute
|
|
|
val link = intent.getStringExtra("link")
|
|
val link = intent.getStringExtra("link")
|
|
|
- origin?.let {
|
|
|
|
|
- rssSource = appDb.rssSourceDao.getByKey(origin)
|
|
|
|
|
- if (link != null) {
|
|
|
|
|
- rssStar = appDb.rssStarDao.get(origin, link)
|
|
|
|
|
- rssArticle = rssStar?.toRssArticle() ?: appDb.rssArticleDao.get(origin, link)
|
|
|
|
|
- rssArticle?.let { rssArticle ->
|
|
|
|
|
- if (!rssArticle.description.isNullOrBlank()) {
|
|
|
|
|
- contentLiveData.postValue(rssArticle.description!!)
|
|
|
|
|
|
|
+ rssSource = appDb.rssSourceDao.getByKey(origin)
|
|
|
|
|
+ if (link != null) {
|
|
|
|
|
+ rssStar = appDb.rssStarDao.get(origin, link)
|
|
|
|
|
+ rssArticle = rssStar?.toRssArticle() ?: appDb.rssArticleDao.get(origin, link)
|
|
|
|
|
+ val rssArticle = rssArticle ?: return@execute
|
|
|
|
|
+ if (!rssArticle.description.isNullOrBlank()) {
|
|
|
|
|
+ contentLiveData.postValue(rssArticle.description!!)
|
|
|
|
|
+ } else {
|
|
|
|
|
+ rssSource?.let {
|
|
|
|
|
+ val ruleContent = it.ruleContent
|
|
|
|
|
+ if (!ruleContent.isNullOrBlank()) {
|
|
|
|
|
+ loadContent(rssArticle, ruleContent)
|
|
|
} else {
|
|
} else {
|
|
|
- rssSource?.let {
|
|
|
|
|
- val ruleContent = it.ruleContent
|
|
|
|
|
- if (!ruleContent.isNullOrBlank()) {
|
|
|
|
|
- loadContent(rssArticle, ruleContent)
|
|
|
|
|
- } else {
|
|
|
|
|
- loadUrl(rssArticle.link, rssArticle.origin)
|
|
|
|
|
- }
|
|
|
|
|
- } ?: loadUrl(rssArticle.link, rssArticle.origin)
|
|
|
|
|
|
|
+ loadUrl(rssArticle.link, rssArticle.origin)
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ } ?: loadUrl(rssArticle.link, rssArticle.origin)
|
|
|
|
|
+ }
|
|
|
|
|
+ } else {
|
|
|
|
|
+ val ruleContent = rssSource?.ruleContent
|
|
|
|
|
+ if (ruleContent.isNullOrBlank()) {
|
|
|
|
|
+ loadUrl(origin, origin)
|
|
|
} else {
|
|
} else {
|
|
|
- val ruleContent = rssSource?.ruleContent
|
|
|
|
|
- if (ruleContent.isNullOrBlank()) {
|
|
|
|
|
- loadUrl(origin, origin)
|
|
|
|
|
- } else {
|
|
|
|
|
- val rssArticle = RssArticle()
|
|
|
|
|
- rssArticle.origin = origin
|
|
|
|
|
- rssArticle.link = origin
|
|
|
|
|
- rssArticle.title = rssSource!!.sourceName
|
|
|
|
|
- loadContent(rssArticle, ruleContent)
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ val rssArticle = RssArticle()
|
|
|
|
|
+ rssArticle.origin = origin
|
|
|
|
|
+ rssArticle.link = origin
|
|
|
|
|
+ rssArticle.title = rssSource!!.sourceName
|
|
|
|
|
+ loadContent(rssArticle, ruleContent)
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}.onFinally {
|
|
}.onFinally {
|
|
@@ -91,18 +89,17 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
private fun loadContent(rssArticle: RssArticle, ruleContent: String) {
|
|
private fun loadContent(rssArticle: RssArticle, ruleContent: String) {
|
|
|
- rssSource?.let { source ->
|
|
|
|
|
- Rss.getContent(viewModelScope, rssArticle, ruleContent, source)
|
|
|
|
|
- .onSuccess(IO) { body ->
|
|
|
|
|
- rssArticle.description = body
|
|
|
|
|
- appDb.rssArticleDao.insert(rssArticle)
|
|
|
|
|
- rssStar?.let {
|
|
|
|
|
- it.description = body
|
|
|
|
|
- appDb.rssStarDao.insert(it)
|
|
|
|
|
- }
|
|
|
|
|
- contentLiveData.postValue(body)
|
|
|
|
|
|
|
+ val source = rssSource ?: return
|
|
|
|
|
+ Rss.getContent(viewModelScope, rssArticle, ruleContent, source)
|
|
|
|
|
+ .onSuccess(IO) { body ->
|
|
|
|
|
+ rssArticle.description = body
|
|
|
|
|
+ appDb.rssArticleDao.insert(rssArticle)
|
|
|
|
|
+ rssStar?.let {
|
|
|
|
|
+ it.description = body
|
|
|
|
|
+ appDb.rssStarDao.insert(it)
|
|
|
}
|
|
}
|
|
|
- }
|
|
|
|
|
|
|
+ contentLiveData.postValue(body)
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
fun refresh(finish: () -> Unit) {
|
|
fun refresh(finish: () -> Unit) {
|
|
@@ -139,18 +136,8 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|
|
webPic ?: return
|
|
webPic ?: return
|
|
|
execute {
|
|
execute {
|
|
|
val fileName = "${AppConst.fileNameFormat.format(Date(System.currentTimeMillis()))}.jpg"
|
|
val fileName = "${AppConst.fileNameFormat.format(Date(System.currentTimeMillis()))}.jpg"
|
|
|
- webData2bitmap(webPic)?.let { biteArray ->
|
|
|
|
|
- if (uri.isContentScheme()) {
|
|
|
|
|
- DocumentFile.fromTreeUri(context, uri)?.let { doc ->
|
|
|
|
|
- DocumentUtils.createFileIfNotExist(doc, fileName)
|
|
|
|
|
- ?.writeBytes(context, biteArray)
|
|
|
|
|
- }
|
|
|
|
|
- } else {
|
|
|
|
|
- val dir = File(uri.path ?: uri.toString())
|
|
|
|
|
- val file = FileUtils.createFileIfNotExist(dir, fileName)
|
|
|
|
|
- file.writeBytes(biteArray)
|
|
|
|
|
- }
|
|
|
|
|
- } ?: throw Throwable("NULL")
|
|
|
|
|
|
|
+ val byteArray = webData2bitmap(webPic) ?: throw NoStackTraceException("NULL")
|
|
|
|
|
+ uri.writeBytes(context, fileName, byteArray)
|
|
|
}.onError {
|
|
}.onError {
|
|
|
context.toastOnUi("保存图片失败:${it.localizedMessage}")
|
|
context.toastOnUi("保存图片失败:${it.localizedMessage}")
|
|
|
}.onSuccess {
|
|
}.onSuccess {
|
|
@@ -178,9 +165,11 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application) {
|
|
|
$content
|
|
$content
|
|
|
""".trimIndent()
|
|
""".trimIndent()
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
content.contains("<style>".toRegex()) -> {
|
|
content.contains("<style>".toRegex()) -> {
|
|
|
content
|
|
content
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
else -> {
|
|
else -> {
|
|
|
"""
|
|
"""
|
|
|
<style>
|
|
<style>
|