diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt index ef07eb323..6eff6e223 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkAdapter.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(DIFF_CALLBACK) { @@ -27,20 +29,30 @@ class BookmarkAdapter : PagedListAdapter } } + 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) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt index b62fa6f49..5133474bf 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/BookmarkFragment.kt @@ -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(R.layout.fragment_bookmark) { override val viewModel: ChapterListViewModel get() = getViewModelOfActivity(ChapterListViewModel::class.java) + private lateinit var adapter: BookmarkAdapter + private var bookmarkLiveData: LiveData>? = 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) }) + } } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt index 3b41d0a73..a76b6386d 100644 --- a/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt +++ b/app/src/main/java/io/legado/app/ui/chapterlist/ChapterListViewModel.kt @@ -5,4 +5,6 @@ import io.legado.app.base.BaseViewModel class ChapterListViewModel : BaseViewModel(App.INSTANCE) { + var bookUrl: String? = null + } \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt index 06ebcdc77..5efb1801a 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt @@ -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(R.layout.fragment_b override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) -// initSearchView() initRecyclerView() initBookGroupData() initBookshelfData() @@ -65,14 +67,6 @@ class BookshelfFragment : VMBaseFragment(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)