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 androidx.compose.runtime.mutableStateOf
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseActivity import io.legado.app.base.VMBaseActivity
import io.legado.app.constant.BookType
import io.legado.app.constant.EventBus import io.legado.app.constant.EventBus
import io.legado.app.constant.Status import io.legado.app.constant.Status
import io.legado.app.constant.Theme 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.service.AudioPlayService
import io.legado.app.ui.about.AppLogDialog import io.legado.app.ui.about.AppLogDialog
import io.legado.app.ui.book.changesource.ChangeBookSourceDialog 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.source.edit.BookSourceEditActivity
import io.legado.app.ui.book.toc.TocActivityResult import io.legado.app.ui.book.toc.TocActivityResult
import io.legado.app.ui.login.SourceLoginActivity 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.ui.widget.seekbar.SeekBarChangeListener
import io.legado.app.utils.* import io.legado.app.utils.*
import io.legado.app.utils.viewbindingdelegate.viewBinding 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 splitties.views.onLongClick
import java.util.* import java.util.*
@ -200,7 +205,20 @@ class AudioPlayActivity :
get() = AudioPlay.book get() = AudioPlay.book
override fun changeTo(source: BookSource, book: Book, toc: List<BookChapter>) { 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() { override fun finish() {

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

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

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

Loading…
Cancel
Save