pull/47/head
kunfei 5 years ago
parent f6f472ed48
commit c3628cf44c
  1. 12
      app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt
  2. 6
      app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt
  3. 6
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt

@ -64,6 +64,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override val viewModel: ReadBookViewModel override val viewModel: ReadBookViewModel
get() = getViewModel(ReadBookViewModel::class.java) get() = getViewModel(ReadBookViewModel::class.java)
private val requestCodeChapterList = 568
private val requestCodeEditSource = 111 private val requestCodeEditSource = 111
private var timeElectricityReceiver: TimeElectricityReceiver? = null private var timeElectricityReceiver: TimeElectricityReceiver? = null
override var readAloudStatus = Status.STOP override var readAloudStatus = Status.STOP
@ -436,7 +437,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
override fun openChapterList() { override fun openChapterList() {
viewModel.bookData.value?.let { viewModel.bookData.value?.let {
startActivity<ChapterListActivity>(Pair("bookUrl", it.bookUrl)) startActivityForResult<ChapterListActivity>(
requestCodeChapterList,
Pair("bookUrl", it.bookUrl)
)
} }
} }
@ -510,6 +514,10 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
if (resultCode == Activity.RESULT_OK) { if (resultCode == Activity.RESULT_OK) {
when (requestCode) { when (requestCode) {
requestCodeEditSource -> viewModel.upBookSource() requestCodeEditSource -> viewModel.upBookSource()
requestCodeChapterList ->
data?.getIntExtra("index", viewModel.durChapterIndex)?.let {
viewModel.openChapter(it)
}
} }
} }
} }
@ -552,7 +560,7 @@ class ReadBookActivity : VMBaseActivity<ReadBookViewModel>(R.layout.activity_boo
observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent<String>(Bus.TIME_CHANGED) { page_view.upTime() }
observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent<Int>(Bus.BATTERY_CHANGED) { page_view.upBattery(it) }
observeEvent<BookChapter>(Bus.OPEN_CHAPTER) { observeEvent<BookChapter>(Bus.OPEN_CHAPTER) {
viewModel.openChapter(it) viewModel.openChapter(it.index)
page_view.upContent() page_view.upContent()
} }
observeEvent<Boolean>(Bus.READ_ALOUD_BUTTON) { observeEvent<Boolean>(Bus.READ_ALOUD_BUTTON) {

@ -279,12 +279,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) {
} }
} }
fun openChapter(chapter: BookChapter) { fun openChapter(index: Int) {
prevTextChapter = null prevTextChapter = null
curTextChapter = null curTextChapter = null
nextTextChapter = null nextTextChapter = null
if (chapter.index != durChapterIndex) { if (index != durChapterIndex) {
durChapterIndex = chapter.index durChapterIndex = index
durPageIndex = 0 durPageIndex = 0
} }
saveRead() saveRead()

@ -1,5 +1,7 @@
package io.legado.app.ui.chapterlist package io.legado.app.ui.chapterlist
import android.app.Activity.RESULT_OK
import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.view.View import android.view.View
import android.widget.LinearLayout import android.widget.LinearLayout
@ -9,11 +11,9 @@ import androidx.recyclerview.widget.LinearLayoutManager
import io.legado.app.App import io.legado.app.App
import io.legado.app.R import io.legado.app.R
import io.legado.app.base.VMBaseFragment import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.Bus
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.utils.getViewModelOfActivity import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.postEvent
import kotlinx.android.synthetic.main.fragment_chapter_list.* import kotlinx.android.synthetic.main.fragment_chapter_list.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
@ -83,7 +83,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
} }
override fun openChapter(bookChapter: BookChapter) { override fun openChapter(bookChapter: BookChapter) {
postEvent(Bus.OPEN_CHAPTER, bookChapter) activity?.setResult(RESULT_OK, Intent().putExtra("index", bookChapter.index))
activity?.finish() activity?.finish()
} }

Loading…
Cancel
Save