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 |
package com.novel.read.base |
||||||
|
|
||||||
import androidx.lifecycle.ViewModel |
import androidx.lifecycle.ViewModel |
||||||
|
import androidx.viewbinding.ViewBinding |
||||||
import com.novel.read.constant.Theme |
import com.novel.read.constant.Theme |
||||||
|
|
||||||
abstract class VMBaseActivity<VM : ViewModel>( |
abstract class VMBaseActivity<VB : ViewBinding,VM : ViewModel>( |
||||||
layoutID: Int, |
|
||||||
fullScreen: Boolean = true, |
fullScreen: Boolean = true, |
||||||
theme: Theme = Theme.Auto, |
theme: Theme = Theme.Auto, |
||||||
toolBarTheme: Theme = Theme.Auto |
toolBarTheme: Theme = Theme.Auto |
||||||
) : BaseActivity(layoutID, fullScreen, theme, toolBarTheme) { |
) : BaseActivity<VB>(fullScreen, theme, toolBarTheme) { |
||||||
|
|
||||||
protected abstract val viewModel: VM |
protected abstract val viewModel: VM |
||||||
|
|
||||||
|
@ -1,28 +1,41 @@ |
|||||||
package com.novel.read.ui.channel |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.module.LoadMoreModule |
import com.chad.library.adapter.base.module.LoadMoreModule |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.data.model.BookListResp |
||||||
|
import com.novel.read.databinding.ItemBookCommonBinding |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
|
||||||
class ChannelInfoAdapter : |
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 { |
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 { |
onClick { |
||||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
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 |
package com.novel.read.ui.chapter |
||||||
|
|
||||||
import com.chad.library.adapter.base.BaseQuickAdapter |
import android.view.LayoutInflater |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
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.Bookmark |
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) { |
override fun convert(holder: VBViewHolder<ItemBookmarkBinding>, item: Bookmark) { |
||||||
holder.itemView.run { |
holder.vb.run { |
||||||
tv_chapter_name.text = item.chapterName |
tvChapterName.text = item.chapterName |
||||||
tv_content.text = item.content |
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 |
package com.novel.read.ui.chapter |
||||||
|
|
||||||
import android.view.View |
import android.view.LayoutInflater |
||||||
import com.chad.library.adapter.base.BaseQuickAdapter |
import android.view.ViewGroup |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
|
||||||
import com.novel.read.R |
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.data.db.entity.BookChapter |
||||||
|
import com.novel.read.databinding.ItemChapterListBinding |
||||||
import com.novel.read.help.BookHelp |
import com.novel.read.help.BookHelp |
||||||
import com.novel.read.utils.ext.* |
import com.novel.read.utils.ext.* |
||||||
import kotlinx.android.synthetic.main.item_chapter_list.view.* |
|
||||||
|
|
||||||
class ChapterListAdapter(val callback: Callback) : |
class ChapterListAdapter(val callback: Callback) : |
||||||
BaseQuickAdapter<BookChapter, BaseViewHolder>(R.layout.item_chapter_list) { |
BaseBindingAdapter<BookChapter, ItemChapterListBinding>() { |
||||||
|
|
||||||
val cacheFileNames = hashSetOf<String>() |
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 isDur = callback.durChapterIndex() == item.chapterIndex |
||||||
val cached = callback.isLocalBook |
val cached = callback.isLocalBook |
||||||
|| cacheFileNames.contains(BookHelp.formatChapterName(item)) |
|| cacheFileNames.contains(BookHelp.formatChapterName(item)) |
||||||
if (isDur) { |
if (isDur) { |
||||||
tv_chapter_name.setTextColor(context.accentColor) |
tvChapterName.setTextColor(context.accentColor) |
||||||
} else { |
} 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()) { |
if (!item.updateDate.isNullOrEmpty()) { |
||||||
tv_tag.text = item.updateDate |
tvTag.text = item.updateDate |
||||||
tv_tag.visible() |
tvTag.visible() |
||||||
} |
} |
||||||
upHasCache(this, isDur, cached) |
upHasCache(this, isDur, cached) |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
holder.itemView.run { |
||||||
setOnClickListener { |
setOnClickListener { |
||||||
getItem(holder.layoutPosition)?.let { |
getItem(holder.layoutPosition).let { |
||||||
callback.openChapter(it) |
callback.openChapter(it) |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
private fun upHasCache(itemView: View, isDur: Boolean, cached: Boolean) = itemView.apply { |
private fun upHasCache(itemView: ItemChapterListBinding, isDur: Boolean, cached: Boolean) = itemView.run { |
||||||
tv_chapter_name.paint.isFakeBoldText = cached |
tvChapterName.paint.isFakeBoldText = cached |
||||||
iv_checked.setImageResource(R.drawable.ic_outline_cloud_24) |
ivChecked.setImageResource(R.drawable.ic_outline_cloud_24) |
||||||
iv_checked.visible(!cached) |
ivChecked.visible(!cached) |
||||||
if (isDur) { |
if (isDur) { |
||||||
iv_checked.setImageResource(R.drawable.ic_check) |
ivChecked.setImageResource(R.drawable.ic_check) |
||||||
iv_checked.visible() |
ivChecked.visible() |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
override fun createViewBinding( |
||||||
|
inflater: LayoutInflater, |
||||||
|
parent: ViewGroup |
||||||
|
): ItemChapterListBinding { |
||||||
|
return ItemChapterListBinding.inflate(inflater,parent,false) |
||||||
|
} |
||||||
|
|
||||||
interface Callback { |
interface Callback { |
||||||
val isLocalBook: Boolean |
val isLocalBook: Boolean |
||||||
fun openChapter(bookChapter: BookChapter) |
fun openChapter(bookChapter: BookChapter) |
||||||
fun durChapterIndex(): Int |
fun durChapterIndex(): Int |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
@ -1,28 +1,37 @@ |
|||||||
package com.novel.read.ui.daily |
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.module.LoadMoreModule |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
|
||||||
import com.novel.read.R |
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.data.model.BookListResp |
||||||
|
import com.novel.read.databinding.ItemBookCommonBinding |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
|
||||||
class DailyAdapter : |
class DailyAdapter : |
||||||
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 { |
holder.itemView.onClick { |
||||||
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) |
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 |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.module.LoadMoreModule |
import com.chad.library.adapter.base.module.LoadMoreModule |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.data.model.BookListResp |
||||||
|
import com.novel.read.databinding.ItemBookCommonBinding |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
|
||||||
class EndAdapter : |
class EndAdapter : |
||||||
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 { |
holder.itemView.onClick { |
||||||
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) |
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 |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.data.model.BookListResp |
||||||
|
import com.novel.read.databinding.ItemHotItemBinding |
||||||
import com.novel.read.lib.ATH |
import com.novel.read.lib.ATH |
||||||
import kotlinx.android.synthetic.main.item_hot_item.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
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 { |
holder.itemView.run { |
||||||
ATH.applyBackgroundTint(this) |
ATH.applyBackgroundTint(this) |
||||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
|
||||||
tv_name.text = item.getBBookName() |
|
||||||
onClick { |
onClick { |
||||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
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 |
package com.novel.read.ui.main.bookshelf |
||||||
|
|
||||||
import android.os.Bundle |
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.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.constant.BookType |
||||||
import com.novel.read.data.db.entity.Book |
import com.novel.read.data.db.entity.Book |
||||||
|
import com.novel.read.databinding.ItemBookshelfListBinding |
||||||
import com.novel.read.lib.ATH |
import com.novel.read.lib.ATH |
||||||
import com.novel.read.utils.ext.* |
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) { |
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>) { |
override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) { |
||||||
super.convert(holder, item, payloads) |
super.convert(holder, item, payloads) |
||||||
val bundle = payloads.getOrNull(0) as? Bundle |
val bundle = payloads.getOrNull(0) as? Bundle |
||||||
holder.itemView.run { |
|
||||||
ATH.applyBackgroundTint(this) |
holder.getViewBinding<ItemBookshelfListBinding>().apply { |
||||||
if (bundle == null) { |
if (bundle == null) { |
||||||
tv_name.text = item.bookName |
tvName.text = item.bookName |
||||||
tv_author.text = item.authorPenname |
tvAuthor.text = item.authorPenname |
||||||
tv_read.text = item.durChapterTitle |
tvRead.text = item.durChapterTitle |
||||||
tv_last.text = item.keyWord |
tvLast.text = item.keyWord |
||||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||||
upRefresh(holder, item) |
upRefresh(this, item) |
||||||
} else { |
} else { |
||||||
tv_read.text = item.durChapterTitle |
tvRead.text = item.durChapterTitle |
||||||
tv_last.text = item.keyWord |
tvLast.text = item.keyWord |
||||||
bundle.keySet().forEach { |
bundle.keySet().forEach { |
||||||
when (it) { |
when (it) { |
||||||
"name" -> tv_name.text = item.bookName |
"name" -> tvName.text = item.bookName |
||||||
"author" -> tv_author.text = item.authorPenname |
"author" -> tvAuthor.text = item.authorPenname |
||||||
"cover" -> iv_cover.load( |
"cover" -> ivCover.load( |
||||||
item.coverImageUrl, |
item.coverImageUrl, |
||||||
item.bookName, |
item.bookName, |
||||||
item.authorPenname |
item.authorPenname |
||||||
) |
) |
||||||
"refresh" -> upRefresh(holder, item) |
"refresh" -> upRefresh(this, item) |
||||||
|
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
holder.itemView.run { |
||||||
|
ATH.applyBackgroundTint(this) |
||||||
|
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
override fun convert(holder: BaseViewHolder, item: Book) { |
override fun convert(holder: BaseViewHolder, item: Book) { |
||||||
holder.itemView.run { |
holder.itemView.run { |
||||||
ATH.applyBackgroundTint(this) |
ATH.applyBackgroundTint(this) |
||||||
tv_name.text = item.bookName |
} |
||||||
tv_author.text = item.authorPenname |
holder.getViewBinding<ItemBookshelfListBinding>().apply { |
||||||
tv_read.text = item.durChapterTitle |
tvName.text = item.bookName |
||||||
tv_last.text = item.keyWord |
tvAuthor.text = item.authorPenname |
||||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
tvRead.text = item.durChapterTitle |
||||||
upRefresh(holder, item) |
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)) { |
if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) { |
||||||
holder.itemView.bv_unread.invisible() |
holder.bvUnread.invisible() |
||||||
holder.itemView.rl_loading.show() |
holder.rlLoading.show() |
||||||
} else { |
} else { |
||||||
holder.itemView.rl_loading.hide() |
holder.rlLoading.hide() |
||||||
holder.itemView.bv_unread.setBadgeCount(0) |
holder.bvUnread.setBadgeCount(0) |
||||||
holder.itemView.bv_unread.setHighlight(true) |
holder.bvUnread.setHighlight(true) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
@ -1,61 +1,71 @@ |
|||||||
package com.novel.read.ui.main.bookshelf |
package com.novel.read.ui.main.bookshelf |
||||||
|
|
||||||
import android.os.Bundle |
import android.os.Bundle |
||||||
|
import android.view.ViewGroup |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.constant.BookType |
||||||
import com.novel.read.data.db.entity.Book |
import com.novel.read.data.db.entity.Book |
||||||
|
import com.novel.read.databinding.ItemBookshelfGridBinding |
||||||
import com.novel.read.lib.ATH |
import com.novel.read.lib.ATH |
||||||
import com.novel.read.utils.ext.invisible |
import com.novel.read.utils.ext.invisible |
||||||
import kotlinx.android.synthetic.main.item_bookshelf_grid.view.* |
|
||||||
|
|
||||||
class BooksAdapterGrid(private val callBack: CallBack) : |
class BooksAdapterGrid(private val callBack: CallBack) : |
||||||
BaseBookAdapter(R.layout.item_bookshelf_grid) { |
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>) { |
override fun convert(holder: BaseViewHolder, item: Book, payloads: List<Any>) { |
||||||
super.convert(holder, item, payloads) |
super.convert(holder, item, payloads) |
||||||
val bundle = payloads.getOrNull(0) as? Bundle |
val bundle = payloads.getOrNull(0) as? Bundle |
||||||
|
holder.getViewBinding<ItemBookshelfGridBinding>().apply{ |
||||||
holder.itemView.run { |
|
||||||
ATH.applyBackgroundTint(this) |
|
||||||
if (bundle == null) { |
if (bundle == null) { |
||||||
tv_name.text = item.bookName |
tvName.text = item.bookName |
||||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
ivCover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||||
upRefresh(holder, item) |
upRefresh(this, item) |
||||||
} else { |
} else { |
||||||
bundle.keySet().forEach { |
bundle.keySet().forEach { |
||||||
when (it) { |
when (it) { |
||||||
"name" -> tv_name.text = item.bookName |
"name" -> tvName.text = item.bookName |
||||||
"cover" -> iv_cover.load( |
"cover" -> ivCover.load( |
||||||
item.coverImageUrl, |
item.coverImageUrl, |
||||||
item.bookName, |
item.bookName, |
||||||
item.authorPenname |
item.authorPenname |
||||||
) |
) |
||||||
"refresh" -> upRefresh(holder, item) |
"refresh" -> upRefresh(this, item) |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
holder.itemView.run { |
||||||
|
ATH.applyBackgroundTint(this) |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
override fun convert(holder: BaseViewHolder, item: Book) { |
override fun convert(holder: BaseViewHolder, item: Book) { |
||||||
holder.itemView.run { |
holder.itemView.run { |
||||||
ATH.applyBackgroundTint(this) |
ATH.applyBackgroundTint(this) |
||||||
tv_name.text = item.bookName |
} |
||||||
iv_cover.load(item.coverImageUrl, item.bookName, item.authorPenname) |
holder.getViewBinding<ItemBookshelfGridBinding>().apply{ |
||||||
upRefresh(holder, item) |
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)) { |
if (item.origin != BookType.local && callBack.isUpdate(item.bookId)) { |
||||||
holder.itemView.bv_unread.invisible() |
holder.bvUnread.invisible() |
||||||
holder.itemView.rl_loading.show() |
holder.rlLoading.show() |
||||||
} else { |
} else { |
||||||
holder.itemView.rl_loading.hide() |
holder.rlLoading.hide() |
||||||
holder.itemView.bv_unread.setBadgeCount(0) |
holder.bvUnread.setBadgeCount(0) |
||||||
holder.itemView.bv_unread.setHighlight(true) |
holder.bvUnread.setHighlight(true) |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
@ -1,36 +1,46 @@ |
|||||||
package com.novel.read.ui.main.bookshelf.arrange |
package com.novel.read.ui.main.bookshelf.arrange |
||||||
|
|
||||||
|
import android.view.LayoutInflater |
||||||
import android.view.View |
import android.view.View |
||||||
import com.chad.library.adapter.base.BaseQuickAdapter |
import android.view.ViewGroup |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.novel.read.base.BaseBindingAdapter |
||||||
import com.novel.read.R |
import com.novel.read.base.VBViewHolder |
||||||
import com.novel.read.data.db.entity.Book |
import com.novel.read.data.db.entity.Book |
||||||
|
import com.novel.read.databinding.ItemArrangeBookBinding |
||||||
import com.novel.read.utils.ext.backgroundColor |
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.backgroundColor |
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
|
||||||
class ArrangeBookAdapter(val callBack: CallBack) : BaseQuickAdapter<Book, BaseViewHolder>(R.layout.item_arrange_book) { |
class ArrangeBookAdapter(val callBack: CallBack) : |
||||||
override fun convert(holder: BaseViewHolder, item: Book) { |
BaseBindingAdapter<Book, ItemArrangeBookBinding>() { |
||||||
holder.itemView.run { |
|
||||||
backgroundColor = context.backgroundColor |
override fun convert(holder: VBViewHolder<ItemArrangeBookBinding>, item: Book) { |
||||||
tv_name.text = item.bookName |
holder.itemView.backgroundColor = context.backgroundColor |
||||||
tv_author.text = item.authorPenname |
holder.vb.run { |
||||||
tv_author.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE |
tvName.text = item.bookName |
||||||
|
tvAuthor.text = item.authorPenname |
||||||
|
tvAuthor.visibility = if (item.authorPenname.isEmpty()) View.GONE else View.VISIBLE |
||||||
// checkbox.isChecked = selectedBooks.contains(item) |
// checkbox.isChecked = selectedBooks.contains(item) |
||||||
iv_book.load(item.coverImageUrl, item.bookName, item.authorPenname) |
ivBook.load(item.coverImageUrl, item.bookName, item.authorPenname) |
||||||
tv_delete.onClick { |
tvDelete.onClick { |
||||||
getItem(holder.layoutPosition)?.let { |
getItem(holder.layoutPosition).let { |
||||||
callBack.deleteBook(it) |
callBack.deleteBook(it) |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
override fun createViewBinding( |
||||||
|
inflater: LayoutInflater, |
||||||
|
parent: ViewGroup |
||||||
|
): ItemArrangeBookBinding { |
||||||
|
return ItemArrangeBookBinding.inflate(inflater, parent, false) |
||||||
|
} |
||||||
|
|
||||||
interface CallBack { |
interface CallBack { |
||||||
fun upSelectCount() |
fun upSelectCount() |
||||||
fun updateBook(vararg book: Book) |
fun updateBook(vararg book: Book) |
||||||
fun deleteBook(book: Book) |
fun deleteBook(book: Book) |
||||||
} |
} |
||||||
|
|
||||||
} |
} |
@ -1,24 +1,35 @@ |
|||||||
package com.novel.read.ui.main.mail.pick |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.data.model.ClickRank |
||||||
|
import com.novel.read.databinding.ItemClickItemBinding |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_click_item.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
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) { |
override fun convert(holder: VBViewHolder<ItemClickItemBinding>, item: ClickRank) { |
||||||
holder.itemView.run { |
holder.vb.run { |
||||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||||
tv_name.text = item.getBBookName() |
tvName.text = item.getBBookName() |
||||||
tv_count.text = context.getString(R.string.book_word, item.wordCount / 10000) |
tvCount.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||||
onClick { |
} |
||||||
|
holder.itemView.onClick { |
||||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
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 |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.data.model.EndRank |
||||||
|
import com.novel.read.databinding.ItemEndItemBinding |
||||||
import com.novel.read.lib.ATH |
import com.novel.read.lib.ATH |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_end_item.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
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 { |
holder.itemView.run { |
||||||
ATH.applyBackgroundTint(this) |
ATH.applyBackgroundTint(this) |
||||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
|
||||||
tv_name.text = item.getBBookName() |
|
||||||
onClick { |
onClick { |
||||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
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 |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.data.model.HotRank |
||||||
|
import com.novel.read.databinding.ItemHotItemBinding |
||||||
import com.novel.read.lib.ATH |
import com.novel.read.lib.ATH |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_hot_item.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
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 { |
holder.itemView.run { |
||||||
ATH.applyBackgroundTint(this) |
ATH.applyBackgroundTint(this) |
||||||
iv_cover.load(item.coverImageUrl, item.getBName(), item.getBAuthor()) |
|
||||||
tv_name.text = item.getBName() |
|
||||||
onClick { |
onClick { |
||||||
BookInfoActivity.actionBookInfo(context,item.bookId,item.bookTypeId) |
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 |
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.os.Bundle |
||||||
import android.view.View |
import android.view.View |
||||||
import com.novel.read.App |
|
||||||
import com.novel.read.R |
import com.novel.read.R |
||||||
import com.novel.read.base.BaseFragment |
import com.novel.read.base.BaseFragment |
||||||
|
import com.novel.read.databinding.FragmentMyBinding |
||||||
import com.novel.read.ui.feedback.FeedBackActivity |
import com.novel.read.ui.feedback.FeedBackActivity |
||||||
import com.novel.read.ui.setting.SettingActivity |
import com.novel.read.ui.setting.SettingActivity |
||||||
import com.novel.read.ui.widget.dialog.AppraiseDialog |
import com.novel.read.ui.widget.dialog.AppraiseDialog |
||||||
import com.novel.read.utils.ext.startActivity |
import com.novel.read.utils.ext.startActivity |
||||||
import com.novel.read.utils.ext.toast |
import com.novel.read.utils.viewbindingdelegate.viewBinding |
||||||
import kotlinx.android.synthetic.main.fragment_my.* |
|
||||||
import kotlinx.android.synthetic.main.view_title_bar.* |
|
||||||
|
|
||||||
class MyFragment : BaseFragment(R.layout.fragment_my) { |
class MyFragment : BaseFragment(R.layout.fragment_my) { |
||||||
|
|
||||||
|
private val binding by viewBinding(FragmentMyBinding::bind) |
||||||
|
|
||||||
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
override fun onFragmentCreated(view: View, savedInstanceState: Bundle?) { |
||||||
setSupportToolbar(toolbar) |
setSupportToolbar(binding.titleBar.toolbar) |
||||||
tv_options.setOnClickListener { |
binding.tvOptions.setOnClickListener { |
||||||
startActivity<FeedBackActivity>() |
startActivity<FeedBackActivity>() |
||||||
} |
} |
||||||
tv_setting.setOnClickListener { |
binding.tvSetting.setOnClickListener { |
||||||
startActivity<SettingActivity>() |
startActivity<SettingActivity>() |
||||||
} |
} |
||||||
tv_appraise.setOnClickListener { |
binding.tvAppraise.setOnClickListener { |
||||||
val dialog = AppraiseDialog(requireActivity()) |
AppraiseDialog().show(childFragmentManager,"AppDialog") |
||||||
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() |
|
||||||
} |
} |
||||||
} |
} |
||||||
|
|
||||||
|
@ -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 |
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.module.LoadMoreModule |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
|
||||||
import com.novel.read.R |
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.data.model.BookListResp |
||||||
|
import com.novel.read.databinding.ItemBookCommonBinding |
||||||
import com.novel.read.ui.info.BookInfoActivity |
import com.novel.read.ui.info.BookInfoActivity |
||||||
import kotlinx.android.synthetic.main.item_book_common.view.* |
|
||||||
import org.jetbrains.anko.sdk27.listeners.onClick |
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
|
||||||
class RankAdapter : |
class RankAdapter : |
||||||
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()) |
holder.vb.run { |
||||||
tv_book_name.text = item.getBBookName() |
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||||
tv_book_description.text = item.getBIntroduction() |
tvBookName.text = item.getBBookName() |
||||||
tv_book_author.text = item.getBAuthorName() |
tvBookDescription.text = item.getBIntroduction() |
||||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
tvBookAuthor.text = item.getBAuthorName() |
||||||
tv_category.text = item.getBCategoryName() |
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||||
onClick { |
tvCategory.text = item.getBCategoryName() |
||||||
|
} |
||||||
|
holder.itemView.onClick { |
||||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
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 |
package com.novel.read.ui.rank |
||||||
|
|
||||||
|
import android.view.LayoutInflater |
||||||
import android.view.View |
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.module.LoadMoreModule |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
|
||||||
import com.novel.read.R |
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 com.novel.read.data.model.TypeName |
||||||
import kotlinx.android.synthetic.main.item_type.view.* |
import com.novel.read.databinding.ItemTypeBinding |
||||||
|
|
||||||
class TypeAdapter : |
class TypeAdapter : |
||||||
BaseQuickAdapter<TypeName, BaseViewHolder>(R.layout.item_type), LoadMoreModule { |
BaseBindingAdapter<TypeName, ItemTypeBinding>(), LoadMoreModule { |
||||||
|
|
||||||
override fun convert(holder: BaseViewHolder, item: TypeName) { |
override fun convert(holder: VBViewHolder<ItemTypeBinding>, item: TypeName) { |
||||||
holder.itemView.run { |
holder.vb.run { |
||||||
tv_type.text = item.name |
tvType.text = item.name |
||||||
if (item.check) { |
if (item.check) { |
||||||
iv_check.visibility = View.VISIBLE |
ivCheck.visibility = View.VISIBLE |
||||||
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background)) |
llBg.setBackgroundColor(context.resources.getColor(R.color.background)) |
||||||
} else { |
} else { |
||||||
iv_check.visibility = View.GONE |
ivCheck.visibility = View.GONE |
||||||
ll_bg.setBackgroundColor(context.resources.getColor(R.color.background_menu)) |
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 |
package com.novel.read.ui.search |
||||||
|
|
||||||
import com.chad.library.adapter.base.BaseQuickAdapter |
import android.view.LayoutInflater |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
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.SearchHistory |
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) { |
override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: SearchHistory) { |
||||||
holder.itemView.run { |
holder.vb.run { |
||||||
tv_label.text = item.getBKey() |
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 |
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.BaseQuickAdapter |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
||||||
import com.novel.read.R |
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.constant.AppConst |
||||||
|
import com.novel.read.databinding.ItemLabelBinding |
||||||
import com.novel.read.utils.StringUtils |
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) { |
override fun convert(holder: VBViewHolder<ItemLabelBinding>, item: String) { |
||||||
holder.itemView.run { |
holder.vb.run { |
||||||
tv_label.text = StringUtils.convertCC(item) |
tvLabel.text = StringUtils.convertCC(item) |
||||||
tv_label.setBackgroundColor(AppConst.tagColors[holder.adapterPosition % 8]) |
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 |
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.module.LoadMoreModule |
||||||
import com.chad.library.adapter.base.viewholder.BaseViewHolder |
|
||||||
import com.novel.read.R |
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.data.model.SearchResp |
||||||
|
import com.novel.read.databinding.ItemBookCommonBinding |
||||||
import com.novel.read.ui.info.BookInfoActivity |
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 |
import org.jetbrains.anko.sdk27.listeners.onClick |
||||||
|
|
||||||
class SearchAdapter : BaseQuickAdapter<SearchResp, BaseViewHolder>(R.layout.item_book_common), |
class SearchAdapter : BaseBindingAdapter<SearchResp, ItemBookCommonBinding>(), |
||||||
LoadMoreModule { |
LoadMoreModule { |
||||||
|
|
||||||
override fun convert(holder: BaseViewHolder, item: SearchResp) { |
override fun convert(holder: VBViewHolder<ItemBookCommonBinding>, item: SearchResp) { |
||||||
holder.itemView.run { |
holder.vb.run { |
||||||
iv_cover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
ivCover.load(item.coverImageUrl, item.getBBookName(), item.getBAuthorName()) |
||||||
tv_book_name.text = item.getBBookName() |
tvBookName.text = item.getBBookName() |
||||||
tv_book_description.text = item.getBIntroduction() |
tvBookDescription.text = item.getBIntroduction() |
||||||
tv_book_author.text = item.getBAuthorName() |
tvBookAuthor.text = item.getBAuthorName() |
||||||
tv_word.text = context.getString(R.string.book_word, item.wordCount / 10000) |
tvWord.text = context.getString(R.string.book_word, item.wordCount / 10000) |
||||||
tv_category.text = item.getBCategoryName() |
tvCategory.text = item.getBCategoryName() |
||||||
onClick { |
|
||||||
|
} |
||||||
|
holder.itemView.onClick { |
||||||
BookInfoActivity.actionBookInfo(context, item.bookId, item.bookTypeId) |
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 |
package com.novel.read.ui.widget.dialog |
||||||
|
|
||||||
import android.app.Dialog |
|
||||||
import android.content.Context |
import android.content.Context |
||||||
|
import android.os.Bundle |
||||||
import android.view.* |
import android.view.* |
||||||
import android.widget.LinearLayout |
|
||||||
import android.widget.TextView |
|
||||||
import com.novel.read.R |
import com.novel.read.R |
||||||
import kotlinx.android.synthetic.main.dialog_go_appraise.* |
import com.novel.read.base.BaseDialogFragment |
||||||
|
import com.novel.read.databinding.DialogGoAppraiseBinding |
||||||
class AppraiseDialog(context: Context) : Dialog(context, R.style.dialog) { |
import com.novel.read.utils.ext.goShop |
||||||
private val view: View = LayoutInflater.from(context).inflate(R.layout.dialog_go_appraise, null) |
import com.novel.read.utils.viewbindingdelegate.viewBinding |
||||||
|
|
||||||
init { |
class AppraiseDialog : BaseDialogFragment() { |
||||||
view.setHasTransientState(true) |
private val binding by viewBinding(DialogGoAppraiseBinding::bind) |
||||||
setContentView( |
|
||||||
view, LinearLayout.LayoutParams( |
override fun onStart() { |
||||||
LinearLayout.LayoutParams.MATCH_PARENT, |
super.onStart() |
||||||
LinearLayout.LayoutParams.MATCH_PARENT |
dialog?.window?.setLayout( |
||||||
|
ViewGroup.LayoutParams.MATCH_PARENT, |
||||||
|
ViewGroup.LayoutParams.WRAP_CONTENT |
||||||
) |
) |
||||||
) |
|
||||||
setCancelable(false) |
|
||||||
initView() |
|
||||||
|
|
||||||
} |
} |
||||||
|
|
||||||
private fun initView() { |
override fun onCreateView( |
||||||
val mTvCancel = findViewById<TextView>(R.id.tv_cancel) |
inflater: LayoutInflater, |
||||||
|
container: ViewGroup?, |
||||||
mTvCancel.setOnClickListener { dismiss() } |
savedInstanceState: Bundle? |
||||||
|
): View? { |
||||||
|
return inflater.inflate(R.layout.dialog_go_appraise, container) |
||||||
} |
} |
||||||
|
|
||||||
fun appraiseDialog(receiveClickListener: View.OnClickListener) { |
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
tv_appraise.setOnClickListener(receiveClickListener) |
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