diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt index 46825ee16..50d2676d3 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesActivity.kt @@ -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(R.layout.activity_rss_artivles), RssArticlesAdapter.CallBack { @@ -24,6 +26,7 @@ class RssArticlesActivity : VMBaseActivity(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>? = null @@ -47,6 +50,9 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { + R.id.menu_edit_source -> viewModel.rssSource?.sourceUrl?.let { + startActivityForResult(editSource, Pair("data", it)) + } R.id.menu_clear -> { intent.getStringExtra("url")?.let { refresh_progress_bar.isAutoLoading = true diff --git a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt index 745216ba4..8fc44c1c9 100644 --- a/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/article/RssArticlesViewModel.kt @@ -11,27 +11,29 @@ import kotlinx.coroutines.Dispatchers.IO class RssArticlesViewModel(application: Application) : BaseViewModel(application) { - + var rssSource: RssSource? = null val titleLiveData = MutableLiveData() 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) - .onSuccess(IO) { - it?.let { - App.db.rssArticleDao().insert(*it.toTypedArray()) + rssSource?.let { + Rss.getArticles(it, this) + .onSuccess(IO) { + it?.let { + App.db.rssArticleDao().insert(*it.toTypedArray()) + } + }.onError { + toast(it.localizedMessage) + }.onFinally { + onFinally() } - }.onError { - toast(it.localizedMessage) - }.onFinally { - onFinally() - } + } } } diff --git a/app/src/main/res/menu/rss_articles.xml b/app/src/main/res/menu/rss_articles.xml index cd68daa0f..03d187bcd 100644 --- a/app/src/main/res/menu/rss_articles.xml +++ b/app/src/main/res/menu/rss_articles.xml @@ -2,6 +2,11 @@ + + 朗读停止 清除缓存 保存 + 编辑源 编辑书源 禁用书源 新建书源