From 13587dafb6838a8c9b5aeb1a6b7cd20b61f81bad Mon Sep 17 00:00:00 2001 From: kunfei Date: Mon, 28 Oct 2019 14:06:22 +0800 Subject: [PATCH] up --- .../app/base/adapter/CommonRecyclerAdapter.kt | 8 +- .../legado/app/base/adapter/ItemAnimation.kt | 6 +- .../app/ui/book/search/SearchActivity.kt | 9 +- .../app/ui/book/search/SearchAdapter.kt | 136 ++++++++---------- .../app/ui/main/bookshelf/BooksAdapter.kt | 1 + 5 files changed, 77 insertions(+), 83 deletions(-) diff --git a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt index 97073009f..679ba6f89 100644 --- a/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt +++ b/app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt @@ -401,9 +401,11 @@ abstract class CommonRecyclerAdapter(protected val context: Context) : Rec protected open fun startAnimation(holder: ItemViewHolder, item: ItemAnimation) { - for (anim in item.itemAnimation.getAnimators(holder.itemView)) { - anim.setDuration(item.itemAnimDuration).start() - anim.interpolator = item.itemAnimInterpolator + item.itemAnimation?.let { + for (anim in it.getAnimators(holder.itemView)) { + anim.setDuration(item.itemAnimDuration).start() + anim.interpolator = item.itemAnimInterpolator + } } } diff --git a/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt b/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt index cf2f40305..a7cc3cdb3 100644 --- a/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt +++ b/app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt @@ -11,7 +11,7 @@ class ItemAnimation private constructor() { var itemAnimEnabled = false var itemAnimFirstOnly = true - var itemAnimation: BaseAnimation = SlideInBottomAnimation() + var itemAnimation: BaseAnimation? = null var itemAnimInterpolator: Interpolator = LinearInterpolator() var itemAnimDuration: Long = 300L var itemAnimStartPosition: Int = -1 @@ -31,7 +31,7 @@ class ItemAnimation private constructor() { return this } - fun animation(animationType: Int = FADE_IN, animation: BaseAnimation? = null): ItemAnimation { + fun animation(animationType: Int = NONE, animation: BaseAnimation? = null): ItemAnimation { if (animation != null) { itemAnimation = animation } else { @@ -57,7 +57,7 @@ class ItemAnimation private constructor() { } companion object { - + const val NONE: Int = 0x00000000 /** * Use with [.openLoadAnimation] */ diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt index 4ca8d948b..f64daa72f 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt @@ -21,6 +21,7 @@ import io.legado.app.lib.theme.ATH import io.legado.app.lib.theme.primaryTextColor import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.source.manage.BookSourceActivity +import io.legado.app.ui.widget.LoadMoreView import io.legado.app.utils.* import kotlinx.android.synthetic.main.activity_book_search.* import kotlinx.android.synthetic.main.view_search.* @@ -41,6 +42,7 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se private lateinit var adapter: SearchAdapter private lateinit var bookAdapter: BookAdapter private lateinit var historyKeyAdapter: HistoryKeyAdapter + private lateinit var loadMoreView: LoadMoreView private var searchBookData: LiveData>? = null private var historyData: LiveData>? = null private var bookData: LiveData>? = null @@ -133,9 +135,10 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se historyKeyAdapter = HistoryKeyAdapter(this, this) rv_history_key.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false) rv_history_key.adapter = historyKeyAdapter - adapter = SearchAdapter(this) + adapter = SearchAdapter(this, this) recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.adapter = adapter + loadMoreView = LoadMoreView(this) } private fun initOtherView() { @@ -154,7 +157,9 @@ class SearchActivity : VMBaseActivity(R.layout.activity_book_se viewModel.startTime ), 30 ).build() - searchBookData?.observe(this, Observer { adapter.submitList(it) }) + searchBookData?.observe(this, Observer { + //ToDo + }) App.db.bookSourceDao().liveGroupEnabled().observe(this, Observer { groups.clear() it.map { group -> diff --git a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt index 38974157d..33c9ae637 100644 --- a/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt @@ -1,11 +1,10 @@ package io.legado.app.ui.book.search -import android.view.LayoutInflater +import android.content.Context import android.view.View -import android.view.ViewGroup -import androidx.paging.PagedListAdapter -import androidx.recyclerview.widget.RecyclerView import io.legado.app.R +import io.legado.app.base.adapter.ItemViewHolder +import io.legado.app.base.adapter.SimpleRecyclerAdapter import io.legado.app.data.entities.SearchShow import io.legado.app.help.ImageLoader import io.legado.app.utils.gone @@ -15,33 +14,19 @@ import kotlinx.android.synthetic.main.item_bookshelf_list.view.tv_name import kotlinx.android.synthetic.main.item_search.view.* import org.jetbrains.anko.sdk27.listeners.onClick -class SearchAdapter(val callBack: CallBack) : - PagedListAdapter(DiffCallBack()) { +class SearchAdapter(context: Context, val callBack: CallBack) : + SimpleRecyclerAdapter(context, R.layout.item_search) { - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { - return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_search, parent, false)) - } - - override fun onBindViewHolder(holder: MyViewHolder, position: Int, payloads: MutableList) { + override fun convert(holder: ItemViewHolder, item: SearchShow, payloads: MutableList) { if (payloads.isEmpty()) { - super.onBindViewHolder(holder, position, payloads) + bind(holder.itemView, item) } else { - getItem(position)?.let { - holder.bindChange(it, payloads) - } + bindChange(holder.itemView, item, payloads) } } - override fun onBindViewHolder(holder: MyViewHolder, position: Int) { - getItem(position)?.let { - holder.bind(it, callBack) - } - } - - - class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { - - fun bind(searchBook: SearchShow, callBack: CallBack?) = with(itemView) { + private fun bind(itemView: View, searchBook: SearchShow) { + with(itemView) { tv_name.text = searchBook.name tv_author.text = context.getString(R.string.author_show, searchBook.author) bv_originCount.setBadgeCount(searchBook.originCount) @@ -90,68 +75,69 @@ class SearchAdapter(val callBack: CallBack) : .setAsDrawable(iv_cover) } onClick { - callBack?.showBookInfo(searchBook.name, searchBook.author) + callBack.showBookInfo(searchBook.name, searchBook.author) } } + } - fun bindChange(searchBook: SearchShow, payloads: MutableList) = - with(itemView) { - when (payloads[0]) { - 1 -> bv_originCount.setBadgeCount(searchBook.originCount) - 2 -> searchBook.coverUrl.let { - ImageLoader.load(context, it)//Glide自动识别http://和file:// - .placeholder(R.drawable.image_cover_default) - .error(R.drawable.image_cover_default) - .centerCrop() - .setAsDrawable(iv_cover) - } - 3 -> { - val kinds = searchBook.getKindList() - if (kinds.isEmpty()) { - ll_kind.gone() - } else { - ll_kind.visible() - for (index in 0..2) { - if (kinds.size > index) { - when (index) { - 0 -> { - tv_kind.text = kinds[index] - tv_kind.visible() - } - 1 -> { - tv_kind_1.text = kinds[index] - tv_kind_1.visible() - } - 2 -> { - tv_kind_2.text = kinds[index] - tv_kind_2.visible() - } + private fun bindChange(itemView: View, searchBook: SearchShow, payloads: MutableList) { + with(itemView) { + when (payloads[0]) { + 1 -> bv_originCount.setBadgeCount(searchBook.originCount) + 2 -> searchBook.coverUrl.let { + ImageLoader.load(context, it)//Glide自动识别http://和file:// + .placeholder(R.drawable.image_cover_default) + .error(R.drawable.image_cover_default) + .centerCrop() + .setAsDrawable(iv_cover) + } + 3 -> { + val kinds = searchBook.getKindList() + if (kinds.isEmpty()) { + ll_kind.gone() + } else { + ll_kind.visible() + for (index in 0..2) { + if (kinds.size > index) { + when (index) { + 0 -> { + tv_kind.text = kinds[index] + tv_kind.visible() } - } else { - when (index) { - 0 -> tv_kind.gone() - 1 -> tv_kind_1.gone() - 2 -> tv_kind_2.gone() + 1 -> { + tv_kind_1.text = kinds[index] + tv_kind_1.visible() } + 2 -> { + tv_kind_2.text = kinds[index] + tv_kind_2.visible() + } + } + } else { + when (index) { + 0 -> tv_kind.gone() + 1 -> tv_kind_1.gone() + 2 -> tv_kind_2.gone() } } } } - 4 -> { - if (searchBook.latestChapterTitle.isNullOrEmpty()) { - tv_lasted.gone() - } else { - tv_lasted.text = context.getString( - R.string.lasted_show, - searchBook.latestChapterTitle - ) - tv_lasted.visible() - } + } + 4 -> { + if (searchBook.latestChapterTitle.isNullOrEmpty()) { + tv_lasted.gone() + } else { + tv_lasted.text = context.getString( + R.string.lasted_show, + searchBook.latestChapterTitle + ) + tv_lasted.visible() } - 5 -> tv_introduce.text = - context.getString(R.string.intro_show, searchBook.intro) } + 5 -> tv_introduce.text = + context.getString(R.string.intro_show, searchBook.intro) } + } } interface CallBack { diff --git a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt index 9b3ec6530..bede42760 100644 --- a/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt +++ b/app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt @@ -17,6 +17,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick class BooksAdapter(context: Context, private val callBack: CallBack) : SimpleRecyclerAdapter(context, R.layout.item_bookshelf_list) { + override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList) = with(holder.itemView) { if (payloads.isEmpty()) {