From 29475f2cee75adb0dd8c32d15afdcda1cbf81ede Mon Sep 17 00:00:00 2001 From: gedoor Date: Thu, 5 Aug 2021 15:55:30 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=A2=E6=BA=90=E7=95=8C=E9=9D=A2=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E5=90=8E=E6=9B=B4=E6=96=B0=E5=BD=93=E5=89=8D=E6=BA=90?= =?UTF-8?q?=E6=A0=87=E7=AD=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/java/io/legado/app/constant/EventBus.kt | 1 + .../legado/app/ui/book/audio/AudioPlayViewModel.kt | 3 +++ .../app/ui/book/changesource/ChangeSourceAdapter.kt | 5 +++++ .../app/ui/book/changesource/ChangeSourceDialog.kt | 12 +++++++++++- .../io/legado/app/ui/book/info/BookInfoViewModel.kt | 3 +++ .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 3 +++ 6 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/legado/app/constant/EventBus.kt b/app/src/main/java/io/legado/app/constant/EventBus.kt index 04f165a60..1cb16afd5 100644 --- a/app/src/main/java/io/legado/app/constant/EventBus.kt +++ b/app/src/main/java/io/legado/app/constant/EventBus.kt @@ -24,4 +24,5 @@ object EventBus { const val CHECK_SOURCE = "checkSource" const val CHECK_SOURCE_DONE = "checkSourceDone" const val TIP_COLOR = "tipColor" + const val SOURCE_CHANGED = "sourceChanged" } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt index 8770dd494..6877bd036 100644 --- a/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt @@ -4,12 +4,14 @@ import android.app.Application import android.content.Intent import io.legado.app.R import io.legado.app.base.BaseViewModel +import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.BookHelp import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.AudioPlay +import io.legado.app.utils.postEvent import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers @@ -98,6 +100,7 @@ class AudioPlayViewModel(application: Application) : BaseViewModel(application) } else { loadChapterList(book1) { upChangeDurChapterIndex(book1, oldTocSize, it) } } + postEvent(EventBus.SOURCE_CHANGED, book1.bookUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt index d34f7a441..35eea0a90 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt @@ -62,6 +62,11 @@ class ChangeSourceAdapter( when (it) { "name" -> tvOrigin.text = item.originName "latest" -> tvLast.text = item.getDisplayLastChapterTitle() + "upCurSource" -> if (callBack.bookUrl == item.bookUrl) { + ivChecked.visible() + } else { + ivChecked.invisible() + } } } } diff --git a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt index b5e3873b6..392349057 100644 --- a/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt +++ b/app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.RecyclerView import io.legado.app.R import io.legado.app.base.BaseDialogFragment import io.legado.app.constant.AppPattern +import io.legado.app.constant.EventBus import io.legado.app.constant.PreferKey import io.legado.app.data.appDb import io.legado.app.data.entities.Book @@ -218,12 +219,12 @@ class ChangeSourceDialog : BaseDialogFragment(), } override fun deleteSource(searchBook: SearchBook) { + viewModel.del(searchBook) if (bookUrl == searchBook.bookUrl) { viewModel.firstSourceOrNull(searchBook)?.let { changeSource(it) } } - viewModel.del(searchBook) } private fun changeSource(searchBook: SearchBook) { @@ -259,6 +260,15 @@ class ChangeSourceDialog : BaseDialogFragment(), } } + override fun observeLiveBus() { + observeEvent(EventBus.SOURCE_CHANGED) { + val payload = Bundle().apply { + putString("upCurSource", bookUrl) + } + adapter.notifyItemRangeChanged(0, adapter.itemCount, payload) + } + } + interface CallBack { val oldBook: Book? fun changeTo(book: Book) diff --git a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt index ddb0f9b0d..eef30dc4e 100644 --- a/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt @@ -5,6 +5,7 @@ import android.content.Intent import androidx.lifecycle.MutableLiveData import io.legado.app.R import io.legado.app.base.BaseViewModel +import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter @@ -13,6 +14,7 @@ import io.legado.app.help.BookHelp import io.legado.app.model.localBook.LocalBook import io.legado.app.model.webBook.WebBook import io.legado.app.service.help.ReadBook +import io.legado.app.utils.postEvent import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers.IO @@ -167,6 +169,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { upChangeDurChapterIndex(newBook, oldTocSize, it) } } + postEvent(EventBus.SOURCE_CHANGED, newBook.bookUrl) } } diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index 968ffbd80..ebaa2f4bf 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -5,6 +5,7 @@ import android.content.Intent import androidx.lifecycle.viewModelScope import io.legado.app.R import io.legado.app.base.BaseViewModel +import io.legado.app.constant.EventBus import io.legado.app.data.appDb import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter @@ -20,6 +21,7 @@ import io.legado.app.service.BaseReadAloudService import io.legado.app.service.help.ReadAloud import io.legado.app.service.help.ReadBook import io.legado.app.utils.msg +import io.legado.app.utils.postEvent import io.legado.app.utils.toastOnUi import kotlinx.coroutines.Dispatchers.IO import kotlinx.coroutines.Dispatchers.Main @@ -207,6 +209,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { upChangeDurChapterIndex(newBook, oldTocSize, it) } } + postEvent(EventBus.SOURCE_CHANGED, newBook.bookUrl) } }