pull/35/head^2
parent
4356e9e30e
commit
26d040c39b
@ -1,14 +1,17 @@ |
||||
package io.legado.app.data.dao |
||||
|
||||
import androidx.lifecycle.LiveData |
||||
import androidx.room.Insert |
||||
import androidx.room.OnConflictStrategy |
||||
import androidx.room.Query |
||||
import io.legado.app.data.entities.RssArticle |
||||
|
||||
interface RssArticleDao { |
||||
|
||||
|
||||
@Query("select * from rssArticles where origin = :origin") |
||||
@Query("select * from rssArticles where origin = :origin order by time desc") |
||||
fun liveByOrigin(origin: String): LiveData<List<RssArticle>> |
||||
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE) |
||||
fun insert(vararg rssArticle: RssArticle) |
||||
} |
@ -1,12 +1,20 @@ |
||||
package io.legado.app.ui.rss.article |
||||
|
||||
import android.app.Application |
||||
import io.legado.app.App |
||||
import io.legado.app.base.BaseViewModel |
||||
import io.legado.app.model.rss.RssParser |
||||
import java.net.URL |
||||
|
||||
|
||||
class RssArticlesViewModel(application: Application) : BaseViewModel(application) { |
||||
|
||||
fun loadContent(url: String) { |
||||
|
||||
execute { |
||||
val xml = URL(url).readText() |
||||
RssParser.parseXML(xml).let { |
||||
App.db.rssArtivleDao().insert(*it.toTypedArray()) |
||||
} |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue