pull/32/head
gedoor 6 years ago
parent f616975be8
commit 8206131f1f
  1. 3
      app/src/main/java/io/legado/app/data/dao/BookDao.kt
  2. 13
      app/src/main/java/io/legado/app/data/dao/BookGroupDao.kt
  3. 12
      app/src/main/java/io/legado/app/data/entities/BookGroup.kt
  4. 11
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  5. 36
      app/src/main/java/io/legado/app/ui/main/bookshelf/RecentReadAdapter.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<Book>
@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insert(vararg books: Book)

@ -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<Int, BookGroup>
}

@ -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
)

@ -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
}
}

@ -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<Book, RecentReadAdapter.MyViewHolder>(DIFF_CALLBACK) {
companion object {
@JvmField
val DIFF_CALLBACK = object : DiffUtil.ItemCallback<Book>() {
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) {
}
}
Loading…
Cancel
Save