From 8892da54689ed5ed75c9b5e4ed52e6c58911b286 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 4 Feb 2020 21:57:05 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../io/legado/app/ui/rss/read/ReadRssActivity.kt | 12 ++++++++---- .../io/legado/app/ui/rss/read/ReadRssViewModel.kt | 3 ++- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt index ffb5c4994..af113b5c0 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssActivity.kt @@ -40,15 +40,19 @@ class ReadRssActivity : VMBaseActivity(R.layout.activity_rss_r override fun onCompatCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.rss_read, menu) - starMenuItem = menu.findItem(R.id.menu_rss_star) - ttsMenuItem = menu.findItem(R.id.menu_aloud) - upStarMenu() return super.onCompatCreateOptionsMenu(menu) } + override fun onPrepareOptionsMenu(menu: Menu?): Boolean { + starMenuItem = menu?.findItem(R.id.menu_rss_star) + ttsMenuItem = menu?.findItem(R.id.menu_aloud) + upStarMenu() + return super.onPrepareOptionsMenu(menu) + } + override fun onCompatOptionsItemSelected(item: MenuItem): Boolean { when (item.itemId) { - R.id.menu_rss_star -> viewModel.star() + R.id.menu_rss_star -> viewModel.favorite() R.id.menu_share_it -> viewModel.rssArticle?.let { shareText("链接分享", it.link) } diff --git a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt index a81655c27..0ace44358 100644 --- a/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/rss/read/ReadRssViewModel.kt @@ -70,7 +70,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } } - fun star() { + fun favorite() { execute { rssArticle?.let { if (star) { @@ -78,6 +78,7 @@ class ReadRssViewModel(application: Application) : BaseViewModel(application), } else { App.db.rssStarDao().insert(it.toStar()) } + star = !star } }.onSuccess { callBack?.upStarMenu()