pull/32/head
kunfei 5 years ago
parent c86a671447
commit 22be80f7f6
  1. 18
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt
  2. 30
      app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt
  3. 2
      app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt
  4. 14
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt

@ -8,6 +8,8 @@ import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
import io.legado.app.R
import io.legado.app.data.entities.Bookmark
import kotlinx.android.synthetic.main.item_bookmark.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
class BookmarkAdapter : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>(DIFF_CALLBACK) {
@ -27,20 +29,30 @@ class BookmarkAdapter : PagedListAdapter<Bookmark, BookmarkAdapter.MyViewHolder>
}
}
var callback: Callback? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookmark, parent, false))
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let {
holder.bind(it)
holder.bind(it, callback)
}
}
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) {
fun bind(bookmark: Bookmark) {
fun bind(bookmark: Bookmark, callback: Callback?) = with(itemView) {
tv_chapter_name.text = bookmark.chapterName
tv_content.text = bookmark.content
itemView.onClick {
callback?.open(bookmark)
}
}
}
interface Callback {
fun open(bookmark: Bookmark)
}
}

@ -1,12 +1,42 @@
package io.legado.app.ui.chapterlist
import android.os.Bundle
import android.view.View
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.paging.LivePagedListBuilder
import androidx.paging.PagedList
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.Bookmark
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.getViewModelOfActivity
import kotlinx.android.synthetic.main.fragment_bookmark.*
class BookmarkFragment : VMBaseFragment<ChapterListViewModel>(R.layout.fragment_bookmark) {
override val viewModel: ChapterListViewModel
get() = getViewModelOfActivity(ChapterListViewModel::class.java)
private lateinit var adapter: BookmarkAdapter
private var bookmarkLiveData: LiveData<PagedList<Bookmark>>? = null
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
initRecyclerView()
}
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(rv_list)
adapter = BookmarkAdapter()
rv_list.layoutManager = LinearLayoutManager(requireContext())
rv_list.adapter = adapter
}
private fun initData() {
bookmarkLiveData?.removeObservers(viewLifecycleOwner)
bookmarkLiveData = LivePagedListBuilder(App.db.bookmarkDao().observeByBook(""), 20).build()
bookmarkLiveData?.observe(viewLifecycleOwner, Observer { adapter.submitList(it) })
}
}

@ -5,4 +5,6 @@ import io.legado.app.base.BaseViewModel
class ChapterListViewModel : BaseViewModel(App.INSTANCE) {
var bookUrl: String? = null
}

@ -26,7 +26,10 @@ import io.legado.app.lib.theme.accentColor
import io.legado.app.ui.bookshelf.BookshelfActivity
import io.legado.app.ui.read.ReadActivity
import io.legado.app.ui.search.SearchActivity
import io.legado.app.utils.*
import io.legado.app.utils.applyTint
import io.legado.app.utils.getViewModel
import io.legado.app.utils.requestInputMethod
import io.legado.app.utils.startActivity
import kotlinx.android.synthetic.main.dialog_edittext.view.*
import kotlinx.android.synthetic.main.fragment_bookshelf.*
import kotlinx.android.synthetic.main.view_title_bar.*
@ -48,7 +51,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
setSupportToolbar(toolbar)
// initSearchView()
initRecyclerView()
initBookGroupData()
initBookshelfData()
@ -65,14 +67,6 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
}
}
private fun initSearchView() {
// search_view.onActionViewExpanded()
// search_view.isSubmitButtonEnabled = true
// search_view.queryHint = getString(R.string.search_book_key)
// search_view.clearFocus()
// search_view.setOnQueryTextListener(this)
}
private fun initRecyclerView() {
ATH.applyEdgeEffectColor(rv_bookshelf)
refresh_layout.setColorSchemeColors(accentColor)

Loading…
Cancel
Save