pull/32/head
kunfei 5 years ago
parent a7cc477e69
commit de103d2f5d
  1. 7
      app/src/main/java/io/legado/app/lib/theme/MaterialValueHelper.kt
  2. 8
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt
  3. 16
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListAdapter.kt
  4. 33
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListFragment.kt

@ -123,6 +123,13 @@ val Fragment.primaryDisabledTextColor: Int
val Fragment.secondaryDisabledTextColor: Int val Fragment.secondaryDisabledTextColor: Int
get() = getSecondaryDisabledTextColor(isDarkTheme) get() = getSecondaryDisabledTextColor(isDarkTheme)
val Context.buttonDisabledColor: Int
get() = if (isDarkTheme) {
ContextCompat.getColor(this, R.color.ate_button_disabled_dark)
} else {
ContextCompat.getColor(this, R.color.ate_button_disabled_light)
}
val Context.isDarkTheme: Boolean val Context.isDarkTheme: Boolean
get() = ColorUtils.isColorLight(ThemeStore.primaryColor(this)) get() = ColorUtils.isColorLight(ThemeStore.primaryColor(this))

@ -2,10 +2,12 @@ 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
@ -32,6 +34,12 @@ class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_
ATH.applyEdgeEffectColor(recycler_view) ATH.applyEdgeEffectColor(recycler_view)
adapter = BookmarkAdapter() adapter = BookmarkAdapter()
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
} }

@ -8,10 +8,13 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R import io.legado.app.R
import io.legado.app.data.entities.BookChapter import io.legado.app.data.entities.BookChapter
import io.legado.app.lib.theme.accentColor
import io.legado.app.utils.getCompatColor
import kotlinx.android.synthetic.main.item_bookmark.view.* import kotlinx.android.synthetic.main.item_bookmark.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class ChapterListAdapter : PagedListAdapter<BookChapter, ChapterListAdapter.MyViewHolder>(DIFF_CALLBACK) { class ChapterListAdapter(val callback: Callback) :
PagedListAdapter<BookChapter, ChapterListAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object { companion object {
@ -26,8 +29,6 @@ class ChapterListAdapter : PagedListAdapter<BookChapter, ChapterListAdapter.MyVi
} }
} }
var callback: Callback? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_chapter_list, parent, false)) return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_chapter_list, parent, false))
} }
@ -42,7 +43,13 @@ class ChapterListAdapter : PagedListAdapter<BookChapter, ChapterListAdapter.MyVi
fun bind(bookChapter: BookChapter, callback: Callback?) = with(itemView) { fun bind(bookChapter: BookChapter, callback: Callback?) = with(itemView) {
tv_chapter_name.text = bookChapter.title tv_chapter_name.text = bookChapter.title
callback?.let {
if (it.durChapterIndex() == bookChapter.index) {
tv_chapter_name.setTextColor(context.accentColor)
} else {
tv_chapter_name.setTextColor(context.getCompatColor(R.color.tv_text_default))
}
}
itemView.onClick { itemView.onClick {
callback?.openChapter() callback?.openChapter()
} }
@ -51,5 +58,6 @@ class ChapterListAdapter : PagedListAdapter<BookChapter, ChapterListAdapter.MyVi
interface Callback { interface Callback {
fun openChapter() fun openChapter()
fun durChapterIndex(): Int
} }
} }

@ -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() {
}
} }
Loading…
Cancel
Save