From d4fca01df102d6c52b03d616415c812f58ab2fd9 Mon Sep 17 00:00:00 2001 From: kunfei Date: Thu, 22 Aug 2019 12:33:24 +0800 Subject: [PATCH] up --- .../io/legado/app/ui/bookinfo/BookInfoActivity.kt | 9 ++++++++- .../io/legado/app/ui/bookinfo/BookInfoViewModel.kt | 3 +++ .../io/legado/app/ui/bookinfo/ChapterListAdapter.kt | 12 ++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt index a6ff40a57..94863261a 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoActivity.kt @@ -9,6 +9,7 @@ import androidx.recyclerview.widget.DividerItemDecoration import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.VMBaseActivity +import io.legado.app.constant.Bus import io.legado.app.data.entities.Book import io.legado.app.data.entities.BookChapter import io.legado.app.help.ImageLoader @@ -19,6 +20,7 @@ import io.legado.app.ui.readbook.ReadBookActivity import io.legado.app.ui.sourceedit.SourceEditActivity import io.legado.app.utils.getViewModel import io.legado.app.utils.gone +import io.legado.app.utils.postEvent import io.legado.app.utils.visible import kotlinx.android.synthetic.main.activity_book_info.* import kotlinx.android.synthetic.main.view_title_bar.* @@ -127,6 +129,7 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo } adapter.clearItems() adapter.addItems(chapterList) + rv_chapter_list.scrollToPosition(viewModel.durChapterIndex) } private fun upLoading(isLoading: Boolean) { @@ -206,7 +209,11 @@ class BookInfoActivity : VMBaseActivity(R.layout.activity_boo viewModel.changeTo(book) } - override fun skipToChapter(index: Int) { + override fun openChapter(chapter: BookChapter) { + postEvent(Bus.OPEN_CHAPTER, chapter) + } + override fun durChapterIndex(): Int { + return viewModel.durChapterIndex } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt index fdc13bb8c..8bdbf18a4 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/BookInfoViewModel.kt @@ -16,6 +16,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { val bookData = MutableLiveData() val chapterListData = MutableLiveData>() val isLoadingData = MutableLiveData() + var durChapterIndex = 0 var inBookshelf = false fun loadBook(intent: Intent) { @@ -23,6 +24,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { 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()) { @@ -34,6 +36,7 @@ class BookInfoViewModel(application: Application) : BaseViewModel(application) { } } ?: intent.getStringExtra("searchBookUrl")?.let { App.db.searchBookDao().getSearchBook(it)?.toBook()?.let { book -> + durChapterIndex = book.durChapterIndex bookData.postValue(book) if (book.tocUrl.isEmpty()) { loadBookInfo(book) diff --git a/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt b/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt index cd5a759db..31468c980 100644 --- a/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/bookinfo/ChapterListAdapter.kt @@ -5,8 +5,10 @@ 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.BookChapter +import io.legado.app.lib.theme.accentColor import kotlinx.android.synthetic.main.item_chapter_list.view.* import org.jetbrains.anko.sdk27.listeners.onClick +import org.jetbrains.anko.textColorResource class ChapterListAdapter(context: Context, var callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_chapter_list) { @@ -14,13 +16,19 @@ class ChapterListAdapter(context: Context, var callBack: CallBack) : override fun convert(holder: ItemViewHolder, item: BookChapter, payloads: MutableList) { holder.itemView.apply { tv_chapter_name.text = item.title + if (item.index == callBack.durChapterIndex()) { + tv_chapter_name.setTextColor(context.accentColor) + } else { + tv_chapter_name.textColorResource = R.color.tv_text_default + } this.onClick { - callBack.skipToChapter(item.index) + callBack.openChapter(item) } } } interface CallBack { - fun skipToChapter(index: Int) + fun openChapter(chapter: BookChapter) + fun durChapterIndex(): Int } } \ No newline at end of file