换源界面删除后更新当前源标签

pull/1212/head
gedoor 3 years ago
parent 9b100ba6a4
commit 29475f2cee
  1. 1
      app/src/main/java/io/legado/app/constant/EventBus.kt
  2. 3
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayViewModel.kt
  3. 5
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceAdapter.kt
  4. 12
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeSourceDialog.kt
  5. 3
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  6. 3
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.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"
}

@ -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)
}
}

@ -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()
}
}
}
}

@ -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<String>(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)

@ -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)
}
}

@ -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)
}
}

Loading…
Cancel
Save