From c3628cf44c9291fa519da701de501781ee62fc50 Mon Sep 17 00:00:00 2001 From: kunfei Date: Tue, 5 Nov 2019 11:29:43 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/book/read/ReadBookActivity.kt | 12 ++++++++++-- .../io/legado/app/ui/book/read/ReadBookViewModel.kt | 6 +++--- .../legado/app/ui/chapterlist/ChapterListFragment.kt | 6 +++--- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt index b2dd3dae0..fdb8d1808 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookActivity.kt @@ -64,6 +64,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override val viewModel: ReadBookViewModel get() = getViewModel(ReadBookViewModel::class.java) + private val requestCodeChapterList = 568 private val requestCodeEditSource = 111 private var timeElectricityReceiver: TimeElectricityReceiver? = null override var readAloudStatus = Status.STOP @@ -436,7 +437,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo override fun openChapterList() { viewModel.bookData.value?.let { - startActivity(Pair("bookUrl", it.bookUrl)) + startActivityForResult( + requestCodeChapterList, + Pair("bookUrl", it.bookUrl) + ) } } @@ -510,6 +514,10 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo if (resultCode == Activity.RESULT_OK) { when (requestCode) { requestCodeEditSource -> viewModel.upBookSource() + requestCodeChapterList -> + data?.getIntExtra("index", viewModel.durChapterIndex)?.let { + viewModel.openChapter(it) + } } } } @@ -552,7 +560,7 @@ class ReadBookActivity : VMBaseActivity(R.layout.activity_boo observeEvent(Bus.TIME_CHANGED) { page_view.upTime() } observeEvent(Bus.BATTERY_CHANGED) { page_view.upBattery(it) } observeEvent(Bus.OPEN_CHAPTER) { - viewModel.openChapter(it) + viewModel.openChapter(it.index) page_view.upContent() } observeEvent(Bus.READ_ALOUD_BUTTON) { diff --git a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt index daf901f60..5880bec5c 100644 --- a/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/book/read/ReadBookViewModel.kt @@ -279,12 +279,12 @@ class ReadBookViewModel(application: Application) : BaseViewModel(application) { } } - fun openChapter(chapter: BookChapter) { + fun openChapter(index: Int) { prevTextChapter = null curTextChapter = null nextTextChapter = null - if (chapter.index != durChapterIndex) { - durChapterIndex = chapter.index + if (index != durChapterIndex) { + durChapterIndex = index durPageIndex = 0 } saveRead() diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt index 4d3e947b6..97092ab13 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt @@ -1,5 +1,7 @@ package io.legado.app.ui.chapterlist +import android.app.Activity.RESULT_OK +import android.content.Intent import android.os.Bundle import android.view.View import android.widget.LinearLayout @@ -9,11 +11,9 @@ import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.App import io.legado.app.R 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.BookChapter import io.legado.app.utils.getViewModelOfActivity -import io.legado.app.utils.postEvent import kotlinx.android.synthetic.main.fragment_chapter_list.* import org.jetbrains.anko.sdk27.listeners.onClick @@ -83,7 +83,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme } override fun openChapter(bookChapter: BookChapter) { - postEvent(Bus.OPEN_CHAPTER, bookChapter) + activity?.setResult(RESULT_OK, Intent().putExtra("index", bookChapter.index)) activity?.finish() }