From 8206131f1f1acec3e7de3bf3e519c0537d3b2519 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sun, 9 Jun 2019 19:41:24 +0800 Subject: [PATCH] up --- .../java/io/legado/app/data/dao/BookDao.kt | 3 ++ .../io/legado/app/data/dao/BookGroupDao.kt | 13 +++++++ .../io/legado/app/data/entities/BookGroup.kt | 12 +++++++ .../ui/main/bookshelf/BookshelfFragment.kt | 11 ++++++ .../ui/main/bookshelf/RecentReadAdapter.kt | 36 +++++++++++++++++++ 5 files changed, 75 insertions(+) create mode 100644 app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt create mode 100644 app/src/main/java/io/legado/app/data/entities/BookGroup.kt create mode 100644 app/src/main/java/io/legado/app/ui/main/bookshelf/RecentReadAdapter.kt diff --git a/app/src/main/java/io/legado/app/data/dao/BookDao.kt b/app/src/main/java/io/legado/app/data/dao/BookDao.kt index 10c65f279..2a1f741ad 100644 --- a/app/src/main/java/io/legado/app/data/dao/BookDao.kt +++ b/app/src/main/java/io/legado/app/data/dao/BookDao.kt @@ -26,6 +26,9 @@ interface BookDao { @get:Query("SELECT COUNT(*) FROM books") val allBookCount: Int + @Query("SELECT * FROM books ORDER BY durChapterTime DESC limit 0,10") + fun recentRead(): List + @Insert(onConflict = OnConflictStrategy.REPLACE) fun insert(vararg books: Book) diff --git a/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt new file mode 100644 index 000000000..4c4d4c727 --- /dev/null +++ b/app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt @@ -0,0 +1,13 @@ +package io.legado.app.data.dao + +import androidx.paging.DataSource +import androidx.room.Query +import io.legado.app.data.entities.BookGroup + +interface BookGroupDao { + + @Query("SELECT * FROM book_groups ORDER BY `order`") + fun observeAll(): DataSource.Factory + + +} \ No newline at end of file diff --git a/app/src/main/java/io/legado/app/data/entities/BookGroup.kt b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt new file mode 100644 index 000000000..dcd02a49f --- /dev/null +++ b/app/src/main/java/io/legado/app/data/entities/BookGroup.kt @@ -0,0 +1,12 @@ +package io.legado.app.data.entities + +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "book_groups") +data class BookGroup( + @PrimaryKey + var groupId: Int = 0, + var groupName: String, + var order: Int = 0 +) \ 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 610d99e43..b0705383e 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 @@ -3,19 +3,30 @@ package io.legado.app.ui.main.bookshelf import android.os.Bundle import android.view.Menu import android.view.View +import androidx.recyclerview.widget.LinearLayoutManager import io.legado.app.R import io.legado.app.base.BaseFragment +import kotlinx.android.synthetic.main.fragment_bookshelf.* import kotlinx.android.synthetic.main.view_title_bar.* class BookshelfFragment : BaseFragment(R.layout.fragment_bookshelf) { + private lateinit var recentReadAdapter: RecentReadAdapter + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { setSupportToolbar(toolbar) + initRecyclerView() } override fun onCompatCreateOptionsMenu(menu: Menu) { menuInflater.inflate(R.menu.bookshelf, menu) } + private fun initRecyclerView() { + rv_bookshelf.layoutManager = LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false) + rv_read_books.layoutManager = LinearLayoutManager(context) + recentReadAdapter = RecentReadAdapter() + rv_read_books.adapter = recentReadAdapter + } } \ No newline at end of file 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/RecentReadAdapter.kt new file mode 100644 index 000000000..f8380e216 --- /dev/null +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/RecentReadAdapter.kt @@ -0,0 +1,36 @@ +package io.legado.app.ui.main.bookshelf + +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.data.entities.Book + +class RecentReadAdapter : PagedListAdapter(DIFF_CALLBACK) { + + companion object { + @JvmField + val DIFF_CALLBACK = object : DiffUtil.ItemCallback() { + override fun areItemsTheSame(oldItem: Book, newItem: Book): Boolean = + oldItem.descUrl == newItem.descUrl + + override fun areContentsTheSame(oldItem: Book, newItem: Book): Boolean = + oldItem.descUrl == newItem.descUrl + && oldItem.durChapterTitle == newItem.durChapterTitle + && oldItem.latestChapterTitle == newItem.latestChapterTitle + } + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + 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) { + + } +} \ No newline at end of file