pull/43/head
kunfei 5 years ago
parent 0ad4439b0f
commit 13587dafb6
  1. 4
      app/src/main/java/io/legado/app/base/adapter/CommonRecyclerAdapter.kt
  2. 6
      app/src/main/java/io/legado/app/base/adapter/ItemAnimation.kt
  3. 9
      app/src/main/java/io/legado/app/ui/book/search/SearchActivity.kt
  4. 40
      app/src/main/java/io/legado/app/ui/book/search/SearchAdapter.kt
  5. 1
      app/src/main/java/io/legado/app/ui/main/bookshelf/BooksAdapter.kt

@ -401,11 +401,13 @@ abstract class CommonRecyclerAdapter<ITEM>(protected val context: Context) : Rec
protected open fun startAnimation(holder: ItemViewHolder, item: ItemAnimation) { protected open fun startAnimation(holder: ItemViewHolder, item: ItemAnimation) {
for (anim in item.itemAnimation.getAnimators(holder.itemView)) { item.itemAnimation?.let {
for (anim in it.getAnimators(holder.itemView)) {
anim.setDuration(item.itemAnimDuration).start() anim.setDuration(item.itemAnimDuration).start()
anim.interpolator = item.itemAnimInterpolator anim.interpolator = item.itemAnimInterpolator
} }
} }
}
companion object { companion object {
private const val TYPE_HEADER_VIEW = Int.MIN_VALUE private const val TYPE_HEADER_VIEW = Int.MIN_VALUE

@ -11,7 +11,7 @@ class ItemAnimation private constructor() {
var itemAnimEnabled = false var itemAnimEnabled = false
var itemAnimFirstOnly = true var itemAnimFirstOnly = true
var itemAnimation: BaseAnimation = SlideInBottomAnimation() var itemAnimation: BaseAnimation? = null
var itemAnimInterpolator: Interpolator = LinearInterpolator() var itemAnimInterpolator: Interpolator = LinearInterpolator()
var itemAnimDuration: Long = 300L var itemAnimDuration: Long = 300L
var itemAnimStartPosition: Int = -1 var itemAnimStartPosition: Int = -1
@ -31,7 +31,7 @@ class ItemAnimation private constructor() {
return this return this
} }
fun animation(animationType: Int = FADE_IN, animation: BaseAnimation? = null): ItemAnimation { fun animation(animationType: Int = NONE, animation: BaseAnimation? = null): ItemAnimation {
if (animation != null) { if (animation != null) {
itemAnimation = animation itemAnimation = animation
} else { } else {
@ -57,7 +57,7 @@ class ItemAnimation private constructor() {
} }
companion object { companion object {
const val NONE: Int = 0x00000000
/** /**
* Use with [.openLoadAnimation] * Use with [.openLoadAnimation]
*/ */

@ -21,6 +21,7 @@ import io.legado.app.lib.theme.ATH
import io.legado.app.lib.theme.primaryTextColor import io.legado.app.lib.theme.primaryTextColor
import io.legado.app.ui.book.info.BookInfoActivity import io.legado.app.ui.book.info.BookInfoActivity
import io.legado.app.ui.book.source.manage.BookSourceActivity import io.legado.app.ui.book.source.manage.BookSourceActivity
import io.legado.app.ui.widget.LoadMoreView
import io.legado.app.utils.* import io.legado.app.utils.*
import kotlinx.android.synthetic.main.activity_book_search.* import kotlinx.android.synthetic.main.activity_book_search.*
import kotlinx.android.synthetic.main.view_search.* import kotlinx.android.synthetic.main.view_search.*
@ -41,6 +42,7 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
private lateinit var adapter: SearchAdapter private lateinit var adapter: SearchAdapter
private lateinit var bookAdapter: BookAdapter private lateinit var bookAdapter: BookAdapter
private lateinit var historyKeyAdapter: HistoryKeyAdapter private lateinit var historyKeyAdapter: HistoryKeyAdapter
private lateinit var loadMoreView: LoadMoreView
private var searchBookData: LiveData<PagedList<SearchShow>>? = null private var searchBookData: LiveData<PagedList<SearchShow>>? = null
private var historyData: LiveData<List<SearchKeyword>>? = null private var historyData: LiveData<List<SearchKeyword>>? = null
private var bookData: LiveData<List<Book>>? = null private var bookData: LiveData<List<Book>>? = null
@ -133,9 +135,10 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
historyKeyAdapter = HistoryKeyAdapter(this, this) historyKeyAdapter = HistoryKeyAdapter(this, this)
rv_history_key.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false) rv_history_key.layoutManager = LinearLayoutManager(this, RecyclerView.HORIZONTAL, false)
rv_history_key.adapter = historyKeyAdapter rv_history_key.adapter = historyKeyAdapter
adapter = SearchAdapter(this) adapter = SearchAdapter(this, this)
recycler_view.layoutManager = LinearLayoutManager(this) recycler_view.layoutManager = LinearLayoutManager(this)
recycler_view.adapter = adapter recycler_view.adapter = adapter
loadMoreView = LoadMoreView(this)
} }
private fun initOtherView() { private fun initOtherView() {
@ -154,7 +157,9 @@ class SearchActivity : VMBaseActivity<SearchViewModel>(R.layout.activity_book_se
viewModel.startTime viewModel.startTime
), 30 ), 30
).build() ).build()
searchBookData?.observe(this, Observer { adapter.submitList(it) }) searchBookData?.observe(this, Observer {
//ToDo
})
App.db.bookSourceDao().liveGroupEnabled().observe(this, Observer { App.db.bookSourceDao().liveGroupEnabled().observe(this, Observer {
groups.clear() groups.clear()
it.map { group -> it.map { group ->

@ -1,11 +1,10 @@
package io.legado.app.ui.book.search package io.legado.app.ui.book.search
import android.view.LayoutInflater import android.content.Context
import android.view.View 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.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.data.entities.SearchShow
import io.legado.app.help.ImageLoader import io.legado.app.help.ImageLoader
import io.legado.app.utils.gone 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 kotlinx.android.synthetic.main.item_search.view.*
import org.jetbrains.anko.sdk27.listeners.onClick import org.jetbrains.anko.sdk27.listeners.onClick
class SearchAdapter(val callBack: CallBack) : class SearchAdapter(context: Context, val callBack: CallBack) :
PagedListAdapter<SearchShow, SearchAdapter.MyViewHolder>(DiffCallBack()) { SimpleRecyclerAdapter<SearchShow>(context, R.layout.item_search) {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder { override fun convert(holder: ItemViewHolder, item: SearchShow, payloads: MutableList<Any>) {
return MyViewHolder(LayoutInflater.from(parent.context).inflate(R.layout.item_search, parent, false))
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int, payloads: MutableList<Any>) {
if (payloads.isEmpty()) { if (payloads.isEmpty()) {
super.onBindViewHolder(holder, position, payloads) bind(holder.itemView, item)
} else { } else {
getItem(position)?.let { bindChange(holder.itemView, item, payloads)
holder.bindChange(it, payloads)
}
}
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
getItem(position)?.let {
holder.bind(it, callBack)
} }
} }
private fun bind(itemView: View, searchBook: SearchShow) {
class MyViewHolder(view: View) : RecyclerView.ViewHolder(view) { with(itemView) {
fun bind(searchBook: SearchShow, callBack: CallBack?) = with(itemView) {
tv_name.text = searchBook.name tv_name.text = searchBook.name
tv_author.text = context.getString(R.string.author_show, searchBook.author) tv_author.text = context.getString(R.string.author_show, searchBook.author)
bv_originCount.setBadgeCount(searchBook.originCount) bv_originCount.setBadgeCount(searchBook.originCount)
@ -90,11 +75,12 @@ class SearchAdapter(val callBack: CallBack) :
.setAsDrawable(iv_cover) .setAsDrawable(iv_cover)
} }
onClick { onClick {
callBack?.showBookInfo(searchBook.name, searchBook.author) callBack.showBookInfo(searchBook.name, searchBook.author)
}
} }
} }
fun bindChange(searchBook: SearchShow, payloads: MutableList<Any>) = private fun bindChange(itemView: View, searchBook: SearchShow, payloads: MutableList<Any>) {
with(itemView) { with(itemView) {
when (payloads[0]) { when (payloads[0]) {
1 -> bv_originCount.setBadgeCount(searchBook.originCount) 1 -> bv_originCount.setBadgeCount(searchBook.originCount)

@ -17,6 +17,7 @@ import org.jetbrains.anko.sdk27.listeners.onLongClick
class BooksAdapter(context: Context, private val callBack: CallBack) : class BooksAdapter(context: Context, private val callBack: CallBack) :
SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) { SimpleRecyclerAdapter<Book>(context, R.layout.item_bookshelf_list) {
override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) = override fun convert(holder: ItemViewHolder, item: Book, payloads: MutableList<Any>) =
with(holder.itemView) { with(holder.itemView) {
if (payloads.isEmpty()) { if (payloads.isEmpty()) {

Loading…
Cancel
Save