From bae96277ff861eaf058e10791b31d5d112ba84d3 Mon Sep 17 00:00:00 2001 From: kunfei Date: Wed, 14 Aug 2019 14:43:55 +0800 Subject: [PATCH] up --- .../app/ui/chapterlist/ChapterListActivity.kt | 1 + .../app/ui/chapterlist/ChapterListFragment.kt | 21 +++++++++++++++++++ .../ui/chapterlist/ChapterListViewModel.kt | 13 ++++++++++++ .../main/res/layout/fragment_chapter_list.xml | 10 +++++++-- 4 files changed, 43 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt index 24576fe41..70367f9f8 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt @@ -27,6 +27,7 @@ class ChapterListActivity : VMBaseActivity(R.layout.activi override fun onActivityCreated(savedInstanceState: Bundle?) { setSupportActionBar(toolbar) viewModel.bookUrl = intent.getStringExtra("bookUrl") + viewModel.loadBook() view_pager.adapter = TabFragmentPageAdapter(supportFragmentManager) tab_layout.setupWithViewPager(view_pager) } 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 2435bb07a..b77da5dc9 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 @@ -13,6 +13,7 @@ import io.legado.app.base.VMBaseFragment import io.legado.app.data.entities.BookChapter import io.legado.app.utils.getViewModelOfActivity import kotlinx.android.synthetic.main.fragment_chapter_list.* +import org.jetbrains.anko.sdk27.listeners.onClick class ChapterListFragment : VMBaseFragment(R.layout.fragment_chapter_list) { override val viewModel: ChapterListViewModel @@ -24,6 +25,7 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) initRecyclerView() + initView() initData() } @@ -38,4 +40,23 @@ class ChapterListFragment : VMBaseFragment(R.layout.fragme liveData = LivePagedListBuilder(App.db.bookChapterDao().observeByBook(viewModel.bookUrl ?: ""), 30).build() liveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) }) } + + private fun initView() { + viewModel.bookDate.value?.let { + tv_current_chapter_info.text = it.durChapterTitle + } ?: viewModel.bookDate.observe(viewLifecycleOwner, Observer { + tv_current_chapter_info.text = it.durChapterTitle + }) + iv_chapter_top.onClick { recycler_view.scrollToPosition(0) } + iv_chapter_bottom.onClick { + if (adapter.itemCount > 0) { + recycler_view.scrollToPosition(adapter.itemCount - 1) + } + } + tv_current_chapter_info.onClick { + viewModel.bookDate.value?.let { + recycler_view.scrollToPosition(it.durChapterIndex) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt index c17237185..11d1b38e9 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt @@ -2,10 +2,23 @@ package io.legado.app.ui.chapterlist import android.app.Application +import androidx.lifecycle.MutableLiveData +import io.legado.app.App import io.legado.app.base.BaseViewModel +import io.legado.app.data.entities.Book class ChapterListViewModel(application: Application) : BaseViewModel(application) { + var bookDate = MutableLiveData() var bookUrl: String? = null + fun loadBook() { + execute { + bookUrl?.let { + App.db.bookDao().getBook(it)?.let { book -> + bookDate.postValue(book) + } + } + } + } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_chapter_list.xml b/app/src/main/res/layout/fragment_chapter_list.xml index 28622e165..8964c91c6 100644 --- a/app/src/main/res/layout/fragment_chapter_list.xml +++ b/app/src/main/res/layout/fragment_chapter_list.xml @@ -1,6 +1,7 @@ @@ -30,6 +31,7 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" + android:background="?android:attr/selectableItemBackgroundBorderless" android:ellipsize="middle" android:paddingLeft="10dp" android:paddingRight="10dp" @@ -45,7 +47,9 @@ android:background="?android:attr/selectableItemBackgroundBorderless" android:contentDescription="@string/go_to_top" android:src="@drawable/ic_arrow_drop_up" - app:tint="@color/tv_text_default" /> + android:tooltipText="@string/go_to_top" + app:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> + android:tooltipText="@string/go_to_bottom" + app:tint="@color/tv_text_default" + tools:ignore="UnusedAttribute" /> \ No newline at end of file