|
|
|
@ -2,25 +2,30 @@ package io.legado.app.ui.chapterlist |
|
|
|
|
|
|
|
|
|
import android.os.Bundle |
|
|
|
|
import android.view.View |
|
|
|
|
import android.widget.LinearLayout |
|
|
|
|
import androidx.lifecycle.LiveData |
|
|
|
|
import androidx.lifecycle.Observer |
|
|
|
|
import androidx.paging.LivePagedListBuilder |
|
|
|
|
import androidx.paging.PagedList |
|
|
|
|
import androidx.recyclerview.widget.DividerItemDecoration |
|
|
|
|
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.data.entities.Book |
|
|
|
|
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) { |
|
|
|
|
class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_chapter_list), |
|
|
|
|
ChapterListAdapter.Callback { |
|
|
|
|
override val viewModel: ChapterListViewModel |
|
|
|
|
get() = getViewModelOfActivity(ChapterListViewModel::class.java) |
|
|
|
|
|
|
|
|
|
lateinit var adapter: ChapterListAdapter |
|
|
|
|
private var liveData: LiveData<PagedList<BookChapter>>? = null |
|
|
|
|
private var durChapterIndex = 0 |
|
|
|
|
|
|
|
|
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { |
|
|
|
|
super.onViewCreated(view, savedInstanceState) |
|
|
|
@ -30,8 +35,14 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun initRecyclerView() { |
|
|
|
|
adapter = ChapterListAdapter() |
|
|
|
|
adapter = ChapterListAdapter(this) |
|
|
|
|
recycler_view.layoutManager = LinearLayoutManager(requireContext()) |
|
|
|
|
recycler_view.addItemDecoration( |
|
|
|
|
DividerItemDecoration( |
|
|
|
|
requireContext(), |
|
|
|
|
LinearLayout.VERTICAL |
|
|
|
|
) |
|
|
|
|
) |
|
|
|
|
recycler_view.adapter = adapter |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -43,9 +54,9 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme |
|
|
|
|
|
|
|
|
|
private fun initView() { |
|
|
|
|
viewModel.bookDate.value?.let { |
|
|
|
|
tv_current_chapter_info.text = it.durChapterTitle |
|
|
|
|
loadBookFinish(it) |
|
|
|
|
} ?: viewModel.bookDate.observe(viewLifecycleOwner, Observer { |
|
|
|
|
tv_current_chapter_info.text = it.durChapterTitle |
|
|
|
|
loadBookFinish(it) |
|
|
|
|
}) |
|
|
|
|
iv_chapter_top.onClick { recycler_view.scrollToPosition(0) } |
|
|
|
|
iv_chapter_bottom.onClick { |
|
|
|
@ -59,4 +70,18 @@ class ChapterListFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragme |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private fun loadBookFinish(book: Book) { |
|
|
|
|
durChapterIndex = book.durChapterIndex |
|
|
|
|
tv_current_chapter_info.text = book.durChapterTitle |
|
|
|
|
recycler_view.scrollToPosition(durChapterIndex) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun durChapterIndex(): Int { |
|
|
|
|
return durChapterIndex |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
override fun openChapter() { |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
} |