pull/51/head
kunfei 5 years ago
parent 8bd1cc0de2
commit 2553777886
  1. 1
      app/src/main/java/io/legado/app/constant/PreferKey.kt
  2. 3
      app/src/main/java/io/legado/app/ui/main/bookshelf/BookshelfFragment.kt
  3. 58
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapter.kt
  4. 61
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterGrid.kt
  5. 63
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksAdapterList.kt
  6. 29
      app/src/main/java/io/legado/app/ui/main/bookshelf/books/BooksFragment.kt

@ -9,4 +9,5 @@ object PreferKey {
const val prevKey = "prevKeyCode"
const val nextKey = "nextKeyCode"
const val showRss = "showRss"
const val bookshelfLayout = "bookshelfLayout"
}

@ -13,6 +13,7 @@ import io.legado.app.App
import io.legado.app.R
import io.legado.app.base.VMBaseFragment
import io.legado.app.constant.AppConst
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.BookGroup
import io.legado.app.lib.dialogs.selector
import io.legado.app.lib.theme.ATH
@ -129,7 +130,7 @@ class BookshelfFragment : VMBaseFragment<BookshelfViewModel>(R.layout.fragment_b
title = "选择书架布局",
items = resources.getStringArray(R.array.bookshelf_layout).toList()
) { _, index ->
putPrefInt("bookshelf", index)
putPrefInt(PreferKey.bookshelfLayout, index)
}
}
}

@ -1,65 +1,11 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.base.adapter.SimpleRecyclerAdapter
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapter(context: Context, private val callBack: CallBack) :
SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
with(holder.itemView) {
if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
tv_author.text = item.author
tv_read.text = item.durChapterTitle
tv_last.text = item.latestChapterTitle
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.into(iv_cover)
}
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)
true
}
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
}
}
}
}
}
abstract class BooksAdapter(context: Context, private val layoutId: Int) :
SimpleRecyclerAdapter<Book>(context, layoutId) {
fun notification(bookUrl: String) {
for (i in 0 until itemCount) {

@ -0,0 +1,61 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapterGrid(context: Context, private val callBack: CallBack) :
BooksAdapter(context, R.layout.item_bookshelf_grid) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
with(holder.itemView) {
if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
tv_author.text = item.author
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.into(iv_cover)
}
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)
true
}
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
}
}
}
}
}
}

@ -0,0 +1,63 @@
package io.legado.app.ui.main.bookshelf.books
import android.content.Context
import io.legado.app.R
import io.legado.app.base.adapter.ItemViewHolder
import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book
import io.legado.app.help.ImageLoader
import io.legado.app.lib.theme.ATH
import io.legado.app.utils.invisible
import kotlinx.android.synthetic.main.item_bookshelf_list.view.*
import org.jetbrains.anko.sdk27.listeners.onClick
import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapterList(context: Context, private val callBack: CallBack) :
BooksAdapter(context, R.layout.item_bookshelf_list) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) {
with(holder.itemView) {
if (payloads.isEmpty()) {
ATH.applyBackgroundTint(this)
tv_name.text = item.name
tv_author.text = item.author
tv_read.text = item.durChapterTitle
tv_last.text = item.latestChapterTitle
item.getDisplayCover()?.let {
ImageLoader.load(context, it)//Glide自动识别http://和file://
.placeholder(R.drawable.image_cover_default)
.error(R.drawable.image_cover_default)
.centerCrop()
.into(iv_cover)
}
onClick { callBack.open(item) }
onLongClick {
callBack.openBookInfo(item)
true
}
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
} else {
when (payloads[0]) {
5 -> {
if (item.origin != BookType.local && callBack.isUpdate(item.bookUrl)) {
bv_unread.invisible()
rl_loading.show()
} else {
rl_loading.hide()
bv_unread.setBadgeCount(item.getUnreadChapterNum())
bv_unread.setHighlight(item.lastCheckCount > 0)
}
}
}
}
}
}
}

@ -2,17 +2,17 @@ package io.legado.app.ui.main.bookshelf.books
import android.os.Bundle
import android.view.View
import androidx.core.content.ContextCompat
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.DividerItemDecoration
import androidx.recyclerview.widget.GridLayoutManager
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.constant.BookType
import io.legado.app.constant.Bus
import io.legado.app.constant.PreferKey
import io.legado.app.data.entities.Book
import io.legado.app.help.IntentDataHelp
import io.legado.app.lib.theme.ATH
@ -21,6 +21,7 @@ import io.legado.app.ui.audio.AudioPlayActivity
import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.read.ReadBookActivity
import io.legado.app.ui.main.MainViewModel
import io.legado.app.utils.getPrefInt
import io.legado.app.utils.getViewModel
import io.legado.app.utils.getViewModelOfActivity
import io.legado.app.utils.observeEvent
@ -68,17 +69,19 @@ class BooksFragment : VMBaseFragment<BooksViewModel>(R.layout.fragment_books),
refresh_layout.isRefreshing = false
activityViewModel.upChapterList()
}
rv_bookshelf.layoutManager = LinearLayoutManager(context)
rv_bookshelf.addItemDecoration(
DividerItemDecoration(requireContext(), DividerItemDecoration.VERTICAL).apply {
ContextCompat.getDrawable(requireContext(), R.drawable.ic_divider)?.let {
this.setDrawable(it)
}
})
booksAdapter = BooksAdapter(
requireContext(),
this
)
val bookshelfLayout = getPrefInt(PreferKey.bookshelfLayout)
rv_bookshelf.layoutManager =
if (bookshelfLayout == 0) {
LinearLayoutManager(context)
} else {
GridLayoutManager(requireContext(), bookshelfLayout)
}
booksAdapter =
if (bookshelfLayout == 0) {
BooksAdapterList(requireContext(), this)
} else {
BooksAdapterGrid(requireContext(), this)
}
rv_bookshelf.adapter = booksAdapter
}

Loading…
Cancel
Save