From a3ac41f5ff71f6faabd90f1c51a7c132e1e45083 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 Jun 2019 20:30:06 +0800 Subject: [PATCH] up --- ...centReadAdapter.kt => BookshelfAdapter.kt} | 8 ++++--- .../ui/main/bookshelf/BookshelfFragment.kt | 24 +++++++++---------- .../main/res/layout/fragment_bookshelf.xml | 4 ++-- 3 files changed, 19 insertions(+), 17 deletions(-) rename app/src/main/java/io/legado/app/ui/main/bookshelf/{RecentReadAdapter.kt => BookshelfAdapter.kt} (77%) diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/RecentReadAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt similarity index 77% rename from app/src/main/java/io/legado/app/ui/main/bookshelf/RecentReadAdapter.kt rename to app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt index f8380e216..6c0252bee 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/RecentReadAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfAdapter.kt @@ -1,13 +1,15 @@ package io.legado.app.ui.main.bookshelf +import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.paging.PagedListAdapter import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.RecyclerView +import io.legado.app.R import io.legado.app.data.entities.Book -class RecentReadAdapter : PagedListAdapter(DIFF_CALLBACK) { +class BookshelfAdapter : PagedListAdapter(DIFF_CALLBACK) { companion object { @JvmField @@ -23,11 +25,11 @@ class RecentReadAdapter : PagedListAdapter } override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_bookshelf_list, parent, false)) } override fun onBindViewHolder(holder: MyViewHolder, position: Int) { - TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { 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 48160f347..b3aa3f2be 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 @@ -18,16 +18,16 @@ import kotlinx.android.synthetic.main.view_title_bar.* class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { - private lateinit var recentReadAdapter: RecentReadAdapter + private lateinit var bookshelfAdapter: BookshelfAdapter private lateinit var bookGroupAdapter: BookGroupAdapter private var bookGroupLiveData: LiveData>? = null - private var recentReadLiveData: LiveData>? = null + private var bookshelfLiveData: LiveData>? = null override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) initRecyclerView() initBookGroupData() - initRecentReadData() + initBookshelfData() } override fun onCompatCreateOptionsMenu(menu: Menu) { @@ -35,12 +35,12 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { } private fun initRecyclerView() { - rv_bookshelf.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + rv_book_group.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) bookGroupAdapter = BookGroupAdapter() - rv_bookshelf.adapter = bookGroupAdapter - rv_read_books.layoutManager = LinearLayoutManager(context) - recentReadAdapter = RecentReadAdapter() - rv_read_books.adapter = recentReadAdapter + rv_book_group.adapter = bookGroupAdapter + rv_bookshelf.layoutManager = LinearLayoutManager(context) + bookshelfAdapter = BookshelfAdapter() + rv_bookshelf.adapter = bookshelfAdapter } private fun initBookGroupData() { @@ -49,10 +49,10 @@ class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { bookGroupLiveData?.observe(viewLifecycleOwner, Observer { bookGroupAdapter.submitList(it) }) } - private fun initRecentReadData() { - recentReadLiveData?.removeObservers(viewLifecycleOwner) - recentReadLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build() - recentReadLiveData?.observe(viewLifecycleOwner, Observer { recentReadAdapter.submitList(it) }) + private fun initBookshelfData() { + bookshelfLiveData?.removeObservers(viewLifecycleOwner) + bookshelfLiveData = LivePagedListBuilder(App.db.bookDao().recentRead(), 20).build() + bookshelfLiveData?.observe(viewLifecycleOwner, Observer { bookshelfAdapter.submitList(it) }) } } \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_bookshelf.xml b/app/src/main/res/layout/fragment_bookshelf.xml index 2590cf458..b7be3a24d 100644 --- a/app/src/main/res/layout/fragment_bookshelf.xml +++ b/app/src/main/res/layout/fragment_bookshelf.xml @@ -13,12 +13,12 @@ app:title="@string/bookshelf" /> \ No newline at end of file