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