pull/32/head
kunfei 5 years ago
parent cebd9c0d9a
commit bae96277ff
  1. 1
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListActivity.kt
  2. 21
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt
  3. 13
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt
  4. 10
      app/src/main/res/layout/fragment_chapter_list.xml

@ -27,6 +27,7 @@ class ChapterListActivity : VMBaseActivity<ChapterListViewModel>(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)
}

@ -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<ChapterListViewModel>(R.layout.fragment_chapter_list) {
override val viewModel: ChapterListViewModel
@ -24,6 +25,7 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRecyclerView()
initView()
initData()
}
@ -38,4 +40,23 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(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)
}
}
}
}

@ -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<Book>()
var bookUrl: String? = null
fun loadBook() {
execute {
bookUrl?.let {
App.db.bookDao().getBook(it)?.let { book ->
bookDate.postValue(book)
}
}
}
}
}

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants">
@ -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" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_chapter_bottom"
@ -54,7 +58,9 @@
android:background="?android:attr/selectableItemBackgroundBorderless"
android:contentDescription="@string/go_to_bottom"
android:src="@drawable/ic_arrow_drop_down"
app:tint="@color/tv_text_default" />
android:tooltipText="@string/go_to_bottom"
app:tint="@color/tv_text_default"
tools:ignore="UnusedAttribute" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save