parent
b5a59fd8fd
commit
af217ea769
@ -0,0 +1,41 @@ |
||||
package com.novel.read.base |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import android.view.ViewGroup |
||||
import androidx.viewbinding.ViewBinding |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.BaseSectionQuickAdapter |
||||
import com.chad.library.adapter.base.entity.SectionEntity |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
|
||||
abstract class BaseBindingAdapter<T, VB : ViewBinding>(data: MutableList<T>? = null) : |
||||
BaseQuickAdapter<T, VBViewHolder<VB>>(0, data) { |
||||
|
||||
abstract fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): VB |
||||
|
||||
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): VBViewHolder<VB> { |
||||
val viewBinding = createViewBinding(LayoutInflater.from(parent.context), parent) |
||||
return VBViewHolder(viewBinding, viewBinding.root) |
||||
} |
||||
|
||||
} |
||||
|
||||
class VBViewHolder<VB : ViewBinding>(val vb: VB, view: View) : BaseViewHolder(view) |
||||
|
||||
|
||||
@JvmName("bind") |
||||
fun <VB : ViewBinding> BaseViewHolder.withBinding(bind: (View) -> VB): BaseViewHolder = |
||||
BaseViewHolderWithBinding(bind(itemView)) |
||||
|
||||
@JvmName("getBinding") |
||||
@Suppress("UNCHECKED_CAST") |
||||
fun <VB : ViewBinding> BaseViewHolder.getViewBinding(): VB { |
||||
if (this is BaseViewHolderWithBinding<*>) { |
||||
return binding as VB |
||||
} else { |
||||
throw IllegalStateException("The binding could not be found.") |
||||
} |
||||
} |
||||
|
||||
class BaseViewHolderWithBinding<VB : ViewBinding>(val binding: VB) : BaseViewHolder(binding.root) |
@ -1,14 +1,14 @@ |
||||
package com.novel.read.base |
||||
|
||||
import androidx.lifecycle.ViewModel |
||||
import androidx.viewbinding.ViewBinding |
||||
import com.novel.read.constant.Theme |
||||
|
||||
abstract class VMBaseActivity<VM : ViewModel>( |
||||
layoutID: Int, |
||||
abstract class VMBaseActivity<VB : ViewBinding,VM : ViewModel>( |
||||
fullScreen: Boolean = true, |
||||
theme: Theme = Theme.Auto, |
||||
toolBarTheme: Theme = Theme.Auto |
||||
) : BaseActivity(layoutID, fullScreen, theme, toolBarTheme) { |
||||
) : BaseActivity<VB>(fullScreen, theme, toolBarTheme) { |
||||
|
||||
protected abstract val viewModel: VM |
||||
|
||||
|
@ -1,28 +1,41 @@ |
||||
package com.novel.read.ui.channel |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.module.LoadMoreModule |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.BookListResp |
||||
import com.novel.read.databinding.ItemBookCommonBinding |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class ChannelInfoAdapter : |
||||
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { |
||||
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: BookListResp) { |
||||
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) { |
||||
holder.itemView.run { |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_book_name.text = item.getBBookName() |
||||
tv_book_description.text = item.getBIntroduction() |
||||
tv_book_author.text = item.getBAuthorName() |
||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tv_category.text = item.getBCategoryName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
} |
||||
} |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvBookName.text = item.getBBookName() |
||||
tvBookDescription.text = item.getBIntroduction() |
||||
tvBookAuthor.text = item.getBAuthorName() |
||||
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tvCategory.text = item.getBCategoryName() |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemBookCommonBinding { |
||||
return ItemBookCommonBinding.inflate(inflater,parent,false) |
||||
} |
||||
} |
@ -1,19 +1,26 @@ |
||||
package com.novel.read.ui.chapter |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.db.entity.Bookmark |
||||
import kotlinx.android.synthetic.main.item_bookmark.view.* |
||||
import com.novel.read.databinding.ItemBookmarkBinding |
||||
|
||||
class BookMarkAdapter :BaseQuickAdapter<Bookmark,BaseViewHolder>(R.layout.item_bookmark) { |
||||
class BookMarkAdapter :BaseBindingAdapter<Bookmark,ItemBookmarkBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: Bookmark) { |
||||
holder.itemView.run { |
||||
tv_chapter_name.text = item.chapterName |
||||
tv_content.text = item.content |
||||
override fun convert(holder: VBViewHolder<ItemBookmarkBinding>, item: Bookmark) { |
||||
holder.vb.run { |
||||
tvChapterName.text = item.chapterName |
||||
tvContent.text = item.content |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemBookmarkBinding { |
||||
return ItemBookmarkBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
} |
@ -1,57 +1,72 @@ |
||||
package com.novel.read.ui.chapter |
||||
|
||||
import android.view.View |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.db.entity.BookChapter |
||||
import com.novel.read.databinding.ItemChapterListBinding |
||||
import com.novel.read.help.BookHelp |
||||
import com.novel.read.utils.ext.* |
||||
import kotlinx.android.synthetic.main.item_chapter_list.view.* |
||||
|
||||
class ChapterListAdapter(val callback: Callback) : |
||||
BaseQuickAdapter<BookChapter, BaseViewHolder>(R.layout.item_chapter_list) { |
||||
BaseBindingAdapter<BookChapter, ItemChapterListBinding>() { |
||||
|
||||
val cacheFileNames = hashSetOf<String>() |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: BookChapter) { |
||||
holder.itemView.run { |
||||
|
||||
override fun convert(holder: VBViewHolder<ItemChapterListBinding>, item: BookChapter) { |
||||
|
||||
holder.vb.run { |
||||
val isDur = callback.durChapterIndex() == item.chapterIndex |
||||
val cached = callback.isLocalBook |
||||
|| cacheFileNames.contains(BookHelp.formatChapterName(item)) |
||||
if (isDur) { |
||||
tv_chapter_name.setTextColor(context.accentColor) |
||||
tvChapterName.setTextColor(context.accentColor) |
||||
} else { |
||||
tv_chapter_name.setTextColor(context.getCompatColor(R.color.primaryText)) |
||||
tvChapterName.setTextColor(context.getCompatColor(R.color.primaryText)) |
||||
} |
||||
tv_chapter_name.text = item.chapterName |
||||
tvChapterName.text = item.chapterName |
||||
if (!item.updateDate.isNullOrEmpty()) { |
||||
tv_tag.text = item.updateDate |
||||
tv_tag.visible() |
||||
tvTag.text = item.updateDate |
||||
tvTag.visible() |
||||
} |
||||
upHasCache(this, isDur, cached) |
||||
|
||||
} |
||||
|
||||
holder.itemView.run { |
||||
setOnClickListener { |
||||
getItem(holder.layoutPosition)?.let { |
||||
getItem(holder.layoutPosition).let { |
||||
callback.openChapter(it) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
private fun upHasCache(itemView: View, isDur: Boolean, cached: Boolean) = itemView.apply { |
||||
tv_chapter_name.paint.isFakeBoldText = cached |
||||
iv_checked.setImageResource(R.drawable.ic_outline_cloud_24) |
||||
iv_checked.visible(!cached) |
||||
private fun upHasCache(itemView: ItemChapterListBinding, isDur: Boolean, cached: Boolean) = itemView.run { |
||||
tvChapterName.paint.isFakeBoldText = cached |
||||
ivChecked.setImageResource(R.drawable.ic_outline_cloud_24) |
||||
ivChecked.visible(!cached) |
||||
if (isDur) { |
||||
iv_checked.setImageResource(R.drawable.ic_check) |
||||
iv_checked.visible() |
||||
ivChecked.setImageResource(R.drawable.ic_check) |
||||
ivChecked.visible() |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemChapterListBinding { |
||||
return ItemChapterListBinding.inflate(inflater,parent,false) |
||||
} |
||||
|
||||
interface Callback { |
||||
val isLocalBook: Boolean |
||||
fun openChapter(bookChapter: BookChapter) |
||||
fun durChapterIndex(): Int |
||||
} |
||||
|
||||
} |
@ -1,28 +1,37 @@ |
||||
package com.novel.read.ui.daily |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.module.LoadMoreModule |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.BookListResp |
||||
import com.novel.read.databinding.ItemBookCommonBinding |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class DailyAdapter : |
||||
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { |
||||
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: BookListResp) { |
||||
holder.itemView.run { |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_book_name.text = item.getBBookName() |
||||
tv_book_description.text = item.getBIntroduction() |
||||
tv_book_author.text = item.getBAuthorName() |
||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tv_category.text = item.getBCategoryName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) { |
||||
holder.itemView.onClick { |
||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
||||
} |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvBookName.text = item.getBBookName() |
||||
tvBookDescription.text = item.getBIntroduction() |
||||
tvBookAuthor.text = item.getBAuthorName() |
||||
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tvCategory.text = item.getBCategoryName() |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemBookCommonBinding { |
||||
return ItemBookCommonBinding.inflate(inflater, parent, false) |
||||
} |
||||
} |
@ -1,28 +1,39 @@ |
||||
package com.novel.read.ui.end |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.module.LoadMoreModule |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.BookListResp |
||||
import com.novel.read.databinding.ItemBookCommonBinding |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class EndAdapter : |
||||
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { |
||||
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: BookListResp) { |
||||
holder.itemView.run { |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_book_name.text = item.getBBookName() |
||||
tv_book_description.text = item.getBIntroduction() |
||||
tv_book_author.text = item.getBAuthorName() |
||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tv_category.text = item.getBCategoryName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) { |
||||
holder.itemView.onClick { |
||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
||||
} |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvBookName.text = item.getBBookName() |
||||
tvBookDescription.text = item.getBIntroduction() |
||||
tvBookAuthor.text = item.getBAuthorName() |
||||
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tvCategory.text = item.getBCategoryName() |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemBookCommonBinding { |
||||
return ItemBookCommonBinding.inflate(inflater, parent, false) |
||||
} |
||||
} |
@ -1,23 +1,36 @@ |
||||
package com.novel.read.ui.info |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.BookListResp |
||||
import com.novel.read.databinding.ItemHotItemBinding |
||||
import com.novel.read.lib.ATH |
||||
import kotlinx.android.synthetic.main.item_hot_item.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class BookInfoAdapter :BaseQuickAdapter<BookListResp,BaseViewHolder>(R.layout.item_hot_item) { |
||||
class BookInfoAdapter :BaseBindingAdapter<BookListResp,ItemHotItemBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: BookListResp) { |
||||
override fun convert(holder: VBViewHolder<ItemHotItemBinding>, item: BookListResp) { |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvName.text = item.getBBookName() |
||||
} |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_name.text = item.getBBookName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemHotItemBinding { |
||||
return ItemHotItemBinding.inflate(inflater,parent,false) |
||||
} |
||||
} |
@ -1,73 +1,84 @@ |
||||
package com.novel.read.ui.main.bookshelf |
||||
|
||||
import android.os.Bundle |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.entity.SectionEntity |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.getViewBinding |
||||
import com.novel.read.base.withBinding |
||||
import com.novel.read.constant.BookType |
||||
import com.novel.read.data.db.entity.Book |
||||
import com.novel.read.databinding.ItemBookshelfListBinding |
||||
import com.novel.read.lib.ATH |
||||
import com.novel.read.utils.ext.* |
||||
import kotlinx.android.synthetic.main.item_bookshelf_list.view.* |
||||
import kotlinx.android.synthetic.main.item_bookshelf_list.view.bv_unread |
||||
import kotlinx.android.synthetic.main.item_bookshelf_list.view.iv_cover |
||||
import kotlinx.android.synthetic.main.item_bookshelf_list.view.rl_loading |
||||
import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name |
||||
|
||||
class BookShelfAdapter(private val callBack: CallBack) : BaseBookAdapter(R.layout.item_bookshelf_list) { |
||||
|
||||
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder { |
||||
val viewHolder = super.onCreateDefViewHolder(parent, viewType) |
||||
return viewHolder.withBinding(ItemBookshelfListBinding::bind) |
||||
} |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) { |
||||
super.convert(holder, item, payloads) |
||||
val bundle = payloads.getOrNull(0) as? Bundle |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
|
||||
holder.getViewBinding<ItemBookshelfListBinding>().apply { |
||||
if (bundle == null) { |
||||
tv_name.text = item.bookName |
||||
tv_author.text = item.authorPenname |
||||
tv_read.text = item.durChapterTitle |
||||
tv_last.text = item.keyWord |
||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(holder, item) |
||||
tvName.text = item.bookName |
||||
tvAuthor.text = item.authorPenname |
||||
tvRead.text = item.durChapterTitle |
||||
tvLast.text = item.keyWord |
||||
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(this, item) |
||||
} else { |
||||
tv_read.text = item.durChapterTitle |
||||
tv_last.text = item.keyWord |
||||
tvRead.text = item.durChapterTitle |
||||
tvLast.text = item.keyWord |
||||
bundle.keySet().forEach { |
||||
when (it) { |
||||
"name" -> tv_name.text = item.bookName |
||||
"author" -> tv_author.text = item.authorPenname |
||||
"cover" -> iv_cover.load( |
||||
"name" -> tvName.text = item.bookName |
||||
"author" -> tvAuthor.text = item.authorPenname |
||||
"cover" -> ivCover.load( |
||||
item.coverImageUrl, |
||||
item.bookName, |
||||
item.authorPenname |
||||
) |
||||
"refresh" -> upRefresh(holder, item) |
||||
"refresh" -> upRefresh(this, item) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
|
||||
} |
||||
} |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: Book) { |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
tv_name.text = item.bookName |
||||
tv_author.text = item.authorPenname |
||||
tv_read.text = item.durChapterTitle |
||||
tv_last.text = item.keyWord |
||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(holder, item) |
||||
} |
||||
holder.getViewBinding<ItemBookshelfListBinding>().apply { |
||||
tvName.text = item.bookName |
||||
tvAuthor.text = item.authorPenname |
||||
tvRead.text = item.durChapterTitle |
||||
tvLast.text = item.keyWord |
||||
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(this, item) |
||||
} |
||||
} |
||||
|
||||
|
||||
private fun upRefresh(holder: BaseViewHolder, item: Book) { |
||||
private fun upRefresh(holder: ItemBookshelfListBinding, item: Book) { |
||||
if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) { |
||||
holder.itemView.bv_unread.invisible() |
||||
holder.itemView.rl_loading.show() |
||||
holder.bvUnread.invisible() |
||||
holder.rlLoading.show() |
||||
} else { |
||||
holder.itemView.rl_loading.hide() |
||||
holder.itemView.bv_unread.setBadgeCount(0) |
||||
holder.itemView.bv_unread.setHighlight(true) |
||||
holder.rlLoading.hide() |
||||
holder.bvUnread.setBadgeCount(0) |
||||
holder.bvUnread.setHighlight(true) |
||||
} |
||||
} |
||||
|
||||
|
@ -1,61 +1,71 @@ |
||||
package com.novel.read.ui.main.bookshelf |
||||
|
||||
import android.os.Bundle |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.getViewBinding |
||||
import com.novel.read.base.withBinding |
||||
import com.novel.read.constant.BookType |
||||
import com.novel.read.data.db.entity.Book |
||||
import com.novel.read.databinding.ItemBookshelfGridBinding |
||||
import com.novel.read.lib.ATH |
||||
import com.novel.read.utils.ext.invisible |
||||
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.* |
||||
|
||||
class BooksAdapterGrid(private val callBack: CallBack) : |
||||
BaseBookAdapter(R.layout.item_bookshelf_grid) { |
||||
|
||||
override fun onCreateDefViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder { |
||||
val viewHolder = super.onCreateDefViewHolder(parent, viewType) |
||||
return viewHolder.withBinding(ItemBookshelfGridBinding::bind) |
||||
} |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) { |
||||
super.convert(holder, item, payloads) |
||||
val bundle = payloads.getOrNull(0) as? Bundle |
||||
|
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
holder.getViewBinding<ItemBookshelfGridBinding>().apply{ |
||||
if (bundle == null) { |
||||
tv_name.text = item.bookName |
||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(holder, item) |
||||
tvName.text = item.bookName |
||||
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(this, item) |
||||
} else { |
||||
bundle.keySet().forEach { |
||||
when (it) { |
||||
"name" -> tv_name.text = item.bookName |
||||
"cover" -> iv_cover.load( |
||||
"name" -> tvName.text = item.bookName |
||||
"cover" -> ivCover.load( |
||||
item.coverImageUrl, |
||||
item.bookName, |
||||
item.authorPenname |
||||
) |
||||
"refresh" -> upRefresh(holder, item) |
||||
"refresh" -> upRefresh(this, item) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
} |
||||
} |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: Book) { |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
tv_name.text = item.bookName |
||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(holder, item) |
||||
} |
||||
holder.getViewBinding<ItemBookshelfGridBinding>().apply{ |
||||
tvName.text = item.bookName |
||||
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
upRefresh(this, item) |
||||
} |
||||
} |
||||
|
||||
private fun upRefresh(holder: BaseViewHolder, item: Book) { |
||||
private fun upRefresh(holder: ItemBookshelfGridBinding, item: Book) { |
||||
if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) { |
||||
holder.itemView.bv_unread.invisible() |
||||
holder.itemView.rl_loading.show() |
||||
holder.bvUnread.invisible() |
||||
holder.rlLoading.show() |
||||
} else { |
||||
holder.itemView.rl_loading.hide() |
||||
holder.itemView.bv_unread.setBadgeCount(0) |
||||
holder.itemView.bv_unread.setHighlight(true) |
||||
holder.rlLoading.hide() |
||||
holder.bvUnread.setBadgeCount(0) |
||||
holder.bvUnread.setHighlight(true) |
||||
} |
||||
} |
||||
} |
@ -1,36 +1,46 @@ |
||||
package com.novel.read.ui.main.bookshelf.arrange |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import android.view.ViewGroup |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.db.entity.Book |
||||
import com.novel.read.databinding.ItemArrangeBookBinding |
||||
import com.novel.read.utils.ext.backgroundColor |
||||
import kotlinx.android.synthetic.main.item_arrange_book.view.* |
||||
import org.jetbrains.anko.backgroundColor |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class ArrangeBookAdapter(val callBack: CallBack) : BaseQuickAdapter<Book, BaseViewHolder>(R.layout.item_arrange_book) { |
||||
override fun convert(holder: BaseViewHolder, item: Book) { |
||||
holder.itemView.run { |
||||
backgroundColor = context.backgroundColor |
||||
tv_name.text = item.bookName |
||||
tv_author.text = item.authorPenname |
||||
tv_author.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE |
||||
class ArrangeBookAdapter(val callBack: CallBack) : |
||||
BaseBindingAdapter<Book, ItemArrangeBookBinding>() { |
||||
|
||||
override fun convert(holder: VBViewHolder<ItemArrangeBookBinding>, item: Book) { |
||||
holder.itemView.backgroundColor = context.backgroundColor |
||||
holder.vb.run { |
||||
tvName.text = item.bookName |
||||
tvAuthor.text = item.authorPenname |
||||
tvAuthor.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE |
||||
// checkbox.isChecked = selectedBooks.contains(item) |
||||
iv_book.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
tv_delete.onClick { |
||||
getItem(holder.layoutPosition)?.let { |
||||
ivBook.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||
tvDelete.onClick { |
||||
getItem(holder.layoutPosition).let { |
||||
callBack.deleteBook(it) |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemArrangeBookBinding { |
||||
return ItemArrangeBookBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
interface CallBack { |
||||
fun upSelectCount() |
||||
fun updateBook(vararg book: Book) |
||||
fun deleteBook(book: Book) |
||||
} |
||||
|
||||
} |
@ -1,24 +1,35 @@ |
||||
package com.novel.read.ui.main.mail.pick |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.ClickRank |
||||
import com.novel.read.databinding.ItemClickItemBinding |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_click_item.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class ClickAdapter :BaseQuickAdapter<ClickRank,BaseViewHolder>(R.layout.item_click_item) { |
||||
class ClickAdapter : BaseBindingAdapter<ClickRank, ItemClickItemBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: ClickRank) { |
||||
holder.itemView.run { |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_name.text = item.getBBookName() |
||||
tv_count.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
override fun convert(holder: VBViewHolder<ItemClickItemBinding>, item: ClickRank) { |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvName.text = item.getBBookName() |
||||
tvCount.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
} |
||||
holder.itemView.onClick { |
||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemClickItemBinding { |
||||
return ItemClickItemBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
} |
@ -1,25 +1,38 @@ |
||||
package com.novel.read.ui.main.mail.pick |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.EndRank |
||||
import com.novel.read.databinding.ItemEndItemBinding |
||||
import com.novel.read.lib.ATH |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_end_item.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class EndAdapter :BaseQuickAdapter<EndRank,BaseViewHolder>(R.layout.item_end_item) { |
||||
class EndAdapter :BaseBindingAdapter<EndRank,ItemEndItemBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: EndRank) { |
||||
override fun convert(holder: VBViewHolder<ItemEndItemBinding>, item: EndRank) { |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvName.text = item.getBBookName() |
||||
} |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_name.text = item.getBBookName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemEndItemBinding { |
||||
return ItemEndItemBinding.inflate(inflater,parent,false) |
||||
} |
||||
|
||||
} |
@ -1,24 +1,37 @@ |
||||
package com.novel.read.ui.main.mail.pick |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.HotRank |
||||
import com.novel.read.databinding.ItemHotItemBinding |
||||
import com.novel.read.lib.ATH |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_hot_item.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class HotAdapter :BaseQuickAdapter<HotRank,BaseViewHolder>(R.layout.item_hot_item) { |
||||
class HotAdapter :BaseBindingAdapter<HotRank,ItemHotItemBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: HotRank) { |
||||
override fun convert(holder: VBViewHolder<ItemHotItemBinding>, item: HotRank) { |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBName(), item.getBAuthor()) |
||||
tvName.text = item.getBName() |
||||
} |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
iv_cover.load(item.coverImageUrl, item.getBName(), item.getBAuthor()) |
||||
tv_name.text = item.getBName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemHotItemBinding { |
||||
return ItemHotItemBinding.inflate(inflater,parent,false) |
||||
} |
||||
} |
@ -1,59 +1,31 @@ |
||||
package com.novel.read.ui.main.my |
||||
|
||||
import android.annotation.SuppressLint |
||||
import android.content.ActivityNotFoundException |
||||
import android.content.Context |
||||
import android.content.Intent |
||||
import android.net.Uri |
||||
import android.os.Bundle |
||||
import android.view.View |
||||
import com.novel.read.App |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseFragment |
||||
import com.novel.read.databinding.FragmentMyBinding |
||||
import com.novel.read.ui.feedback.FeedBackActivity |
||||
import com.novel.read.ui.setting.SettingActivity |
||||
import com.novel.read.ui.widget.dialog.AppraiseDialog |
||||
import com.novel.read.utils.ext.startActivity |
||||
import com.novel.read.utils.ext.toast |
||||
import kotlinx.android.synthetic.main.fragment_my.* |
||||
import kotlinx.android.synthetic.main.view_title_bar.* |
||||
import com.novel.read.utils.viewbindingdelegate.viewBinding |
||||
|
||||
|
||||
class MyFragment : BaseFragment(R.layout.fragment_my) { |
||||
|
||||
private val binding by viewBinding(FragmentMyBinding::bind) |
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||
setSupportToolbar(toolbar) |
||||
tv_options.setOnClickListener { |
||||
setSupportToolbar(binding.titleBar.toolbar) |
||||
binding.tvOptions.setOnClickListener { |
||||
startActivity<FeedBackActivity>() |
||||
} |
||||
tv_setting.setOnClickListener { |
||||
binding.tvSetting.setOnClickListener { |
||||
startActivity<SettingActivity>() |
||||
} |
||||
tv_appraise.setOnClickListener { |
||||
val dialog = AppraiseDialog(requireActivity()) |
||||
dialog.appraiseDialog { |
||||
goToMarket(App.INSTANCE, App.INSTANCE.packageName) |
||||
dialog.dismiss() |
||||
} |
||||
dialog.show() |
||||
} |
||||
} |
||||
|
||||
@SuppressLint("QueryPermissionsNeeded") |
||||
fun goToMarket(context: Context, packageName: String) { |
||||
val uri = Uri.parse("market://details?id=$packageName") |
||||
val goToMarket = Intent(Intent.ACTION_VIEW, uri) |
||||
val googlePlay = "com.android.vending" //这里对应的是谷歌商店,跳转别的商店改成对应的即可 |
||||
goToMarket.setPackage(googlePlay) //这里对应的是谷歌商店,跳转别的商店改成对应的即可 |
||||
try { |
||||
startActivity(goToMarket) |
||||
} catch (e: ActivityNotFoundException) { |
||||
if (goToMarket.resolveActivity(context.packageManager) != null) { //有浏览器 |
||||
startActivity(goToMarket) |
||||
} else { |
||||
toast(R.string.no_google) |
||||
} |
||||
e.printStackTrace() |
||||
binding.tvAppraise.setOnClickListener { |
||||
AppraiseDialog().show(childFragmentManager,"AppDialog") |
||||
} |
||||
} |
||||
|
||||
|
@ -1,19 +0,0 @@ |
||||
package com.novel.read.ui.main.my |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.data.model.Tools |
||||
import com.novel.read.lib.ATH |
||||
import kotlinx.android.synthetic.main.item_tools.view.* |
||||
|
||||
class ToolsAdapter : BaseQuickAdapter<Tools, BaseViewHolder>(R.layout.item_tools) { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: Tools) { |
||||
holder.itemView.run { |
||||
ATH.applyBackgroundTint(this) |
||||
tv_tools.text = item.title |
||||
iv_tools.setImageResource(item.img) |
||||
} |
||||
} |
||||
} |
@ -1,28 +1,38 @@ |
||||
package com.novel.read.ui.rank |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.module.LoadMoreModule |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.BookListResp |
||||
import com.novel.read.databinding.ItemBookCommonBinding |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class RankAdapter : |
||||
BaseQuickAdapter<BookListResp, BaseViewHolder>(R.layout.item_book_common), LoadMoreModule { |
||||
BaseBindingAdapter<BookListResp, ItemBookCommonBinding>(), LoadMoreModule { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: BookListResp) { |
||||
holder.itemView.run { |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_book_name.text = item.getBBookName() |
||||
tv_book_description.text = item.getBIntroduction() |
||||
tv_book_author.text = item.getBAuthorName() |
||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tv_category.text = item.getBCategoryName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: BookListResp) { |
||||
|
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvBookName.text = item.getBBookName() |
||||
tvBookDescription.text = item.getBIntroduction() |
||||
tvBookAuthor.text = item.getBAuthorName() |
||||
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tvCategory.text = item.getBCategoryName() |
||||
} |
||||
holder.itemView.onClick { |
||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemBookCommonBinding { |
||||
return ItemBookCommonBinding.inflate(inflater, parent, false) |
||||
} |
||||
} |
@ -1,26 +1,32 @@ |
||||
package com.novel.read.ui.rank |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.View |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.module.LoadMoreModule |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.TypeName |
||||
import kotlinx.android.synthetic.main.item_type.view.* |
||||
import com.novel.read.databinding.ItemTypeBinding |
||||
|
||||
class TypeAdapter : |
||||
BaseQuickAdapter<TypeName, BaseViewHolder>(R.layout.item_type), LoadMoreModule { |
||||
BaseBindingAdapter<TypeName, ItemTypeBinding>(), LoadMoreModule { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: TypeName) { |
||||
holder.itemView.run { |
||||
tv_type.text = item.name |
||||
override fun convert(holder: VBViewHolder<ItemTypeBinding>, item: TypeName) { |
||||
holder.vb.run { |
||||
tvType.text = item.name |
||||
if (item.check) { |
||||
iv_check.visibility = View.VISIBLE |
||||
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background)) |
||||
ivCheck.visibility = View.VISIBLE |
||||
llBg.setBackgroundColor(context.resources.getColor(R.color.background)) |
||||
} else { |
||||
iv_check.visibility = View.GONE |
||||
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background_menu)) |
||||
ivCheck.visibility = View.GONE |
||||
llBg.setBackgroundColor(context.resources.getColor(R.color.background_menu)) |
||||
} |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): ItemTypeBinding { |
||||
return ItemTypeBinding.inflate(inflater, parent, false) |
||||
} |
||||
} |
@ -1,17 +1,22 @@ |
||||
package com.novel.read.ui.search |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.db.entity.SearchHistory |
||||
import kotlinx.android.synthetic.main.item_label.view.* |
||||
import com.novel.read.databinding.ItemLabelBinding |
||||
|
||||
class HistoryAdapter : BaseQuickAdapter<SearchHistory, BaseViewHolder>(R.layout.item_label) { |
||||
class HistoryAdapter : BaseBindingAdapter<SearchHistory, ItemLabelBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: SearchHistory) { |
||||
holder.itemView.run { |
||||
tv_label.text = item.getBKey() |
||||
override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: SearchHistory) { |
||||
holder.vb.run { |
||||
tvLabel.text = item.getBKey() |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): ItemLabelBinding { |
||||
return ItemLabelBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
} |
@ -1,19 +1,27 @@ |
||||
package com.novel.read.ui.search |
||||
|
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.constant.AppConst |
||||
import com.novel.read.databinding.ItemLabelBinding |
||||
import com.novel.read.utils.StringUtils |
||||
import kotlinx.android.synthetic.main.item_label.view.* |
||||
|
||||
class HotAdapter : BaseQuickAdapter<String, BaseViewHolder>(R.layout.item_label) { |
||||
class HotAdapter : BaseBindingAdapter<String, ItemLabelBinding>() { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: String) { |
||||
holder.itemView.run { |
||||
tv_label.text = StringUtils.convertCC(item) |
||||
tv_label.setBackgroundColor(AppConst.tagColors[holder.adapterPosition % 8]) |
||||
override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: String) { |
||||
holder.vb.run { |
||||
tvLabel.text = StringUtils.convertCC(item) |
||||
tvLabel.setBackgroundColor(AppConst.tagColors[holder.adapterPosition % 8]) |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding(inflater: LayoutInflater, parent: ViewGroup): ItemLabelBinding { |
||||
return ItemLabelBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
} |
@ -1,31 +1,39 @@ |
||||
package com.novel.read.ui.search |
||||
|
||||
import com.chad.library.adapter.base.BaseQuickAdapter |
||||
import android.view.LayoutInflater |
||||
import android.view.ViewGroup |
||||
import com.chad.library.adapter.base.module.LoadMoreModule |
||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||
import com.novel.read.R |
||||
import com.novel.read.base.BaseBindingAdapter |
||||
import com.novel.read.base.VBViewHolder |
||||
import com.novel.read.data.model.SearchResp |
||||
import com.novel.read.databinding.ItemBookCommonBinding |
||||
import com.novel.read.ui.info.BookInfoActivity |
||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
||||
import kotlinx.android.synthetic.main.item_init_search.view.tv_book_name |
||||
import org.jetbrains.anko.sdk27.listeners.onClick |
||||
|
||||
class SearchAdapter : BaseQuickAdapter<SearchResp, BaseViewHolder>(R.layout.item_book_common), |
||||
class SearchAdapter : BaseBindingAdapter<SearchResp, ItemBookCommonBinding>(), |
||||
LoadMoreModule { |
||||
|
||||
override fun convert(holder: BaseViewHolder, item: SearchResp) { |
||||
holder.itemView.run { |
||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tv_book_name.text = item.getBBookName() |
||||
tv_book_description.text = item.getBIntroduction() |
||||
tv_book_author.text = item.getBAuthorName() |
||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tv_category.text = item.getBCategoryName() |
||||
onClick { |
||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
||||
} |
||||
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: SearchResp) { |
||||
holder.vb.run { |
||||
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||
tvBookName.text = item.getBBookName() |
||||
tvBookDescription.text = item.getBIntroduction() |
||||
tvBookAuthor.text = item.getBAuthorName() |
||||
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||
tvCategory.text = item.getBCategoryName() |
||||
|
||||
} |
||||
holder.itemView.onClick { |
||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
||||
} |
||||
} |
||||
|
||||
override fun createViewBinding( |
||||
inflater: LayoutInflater, |
||||
parent: ViewGroup |
||||
): ItemBookCommonBinding { |
||||
return ItemBookCommonBinding.inflate(inflater, parent, false) |
||||
} |
||||
|
||||
|
||||
|
@ -1,37 +1,44 @@ |
||||
package com.novel.read.ui.widget.dialog |
||||
|
||||
import android.app.Dialog |
||||
import android.content.Context |
||||
import android.os.Bundle |
||||
import android.view.* |
||||
import android.widget.LinearLayout |
||||
import android.widget.TextView |
||||
import com.novel.read.R |
||||
import kotlinx.android.synthetic.main.dialog_go_appraise.* |
||||
|
||||
class AppraiseDialog(context: Context) : Dialog(context, R.style.dialog) { |
||||
private val view: View = LayoutInflater.from(context).inflate(R.layout.dialog_go_appraise, null) |
||||
|
||||
init { |
||||
view.setHasTransientState(true) |
||||
setContentView( |
||||
view, LinearLayout.LayoutParams( |
||||
LinearLayout.LayoutParams.MATCH_PARENT, |
||||
LinearLayout.LayoutParams.MATCH_PARENT |
||||
import com.novel.read.base.BaseDialogFragment |
||||
import com.novel.read.databinding.DialogGoAppraiseBinding |
||||
import com.novel.read.utils.ext.goShop |
||||
import com.novel.read.utils.viewbindingdelegate.viewBinding |
||||
|
||||
class AppraiseDialog : BaseDialogFragment() { |
||||
private val binding by viewBinding(DialogGoAppraiseBinding::bind) |
||||
|
||||
override fun onStart() { |
||||
super.onStart() |
||||
dialog?.window?.setLayout( |
||||
ViewGroup.LayoutParams.MATCH_PARENT, |
||||
ViewGroup.LayoutParams.WRAP_CONTENT |
||||
) |
||||
) |
||||
setCancelable(false) |
||||
initView() |
||||
|
||||
} |
||||
|
||||
private fun initView() { |
||||
val mTvCancel = findViewById<TextView>(R.id.tv_cancel) |
||||
|
||||
mTvCancel.setOnClickListener { dismiss() } |
||||
override fun onCreateView( |
||||
inflater: LayoutInflater, |
||||
container: ViewGroup?, |
||||
savedInstanceState: Bundle? |
||||
): View? { |
||||
return inflater.inflate(R.layout.dialog_go_appraise, container) |
||||
} |
||||
|
||||
fun appraiseDialog(receiveClickListener: View.OnClickListener) { |
||||
tv_appraise.setOnClickListener(receiveClickListener) |
||||
override fun onCreate(savedInstanceState: Bundle?) { |
||||
super.onCreate(savedInstanceState) |
||||
setStyle(STYLE_NO_TITLE, R.style.dialog_app) |
||||
} |
||||
|
||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?){ |
||||
binding.tvAppraise.setOnClickListener{ |
||||
context?.goShop() |
||||
dismiss() |
||||
} |
||||
binding.clBg.setBackgroundResource(R.color.transparent) |
||||
binding.tvCancel.setOnClickListener { dismiss() } |
||||
} |
||||
} |
@ -0,0 +1,60 @@ |
||||
@file:Suppress("RedundantVisibilityModifier", "unused") |
||||
|
||||
package com.novel.read.utils.viewbindingdelegate |
||||
|
||||
import android.view.View |
||||
import androidx.annotation.IdRes |
||||
import androidx.core.app.ComponentActivity |
||||
import androidx.viewbinding.ViewBinding |
||||
|
||||
private class ActivityViewBindingProperty<A : ComponentActivity, T : ViewBinding>( |
||||
viewBinder: (A) -> T |
||||
) : ViewBindingProperty<A, T>(viewBinder) { |
||||
|
||||
override fun getLifecycleOwner(thisRef: A) = thisRef |
||||
} |
||||
|
||||
/** |
||||
* Create new [ViewBinding] associated with the [Activity][ComponentActivity] and allow customize how |
||||
* a [View] will be bounded to the view binding. |
||||
*/ |
||||
@JvmName("viewBindingActivity") |
||||
public fun <A : ComponentActivity, T : ViewBinding> ComponentActivity.viewBinding( |
||||
viewBinder: (A) -> T |
||||
): ViewBindingProperty<A, T> { |
||||
return ActivityViewBindingProperty(viewBinder) |
||||
} |
||||
|
||||
/** |
||||
* Create new [ViewBinding] associated with the [Activity][ComponentActivity] and allow customize how |
||||
* a [View] will be bounded to the view binding. |
||||
*/ |
||||
@JvmName("viewBindingActivity") |
||||
public inline fun <A : ComponentActivity, T : ViewBinding> ComponentActivity.viewBinding( |
||||
crossinline vbFactory: (View) -> T, |
||||
crossinline viewProvider: (A) -> View |
||||
): ViewBindingProperty<A, T> { |
||||
return viewBinding { activity: A -> vbFactory(viewProvider(activity)) } |
||||
} |
||||
|
||||
/** |
||||
* Create new [ViewBinding] associated with the [Activity][this] and allow customize how |
||||
* a [View] will be bounded to the view binding. |
||||
* |
||||
* @param vbFactory Function that create new instance of [ViewBinding]. `MyViewBinding::bind` can be used |
||||
* @param viewBindingRootId Root view's id that will be used as root for the view binding |
||||
*/ |
||||
@Suppress("unused") |
||||
@JvmName("viewBindingActivity") |
||||
public inline fun <T : ViewBinding> ComponentActivity.viewBinding( |
||||
crossinline vbFactory: (View) -> T, |
||||
@IdRes viewBindingRootId: Int |
||||
): ViewBindingProperty<ComponentActivity, T> { |
||||
return viewBinding { activity: ComponentActivity -> |
||||
vbFactory( |
||||
activity.findViewById( |
||||
viewBindingRootId |
||||
) |
||||
) |
||||
} |
||||
} |
@ -0,0 +1,54 @@ |
||||
@file:Suppress("RedundantVisibilityModifier", "unused") |
||||
@file:JvmName("ReflectionFragmentViewBindings") |
||||
|
||||
package com.novel.read.utils.viewbindingdelegate |
||||
|
||||
import android.view.View |
||||
import androidx.annotation.IdRes |
||||
import androidx.fragment.app.Fragment |
||||
import androidx.viewbinding.ViewBinding |
||||
|
||||
private class FragmentViewBindingProperty<F : Fragment, T : ViewBinding>( |
||||
viewBinder: (F) -> T |
||||
) : ViewBindingProperty<F, T>(viewBinder) { |
||||
|
||||
override fun getLifecycleOwner(thisRef: F) = thisRef.viewLifecycleOwner |
||||
} |
||||
|
||||
/** |
||||
* Create new [ViewBinding] associated with the [Fragment] |
||||
*/ |
||||
@JvmName("viewBindingFragment") |
||||
public fun <F : Fragment, T : ViewBinding> Fragment.viewBinding(viewBinder: (F) -> T): ViewBindingProperty<F, T> { |
||||
return FragmentViewBindingProperty(viewBinder) |
||||
} |
||||
|
||||
/** |
||||
* Create new [ViewBinding] associated with the [Fragment] |
||||
* |
||||
* @param vbFactory Function that create new instance of [ViewBinding]. `MyViewBinding::bind` can be used |
||||
* @param viewProvider Provide a [View] from the Fragment. By default call [Fragment.requireView] |
||||
*/ |
||||
@JvmName("viewBindingFragment") |
||||
public inline fun <F : Fragment, T : ViewBinding> Fragment.viewBinding( |
||||
crossinline vbFactory: (View) -> T, |
||||
crossinline viewProvider: (F) -> View = Fragment::requireView |
||||
): ViewBindingProperty<F, T> { |
||||
return viewBinding { fragment: F -> vbFactory(viewProvider(fragment)) } |
||||
} |
||||
|
||||
/** |
||||
* Create new [ViewBinding] associated with the [Fragment] |
||||
* |
||||
* @param vbFactory Function that create new instance of [ViewBinding]. `MyViewBinding::bind` can be used |
||||
* @param viewBindingRootId Root view's id that will be used as root for the view binding |
||||
*/ |
||||
@JvmName("viewBindingFragment") |
||||
public inline fun <T : ViewBinding> Fragment.viewBinding( |
||||
crossinline vbFactory: (View) -> T, |
||||
@IdRes viewBindingRootId: Int |
||||
): ViewBindingProperty<Fragment, T> { |
||||
return viewBinding(vbFactory) { fragment: Fragment -> |
||||
fragment.requireView().findViewById(viewBindingRootId) |
||||
} |
||||
} |
@ -0,0 +1,57 @@ |
||||
@file:Suppress("RedundantVisibilityModifier") |
||||
|
||||
package com.novel.read.utils.viewbindingdelegate |
||||
|
||||
import android.os.Handler |
||||
import android.os.Looper |
||||
import androidx.annotation.MainThread |
||||
import androidx.lifecycle.DefaultLifecycleObserver |
||||
import androidx.lifecycle.Lifecycle |
||||
import androidx.lifecycle.LifecycleOwner |
||||
import androidx.viewbinding.ViewBinding |
||||
import kotlin.properties.ReadOnlyProperty |
||||
import kotlin.reflect.KProperty |
||||
|
||||
public abstract class ViewBindingProperty<in R : Any, T : ViewBinding>( |
||||
private val viewBinder: (R) -> T |
||||
) : ReadOnlyProperty<R, T> { |
||||
|
||||
private var viewBinding: T? = null |
||||
private val lifecycleObserver = ClearOnDestroyLifecycleObserver() |
||||
private var thisRef: R? = null |
||||
|
||||
protected abstract fun getLifecycleOwner(thisRef: R): LifecycleOwner |
||||
|
||||
@MainThread |
||||
public override fun getValue(thisRef: R, property: KProperty<*>): T { |
||||
viewBinding?.let { return it } |
||||
|
||||
this.thisRef = thisRef |
||||
val lifecycle = getLifecycleOwner(thisRef).lifecycle |
||||
if (lifecycle.currentState == Lifecycle.State.DESTROYED) { |
||||
mainHandler.post { viewBinding = null } |
||||
} else { |
||||
lifecycle.addObserver(lifecycleObserver) |
||||
} |
||||
return viewBinder(thisRef).also { viewBinding = it } |
||||
} |
||||
|
||||
@MainThread |
||||
public fun clear() { |
||||
val thisRef = thisRef ?: return |
||||
this.thisRef = null |
||||
getLifecycleOwner(thisRef).lifecycle.removeObserver(lifecycleObserver) |
||||
mainHandler.post { viewBinding = null } |
||||
} |
||||
|
||||
private inner class ClearOnDestroyLifecycleObserver : DefaultLifecycleObserver { |
||||
|
||||
@MainThread |
||||
override fun onDestroy(owner: LifecycleOwner): Unit = clear() |
||||
} |
||||
|
||||
private companion object { |
||||
|
||||
private val mainHandler = Handler(Looper.getMainLooper()) |
||||
} |
||||
} |
@ -1,55 +0,0 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||
android:layout_width="match_parent" |
||||
android:layout_height="50dp" |
||||
android:layout_gravity="center" |
||||
android:clickable="true" |
||||
android:focusable="true" |
||||
android:id="@+id/cv_tools" |
||||
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||
xmlns:tools="http://schemas.android.com/tools"> |
||||
|
||||
<ImageView |
||||
android:id="@+id/iv_tools" |
||||
android:layout_width="22dp" |
||||
android:layout_height="22dp" |
||||
android:src="@drawable/ic_tools_history" |
||||
app:layout_constraintHorizontal_bias="0" |
||||
android:layout_marginHorizontal="15dp" |
||||
app:layout_constraintHorizontal_chainStyle="packed" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintRight_toLeftOf="@+id/tv_tools" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent"/> |
||||
|
||||
|
||||
<TextView |
||||
android:id="@+id/tv_tools" |
||||
android:layout_width="wrap_content" |
||||
android:layout_height="wrap_content" |
||||
tools:text="常用工具" |
||||
android:textSize="13sp" |
||||
android:textColor="@color/primaryText" |
||||
app:layout_constraintLeft_toRightOf="@+id/iv_tools" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
app:layout_constraintBottom_toBottomOf="parent"/> |
||||
|
||||
|
||||
<ImageView |
||||
android:layout_width="15dp" |
||||
android:layout_height="15dp" |
||||
android:src="@drawable/ic_arrow_right" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:layout_constraintTop_toTopOf="parent" |
||||
android:layout_marginEnd="15dp" |
||||
app:layout_constraintBottom_toBottomOf="parent"/> |
||||
|
||||
<View android:layout_width="0dp" |
||||
android:layout_height="0.5dp" |
||||
app:layout_constraintLeft_toLeftOf="parent" |
||||
app:layout_constraintRight_toRightOf="parent" |
||||
app:layout_constraintBottom_toBottomOf="parent" |
||||
android:background="@color/bg_divider_line"/> |
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading…
Reference in new issue