pull/1041/head
gedoor 4 years ago
parent 1ded30fe86
commit da3fb420f2
  1. 104
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterGrid.kt
  2. 137
      app/src/main/java/io/legado/app/ui/main/bookshelf/style2/BooksAdapterList.kt
  3. 90
      app/src/main/res/layout/item_bookshelf_grid_group.xml
  4. 170
      app/src/main/res/layout/item_bookshelf_list_group.xml

@ -9,12 +9,13 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.ItemBookshelfGridBinding import io.legado.app.databinding.ItemBookshelfGridBinding
import io.legado.app.databinding.ItemBookshelfGridGroupBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
import splitties.views.onLongClick import splitties.views.onLongClick
class BooksAdapterGrid(context: Context, callBack: CallBack) : class BooksAdapterGrid(context: Context, callBack: CallBack) :
BaseBooksAdapter<BooksAdapterGrid.ItemViewHolder>(context, callBack) { BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
override fun getItemCount(): Int { override fun getItemCount(): Int {
return callBack.getItemCount() return callBack.getItemCount()
@ -23,56 +24,82 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
override fun onCreateViewHolder( override fun onCreateViewHolder(
parent: ViewGroup, parent: ViewGroup,
viewType: Int viewType: Int
): ItemViewHolder { ): RecyclerView.ViewHolder {
return ItemViewHolder( return BookViewHolder(
ItemBookshelfGridBinding.inflate(LayoutInflater.from(context), parent, false) ItemBookshelfGridBinding.inflate(LayoutInflater.from(context), parent, false)
) )
} }
override fun onBindViewHolder( override fun onBindViewHolder(
holder: ItemViewHolder, holder: RecyclerView.ViewHolder,
position: Int, position: Int,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
holder.binding.run { val bundle = payloads.getOrNull(0) as? Bundle
val bundle = payloads.getOrNull(0) as? Bundle when {
if (bundle == null) { bundle == null -> super.onBindViewHolder(holder, position, payloads)
super.onBindViewHolder(holder, position, payloads) holder is BookViewHolder -> onBindBook(holder.binding, position, bundle)
} else { holder is GroupViewHolder -> onBindGroup(holder.binding, position, bundle)
when (val item = callBack.getItem(position)) { }
is Book -> { }
bundle.keySet().forEach {
when (it) { private fun onBindGroup(binding: ItemBookshelfGridGroupBinding, position: Int, bundle: Bundle) {
"name" -> tvName.text = item.name binding.run {
"cover" -> ivCover.load( val item = callBack.getItem(position)
item.getDisplayCover(), if (item is BookGroup) {
item.name, tvName.text = item.groupName
item.author }
) }
"refresh" -> upRefresh(this, item) }
}
} private fun onBindBook(binding: ItemBookshelfGridBinding, position: Int, bundle: Bundle) {
} binding.run {
is BookGroup -> { val item = callBack.getItem(position)
tvName.text = item.groupName if (item is Book) {
bundle.keySet().forEach {
when (it) {
"name" -> tvName.text = item.name
"cover" -> ivCover.load(
item.getDisplayCover(),
item.name,
item.author
)
"refresh" -> upRefresh(this, item)
} }
} }
}
}
}
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
when (holder) {
is BookViewHolder -> onBindBook(holder.binding, position)
is GroupViewHolder -> onBindGroup(holder.binding, position)
}
}
private fun onBindGroup(binding: ItemBookshelfGridGroupBinding, position: Int) {
binding.run {
val item = callBack.getItem(position)
if (item is BookGroup) {
tvName.text = item.groupName
}
root.setOnClickListener {
callBack.onItemClick(position)
}
root.onLongClick {
callBack.onItemLongClick(position)
} }
} }
} }
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { private fun onBindBook(binding: ItemBookshelfGridBinding, position: Int) {
holder.binding.run { binding.run {
when (val item = callBack.getItem(position)) { val item = callBack.getItem(position)
is Book -> { if (item is Book) {
tvName.text = item.name tvName.text = item.name
ivCover.load(item.getDisplayCover(), item.name, item.author) ivCover.load(item.getDisplayCover(), item.name, item.author)
upRefresh(this, item) upRefresh(this, item)
}
is BookGroup -> {
tvName.text = item.groupName
}
} }
root.setOnClickListener { root.setOnClickListener {
callBack.onItemClick(position) callBack.onItemClick(position)
@ -98,7 +125,10 @@ class BooksAdapterGrid(context: Context, callBack: CallBack) :
} }
} }
class ItemViewHolder(val binding: ItemBookshelfGridBinding) : class BookViewHolder(val binding: ItemBookshelfGridBinding) :
RecyclerView.ViewHolder(binding.root)
class GroupViewHolder(val binding: ItemBookshelfGridGroupBinding) :
RecyclerView.ViewHolder(binding.root) RecyclerView.ViewHolder(binding.root)
} }

@ -9,6 +9,7 @@ import io.legado.app.constant.BookType
import io.legado.app.data.entities.Book import io.legado.app.data.entities.Book
import io.legado.app.data.entities.BookGroup import io.legado.app.data.entities.BookGroup
import io.legado.app.databinding.ItemBookshelfListBinding import io.legado.app.databinding.ItemBookshelfListBinding
import io.legado.app.databinding.ItemBookshelfListGroupBinding
import io.legado.app.help.AppConfig import io.legado.app.help.AppConfig
import io.legado.app.utils.gone import io.legado.app.utils.gone
import io.legado.app.utils.invisible import io.legado.app.utils.invisible
@ -16,78 +17,105 @@ import io.legado.app.utils.visible
import splitties.views.onLongClick import splitties.views.onLongClick
class BooksAdapterList(context: Context, callBack: CallBack) : class BooksAdapterList(context: Context, callBack: CallBack) :
BaseBooksAdapter<BooksAdapterList.ItemViewHolder>(context, callBack) { BaseBooksAdapter<RecyclerView.ViewHolder>(context, callBack) {
override fun getItemCount(): Int { override fun getItemCount(): Int {
return callBack.getItemCount() return callBack.getItemCount()
} }
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
return ItemViewHolder( return BookViewHolder(
ItemBookshelfListBinding.inflate(LayoutInflater.from(context), parent, false) ItemBookshelfListBinding.inflate(LayoutInflater.from(context), parent, false)
) )
} }
override fun onBindViewHolder( override fun onBindViewHolder(
holder: ItemViewHolder, holder: RecyclerView.ViewHolder,
position: Int, position: Int,
payloads: MutableList<Any> payloads: MutableList<Any>
) { ) {
val bundle = payloads.getOrNull(0) as? Bundle val bundle = payloads.getOrNull(0) as? Bundle
if (bundle == null) { when {
super.onBindViewHolder(holder, position, payloads) bundle == null -> super.onBindViewHolder(holder, position, payloads)
} else { holder is BookViewHolder -> onBindBook(holder.binding, position, bundle)
holder.binding.run { holder is GroupViewHolder -> onBindGroup(holder.binding, position, bundle)
when (val item = callBack.getItem(position)) { }
is Book -> { }
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle private fun onBindGroup(binding: ItemBookshelfListGroupBinding, position: Int, bundle: Bundle) {
bundle.keySet().forEach { binding.run {
when (it) { val item = callBack.getItem(position)
"name" -> tvName.text = item.name if (item is BookGroup) {
"author" -> tvAuthor.text = item.author tvName.text = item.groupName
"cover" -> ivCover.load( }
item.getDisplayCover(), }
item.name, }
item.author
) private fun onBindBook(binding: ItemBookshelfListBinding, position: Int, bundle: Bundle) {
"refresh" -> upRefresh(this, item) binding.run {
} val item = callBack.getItem(position)
} if (item is Book) {
} tvRead.text = item.durChapterTitle
is BookGroup -> { tvLast.text = item.latestChapterTitle
tvName.text = item.groupName bundle.keySet().forEach {
when (it) {
"name" -> tvName.text = item.name
"author" -> tvAuthor.text = item.author
"cover" -> ivCover.load(
item.getDisplayCover(),
item.name,
item.author
)
"refresh" -> upRefresh(this, item)
} }
} }
} }
} }
} }
override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
holder.binding.run { when (holder) {
when (val item = callBack.getItem(position)) { is BookViewHolder -> onBindBook(holder.binding, position)
is Book -> { is GroupViewHolder -> onBindGroup(holder.binding, position)
tvName.text = item.name }
tvAuthor.text = item.author }
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle private fun onBindGroup(binding: ItemBookshelfListGroupBinding, position: Int) {
ivCover.load(item.getDisplayCover(), item.name, item.author) binding.run {
flHasNew.visible() val item = callBack.getItem(position)
ivAuthor.visible() if (item is BookGroup) {
ivLast.visible() tvName.text = item.groupName
ivRead.visible() flHasNew.gone()
upRefresh(this, item) ivAuthor.gone()
} ivLast.gone()
is BookGroup -> { ivRead.gone()
tvName.text = item.groupName tvAuthor.gone()
flHasNew.gone() tvLast.gone()
ivAuthor.gone() tvRead.gone()
ivLast.gone() }
ivRead.gone() root.setOnClickListener {
tvAuthor.gone() callBack.onItemClick(position)
tvLast.gone() }
tvRead.gone() root.onLongClick {
} callBack.onItemLongClick(position)
}
}
}
private fun onBindBook(binding: ItemBookshelfListBinding, position: Int) {
binding.run {
val item = callBack.getItem(position)
if (item is Book) {
tvName.text = item.name
tvAuthor.text = item.author
tvRead.text = item.durChapterTitle
tvLast.text = item.latestChapterTitle
ivCover.load(item.getDisplayCover(), item.name, item.author)
flHasNew.visible()
ivAuthor.visible()
ivLast.visible()
ivRead.visible()
upRefresh(this, item)
} }
root.setOnClickListener { root.setOnClickListener {
callBack.onItemClick(position) callBack.onItemClick(position)
@ -113,7 +141,10 @@ class BooksAdapterList(context: Context, callBack: CallBack) :
} }
} }
class ItemViewHolder(val binding: ItemBookshelfListBinding) : class BookViewHolder(val binding: ItemBookshelfListBinding) :
RecyclerView.ViewHolder(binding.root)
class GroupViewHolder(val binding: ItemBookshelfListGroupBinding) :
RecyclerView.ViewHolder(binding.root) RecyclerView.ViewHolder(binding.root)
} }

@ -0,0 +1,90 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
tools:ignore="UnusedAttribute">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="8dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<io.legado.app.ui.widget.image.CoverImageView
android:id="@+id/iv_cover"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:scaleType="centerCrop"
android:src="@drawable/image_cover_default"
android:transitionName="img_cover"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UnusedAttribute" />
<io.legado.app.ui.widget.text.BadgeView
android:id="@+id/bv_unread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:includeFontPadding="false"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rl_loading"
android:layout_width="22dp"
android:layout_height="22dp"
android:layout_gravity="right"
android:visibility="invisible"
app:hide_mode="invisible"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:loading_width="2dp"
tools:ignore="RtlHardcoded" />
</androidx.constraintlayout.widget.ConstraintLayout>
<TextView
android:id="@+id/tv_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:ellipsize="end"
android:gravity="top|center_horizontal"
android:includeFontPadding="false"
android:lines="2"
android:text="@string/book_name"
android:textColor="@color/primaryText"
android:textSize="12sp"
tools:ignore="RtlHardcoded,RtlSymmetry" />
</LinearLayout>
<View
android:id="@+id/vw_foreground"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -0,0 +1,170 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cv_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="true"
tools:ignore="UnusedAttribute">
<io.legado.app.ui.widget.image.CoverImageView
android:id="@+id/iv_cover"
android:layout_width="66dp"
android:layout_height="90dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="12dp"
android:contentDescription="@string/img_cover"
android:scaleType="centerCrop"
android:src="@drawable/image_cover_default"
android:transitionName="img_cover"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="UnusedAttribute" />
<FrameLayout
android:id="@+id/fl_has_new"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/iv_cover">
<io.legado.app.ui.widget.text.BadgeView
android:id="@+id/bv_unread"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_margin="5dp"
android:includeFontPadding="false"
tools:ignore="RtlHardcoded" />
<io.legado.app.ui.widget.anima.RotateLoading
android:id="@+id/rl_loading"
android:layout_width="26dp"
android:layout_height="26dp"
android:layout_gravity="right"
android:visibility="invisible"
app:loading_width="2dp"
tools:ignore="RtlHardcoded" />
</FrameLayout>
<TextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="12dp"
android:includeFontPadding="false"
android:paddingBottom="4dp"
android:paddingLeft="2dp"
android:singleLine="true"
android:text="@string/book_name"
android:textColor="@color/primaryText"
android:textSize="16sp"
app:layout_constraintBottom_toTopOf="@+id/tv_author"
app:layout_constraintLeft_toRightOf="@+id/iv_cover"
app:layout_constraintRight_toLeftOf="@id/fl_has_new"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_author"
android:layout_width="@dimen/desc_icon_size"
android:layout_height="@dimen/desc_icon_size"
android:contentDescription="@string/author"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:src="@drawable/ic_author"
app:layout_constraintBottom_toBottomOf="@+id/tv_author"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintTop_toTopOf="@+id/tv_author"
app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_author"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:maxLines="1"
android:paddingEnd="6dp"
android:text="@string/author"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
app:layout_constraintBottom_toTopOf="@+id/tv_read"
app:layout_constraintLeft_toRightOf="@+id/iv_author"
app:layout_constraintRight_toRightOf="@id/fl_has_new"
app:layout_constraintTop_toBottomOf="@+id/tv_name"
tools:ignore="RtlSymmetry" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_read"
android:layout_width="@dimen/desc_icon_size"
android:layout_height="@dimen/desc_icon_size"
android:contentDescription="@string/read_dur_progress"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:src="@drawable/ic_history"
app:layout_constraintBottom_toBottomOf="@+id/tv_read"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintTop_toTopOf="@+id/tv_read"
app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_read"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:includeFontPadding="false"
android:singleLine="true"
android:text="@string/read_dur_progress"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
app:layout_constraintBottom_toTopOf="@id/tv_last"
app:layout_constraintLeft_toRightOf="@+id/iv_read"
app:layout_constraintRight_toRightOf="@+id/fl_has_new"
app:layout_constraintTop_toBottomOf="@+id/tv_author" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_last"
android:layout_width="@dimen/desc_icon_size"
android:layout_height="@dimen/desc_icon_size"
android:contentDescription="@string/lasted_show"
android:paddingStart="2dp"
android:paddingEnd="2dp"
android:src="@drawable/ic_book_last"
app:layout_constraintBottom_toBottomOf="@+id/tv_last"
app:layout_constraintLeft_toLeftOf="@+id/tv_name"
app:layout_constraintTop_toTopOf="@+id/tv_last"
app:tint="@color/tv_text_summary"
tools:ignore="RtlHardcoded,RtlSymmetry" />
<TextView
android:id="@+id/tv_last"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:singleLine="true"
android:text="@string/lasted_show"
android:textColor="@color/tv_text_summary"
android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/iv_last"
app:layout_constraintRight_toRightOf="@id/fl_has_new"
app:layout_constraintTop_toBottomOf="@+id/tv_read" />
<View
android:id="@+id/vw_foreground"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="?android:attr/selectableItemBackground"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0"
tools:layout_editor_absoluteX="0dp" />
</androidx.constraintlayout.widget.ConstraintLayout>
Loading…
Cancel
Save