pull/43/head
kunfei 5 years ago
parent 2bed9af097
commit ded1afe546
  1. 6
      app/src/main/java/io/legado/app/help/IntentDataHelp.kt
  2. 2
      app/src/main/java/io/legado/app/service/BaseReadAloudService.kt
  3. 37
      app/src/main/java/io/legado/app/ui/book/info/BookInfoViewModel.kt
  4. 9
      app/src/main/java/io/legado/app/ui/explore/ExploreShowActivity.kt
  5. 5
      app/src/main/java/io/legado/app/ui/explore/ExploreShowAdapter.kt

@ -10,9 +10,11 @@ object IntentDataHelp {
return key
}
fun getData(key: String): Any? {
@Suppress("UNCHECKED_CAST")
fun <T> getData(key: String?): T? {
if (key == null) return null
val data = bigData[key]
bigData.remove(key)
return data
return data as? T
}
}

@ -104,7 +104,7 @@ abstract class BaseReadAloudService : BaseService(),
@CallSuper
open fun newReadAloud(dataKey: String?, play: Boolean) {
dataKey?.let {
textChapter = IntentDataHelp.getData(dataKey) as? TextChapter
textChapter = IntentDataHelp.getData<TextChapter>(dataKey)
textChapter?.let { textChapter ->
nowSpeak = 0
readAloudNumber = textChapter.getReadLength(pageIndex)

@ -9,6 +9,7 @@ import io.legado.app.base.BaseViewModel
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.model.WebBook
import kotlinx.coroutines.Dispatchers.IO
@ -22,33 +23,35 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) {
fun loadBook(intent: Intent) {
execute {
intent.getStringExtra("bookUrl")?.let {
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
durChapterIndex = book.durChapterIndex
bookData.postValue(book)
val chapterList = App.db.bookChapterDao().getChapterList(it)
if (chapterList.isNotEmpty()) {
chapterListData.postValue(chapterList)
isLoadingData.postValue(false)
} else {
loadChapter(book)
}
setBook(book)
}
} ?: intent.getStringExtra("searchBookUrl")?.let {
App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book ->
durChapterIndex = book.durChapterIndex
bookData.postValue(book)
if (book.tocUrl.isEmpty()) {
loadBookInfo(book)
} else {
loadChapter(book)
}
inBookshelf = App.db.bookDao().getBook(book.bookUrl) != null
setBook(book)
}
}
}
}
private fun setBook(book: Book) {
durChapterIndex = book.durChapterIndex
bookData.postValue(book)
val chapterList = App.db.bookChapterDao().getChapterList(book.bookUrl)
if (chapterList.isNotEmpty()) {
chapterListData.postValue(chapterList)
isLoadingData.postValue(false)
} else {
loadChapter(book)
}
}
fun loadBookInfo(
book: Book,
changeDruChapterIndex: ((chapters: List<BookChapter>) -> Unit)? = null

@ -9,7 +9,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.base.VMBaseActivity
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.IntentDataHelp
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.utils.getViewModel
import io.legado.app.utils.visible
@ -83,7 +85,10 @@ class ExploreShowActivity : VMBaseActivity<ExploreShowViewModel>(R.layout.activi
}
}
override fun showBookInfo(bookUrl: String) {
startActivity<BookInfoActivity>(Pair("searchBookUrl", bookUrl))
override fun showBookInfo(book: Book) {
startActivity<BookInfoActivity>(
Pair("searchBookUrl", book.bookUrl),
Pair("key", IntentDataHelp.putData(book, System.currentTimeMillis().toString()))
)
}
}

@ -4,6 +4,7 @@ import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.data.entities.Book
import io.legado.app.data.entities.SearchBook
import io.legado.app.help.ImageLoader
import io.legado.app.utils.gone
@ -65,11 +66,11 @@ class ExploreShowAdapter(context: Context, val callBack: CallBack) :
.setAsDrawable(iv_cover)
}
onClick {
callBack.showBookInfo(item.bookUrl)
callBack.showBookInfo(item.toBook())
}
}
interface CallBack {
fun showBookInfo(bookUrl: String)
fun showBookInfo(book: Book)
}
}
Loading…
Cancel
Save