From e1f0afc69291d41f3e64fe3087e40a672932886e Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 8 Oct 2019 14:43:36 +0800 Subject: [PATCH] up --- .../io/legado/app/data/dao/RssArticleDao.kt | 3 +++ .../app/ui/rss/article/RssArticlesActivity.kt | 21 +++++++++++++++++++ .../ui/rss/article/RssArticlesViewModel.kt | 6 ++++++ 3 files changed, 30 insertions(+) diff --git a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt index 44c333ac7..a38fa15d9 100644 --- a/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/RssArticleDao.kt @@ -18,4 +18,7 @@ interface RssArticleDao { @Update fun update(vararg rssArticle: RssArticle) + + @Query("delete from rssArticles where origin = :origin") + fun delete(origin: String) } \ No newline at end of file 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 beeb737d1..6b97443fb 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 @@ -1,6 +1,8 @@ package io.legado.app.ui.rss.article import android.os.Bundle +import android.view.Menu +import android.view.MenuItem import androidx.core.content.ContextCompat import androidx.lifecycle.LiveData import androidx.lifecycle.Observer @@ -38,6 +40,25 @@ class RssArticlesActivity : VMBaseActivity(R.layout.activi } } + override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { + menuInflater.inflate(R.menu.rss_articles, menu) + return super.onCompatCreateOptionsMenu(menu) + } + + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { + when (item.itemId) { + R.id.menu_clear -> { + intent.getStringExtra("url")?.let { + refresh_progress_bar.isAutoLoading = true + viewModel.loadContent(it) { + refresh_progress_bar.isAutoLoading = false + } + } + } + } + return super.onCompatOptionsItemSelected(item) + } + private fun initView() { ATH.applyEdgeEffectColor(recycler_view) recycler_view.layoutManager = LinearLayoutManager(this) 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 a75e7ae07..ccc939105 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 @@ -42,4 +42,10 @@ class RssArticlesViewModel(application: Application) : BaseViewModel(application } } + fun clear(url: String, onFinally: () -> Unit) { + execute { + App.db.rssArtivleDao().delete(url) + loadContent(url, onFinally) + } + } } \ No newline at end of file