pull/43/head
kunfei 5 years ago
parent e2c2d9e408
commit 875e4b218b
  1. 18
      app/src/main/java/io/legado/app/ui/book/info/BookInfoActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  3. 21
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  4. 6
      app/src/main/java/io/legado/app/ui/main/bookshelf/BooksFragment.kt

@ -11,6 +11,7 @@ import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.ImageLoader
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.ui.book.info.edit.BookInfoEditActivity
import io.legado.app.ui.book.read.ReadBookActivity
@ -46,7 +47,7 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
viewModel.chapterListData.value?.let { chapters ->
showChapter(chapters)
}
} ?: viewModel.loadBook(intent)
} ?: viewModel.initData(intent)
initOnClick()
}
@ -210,17 +211,22 @@ class BookInfoActivity : VMBaseActivity<BookInfoViewModel>(R.layout.activity_boo
if (!viewModel.inBookshelf) {
viewModel.saveBook {
viewModel.saveChapterList {
startActivity<ReadBookActivity>(
Pair("bookUrl", book.bookUrl),
Pair("inBookshelf", false)
)
startReadActivity(book)
}
}
} else {
viewModel.saveBook {
startActivity<ReadBookActivity>(Pair("bookUrl", book.bookUrl))
startReadActivity(book)
}
}
}
private fun startReadActivity(book: Book) {
startActivity<ReadBookActivity>(
Pair("bookUrl", book.bookUrl),
Pair("inBookshelf", viewModel.inBookshelf),
Pair("key", IntentDataHelp.putData(book))
)
}
override val curOrigin: String?

@ -21,19 +21,16 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
var durChapterIndex = 0
var inBookshelf = false
fun loadBook(intent: Intent) {
fun initData(intent: Intent) {
execute {
IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let { book ->
inBookshelf = App.db.bookDao().getBook(book.bookUrl) != null
setBook(book)
} ?: intent.getStringExtra("bookUrl")?.let {
App.db.bookDao().getBook(it)?.let { book ->
inBookshelf = true
setBook(book)
}
} ?: intent.getStringExtra("searchBookUrl")?.let {
App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book ->
inBookshelf = App.db.bookDao().getBook(book.bookUrl) != null
setBook(book)
}
}
@ -41,6 +38,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
}
private fun setBook(book: Book) {
inBookshelf = App.db.bookDao().getBook(book.bookUrl) != null
durChapterIndex = book.durChapterIndex
bookData.postValue(book)
if (book.tocUrl.isEmpty()) {

@ -10,6 +10,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter
import io.legado.app.help.BookHelp
import io.legado.app.help.IntentDataHelp
import io.legado.app.help.ReadAloud
import io.legado.app.model.WebBook
import io.legado.app.ui.widget.page.TextChapter
@ -38,13 +39,19 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
fun initData(intent: Intent) {
execute {
inBookshelf = intent.getBooleanExtra("inBookshelf", true)
val bookUrl = intent.getStringExtra("bookUrl")
val book = if (!bookUrl.isNullOrEmpty()) {
App.db.bookDao().getBook(bookUrl)
} else {
App.db.bookDao().lastReadBook
IntentDataHelp.getData<Book>(intent.getStringExtra("key"))?.let {
setBook(it)
} ?: intent.getStringExtra("bookUrl")?.let {
App.db.bookDao().getBook(it)?.let { book ->
setBook(book)
}
} ?: App.db.bookDao().lastReadBook?.let {
setBook(it)
}
}
book?.let {
}
private fun setBook(book: Book) {
durChapterIndex = book.durChapterIndex
durPageIndex = book.durChapterPos
isLocalBook = book.origin == BookType.local
@ -66,7 +73,7 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
chapterSize = count
chapterListFinish.postValue(true)
}
}
if (inBookshelf) {
saveRead(book)
}
}

@ -14,6 +14,7 @@ import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.BookType
import io.legado.app.constant.Bus
import io.legado.app.data.entities.Book
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.audio.AudioPlayActivity
@ -98,7 +99,10 @@ class BooksFragment : VMBaseFragment<BooksViewModel>(R.layout.fragment_books),
when (book.type) {
BookType.audio ->
context?.startActivity<AudioPlayActivity>(Pair("bookUrl", book.bookUrl))
else -> context?.startActivity<ReadBookActivity>(Pair("bookUrl", book.bookUrl))
else -> context?.startActivity<ReadBookActivity>(
Pair("bookUrl", book.bookUrl),
Pair("key", IntentDataHelp.putData(book))
)
}
}

Loading…
Cancel
Save