pull/37/head
kunfei 5 years ago
parent c513db1005
commit a65e2d3f0b
  1. 6
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt
  2. 14
      app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt
  3. 5
      app/src/main/res/menu/rss_articles.xml
  4. 1
      app/src/main/res/values/strings.xml

@ -14,9 +14,11 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.RssArticle
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.rss.read.ReadRssActivity
import io.legado.app.ui.rss.source.edit.RssSourceEditActivity
import io.legado.app.utils.getViewModel
import kotlinx.android.synthetic.main.activity_rss_artivles.*
import org.jetbrains.anko.startActivity
import org.jetbrains.anko.startActivityForResult
class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activity_rss_artivles),
RssArticlesAdapter.CallBack {
@ -24,6 +26,7 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
override val viewModel: RssArticlesViewModel
get() = getViewModel(RssArticlesViewModel::class.java)
private val editSource = 12319
private var adapter: RssArticlesAdapter? = null
private var rssArticlesData: LiveData<List<RssArticle>>? = null
@ -47,6 +50,9 @@ class RssArticlesActivity : VMBaseActivity<RssArticlesViewModel>(R.layout.activi
override fun onCompatOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId) {
R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let {
startActivityForResult<RssSourceEditActivity>(editSource, Pair("data", it))
}
R.id.menu_clear -> {
intent.getStringExtra("url")?.let {
refresh_progress_bar.isAutoLoading = true

@ -11,18 +11,19 @@ import kotlinx.coroutines.Dispatchers.IO
class RssArticlesViewModel(application: Application) : BaseViewModel(application) {
var rssSource: RssSource? = null
val titleLiveData = MutableLiveData<String>()
fun loadContent(url: String, onFinally: () -> Unit) {
execute {
var rssSource = App.db.rssSourceDao().getByKey(url)
if (rssSource == null) {
rssSource = App.db.rssSourceDao().getByKey(url)
rssSource?.let {
titleLiveData.postValue(it.sourceName)
} ?: let {
rssSource = RssSource(sourceUrl = url)
} else {
titleLiveData.postValue(rssSource.sourceName)
}
Rss.getArticles(rssSource, this)
rssSource?.let {
Rss.getArticles(it, this)
.onSuccess(IO) {
it?.let {
App.db.rssArticleDao().insert(*it.toTypedArray())
@ -34,6 +35,7 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application
}
}
}
}
fun read(rssArticle: RssArticle) {
execute {

@ -2,6 +2,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/menu_edit_source"
android:title="@string/edit_source"
app:showAsAction="never" />
<item
android:id="@+id/menu_clear"
android:title="@string/clear"

@ -144,6 +144,7 @@
<string name="aloud_stop">朗读停止</string>
<string name="clear_cache">清除缓存</string>
<string name="action_save">保存</string>
<string name="edit_source">编辑源</string>
<string name="edit_book_source">编辑书源</string>
<string name="disable_book_source">禁用书源</string>
<string name="add_book_source">新建书源</string>

Loading…
Cancel
Save