pull/1753/head^2
kunfei 3 years ago
parent 3d1dd8a27e
commit 8fffc25a44
  1. 20
      app/src/main/java/io/legado/app/ui/book/audio/AudioPlayActivity.kt
  2. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceDialog.kt
  3. 11
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeBookSourceViewModel.kt
  4. 2
      app/src/main/java/io/legado/app/ui/book/changesource/ChangeChapterSourceDialog.kt

@ -12,6 +12,7 @@ import androidx.activity.viewModels
import androidx.compose.runtime.mutableStateOf
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus
import io.legado.app.constant.Status
import io.legado.app.constant.Theme
@ -25,6 +26,7 @@ import io.legado.app.model.BookCover
import io.legado.app.service.AudioPlayService
import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.book.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.login.SourceLoginActivity
@ -32,6 +34,9 @@ import io.legado.app.ui.theme.AppTheme
import io.legado.app.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import splitties.views.onLongClick
import java.util.*
@ -200,7 +205,20 @@ class AudioPlayActivity :
get() = AudioPlay.book
override fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) {
viewModel.changeTo(source, book, toc)
if (book.type == BookType.audio) {
viewModel.changeTo(source, book, toc)
} else {
AudioPlay.stop(this)
launch {
withContext(IO) {
AudioPlay.book?.changeTo(book, toc)
}
startActivity<ReadBookActivity> {
putExtra("bookUrl", book.bookUrl)
}
finish()
}
}
}
override fun finish() {

@ -287,7 +287,7 @@ class ChangeBookSourceDialog() : BaseDialogFragment(R.layout.dialog_book_change_
override fun deleteSource(searchBook: SearchBook) {
viewModel.del(searchBook)
if (bookUrl == searchBook.bookUrl) {
viewModel.autoChangeSource { book, toc, source ->
viewModel.autoChangeSource(callBack?.oldBook?.type) { book, toc, source ->
callBack?.changeTo(source, book, toc)
}
}

@ -360,14 +360,17 @@ open class ChangeBookSourceViewModel(application: Application) : BaseViewModel(a
}
fun autoChangeSource(
bookType: Int?,
onSuccess: (book: Book, toc: List<BookChapter>, source: BookSource) -> Unit
) {
execute {
searchBooks.forEach {
val book = it.toBook()
val result = getToc(book).getOrNull()
if (result != null) {
return@execute Triple(book, result.first, result.second)
if (it.type == bookType) {
val book = it.toBook()
val result = getToc(book).getOrNull()
if (result != null) {
return@execute Triple(book, result.first, result.second)
}
}
}
throw NoStackTraceException("没有有效源")

@ -309,7 +309,7 @@ class ChangeChapterSourceDialog() : BaseDialogFragment(R.layout.dialog_chapter_c
override fun deleteSource(searchBook: SearchBook) {
viewModel.del(searchBook)
if (bookUrl == searchBook.bookUrl) {
viewModel.autoChangeSource { book, toc, source ->
viewModel.autoChangeSource(callBack?.oldBook?.type) { book, toc, source ->
callBack?.changeTo(source, book, toc)
}
}

Loading…
Cancel
Save