|
|
@ -9,18 +9,18 @@ import android.widget.ImageView |
|
|
|
import android.widget.TextView |
|
|
|
import android.widget.TextView |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
import androidx.recyclerview.widget.RecyclerView |
|
|
|
|
|
|
|
|
|
|
|
import com.novel.read.R |
|
|
|
import com.novel.read.R |
|
|
|
import com.novel.read.activity.NovelBookDetailActivity |
|
|
|
import com.novel.read.activity.NovelBookDetailActivity |
|
|
|
import com.novel.read.adapter.holder.EmptyHolder |
|
|
|
import com.novel.read.adapter.holder.EmptyHolder |
|
|
|
import com.novel.read.adapter.holder.MoreHolder |
|
|
|
import com.novel.read.adapter.holder.MoreHolder |
|
|
|
import com.novel.read.constants.Constant |
|
|
|
import com.novel.read.constants.Constant |
|
|
|
|
|
|
|
import com.novel.read.constants.Constant.COMMENT_SIZE |
|
|
|
import com.novel.read.inter.OnLoadMoreListener |
|
|
|
import com.novel.read.inter.OnLoadMoreListener |
|
|
|
import com.novel.read.model.protocol.SearchResp |
|
|
|
import com.novel.read.model.protocol.SearchResp |
|
|
|
import com.novel.read.utlis.GlideImageLoader |
|
|
|
import com.novel.read.utlis.GlideImageLoader |
|
|
|
import com.novel.read.constants.Constant.COMMENT_SIZE |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: RecyclerView) : RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: RecyclerView) : |
|
|
|
|
|
|
|
RecyclerView.Adapter<RecyclerView.ViewHolder>() { |
|
|
|
|
|
|
|
|
|
|
|
private var mContext: Context? = null |
|
|
|
private var mContext: Context? = null |
|
|
|
|
|
|
|
|
|
|
@ -35,12 +35,12 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: |
|
|
|
|
|
|
|
|
|
|
|
init { |
|
|
|
init { |
|
|
|
if (recyclerView.layoutManager is LinearLayoutManager) { |
|
|
|
if (recyclerView.layoutManager is LinearLayoutManager) { |
|
|
|
val llMangager = recyclerView.layoutManager as LinearLayoutManager? |
|
|
|
val manager = recyclerView.layoutManager as LinearLayoutManager? |
|
|
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { |
|
|
|
recyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() { |
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { |
|
|
|
override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { |
|
|
|
super.onScrolled(recyclerView, dx, dy) |
|
|
|
super.onScrolled(recyclerView, dx, dy) |
|
|
|
totalItemCount = llMangager!!.itemCount |
|
|
|
totalItemCount = manager!!.itemCount |
|
|
|
lastVisibleItem = llMangager.findLastVisibleItemPosition() |
|
|
|
lastVisibleItem = manager.findLastVisibleItemPosition() |
|
|
|
if (!isLoadingMore && totalItemCount == lastVisibleItem + visibleThreshold && totalItemCount >= COMMENT_SIZE) { |
|
|
|
if (!isLoadingMore && totalItemCount == lastVisibleItem + visibleThreshold && totalItemCount >= COMMENT_SIZE) { |
|
|
|
if (mOnLoadMoreListener != null) { |
|
|
|
if (mOnLoadMoreListener != null) { |
|
|
|
mOnLoadMoreListener!!.onLoadMore() |
|
|
|
mOnLoadMoreListener!!.onLoadMore() |
|
|
@ -63,19 +63,23 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: |
|
|
|
val view: View |
|
|
|
val view: View |
|
|
|
when (i) { |
|
|
|
when (i) { |
|
|
|
VALUE_ITEM -> { |
|
|
|
VALUE_ITEM -> { |
|
|
|
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_item_search, viewGroup, false) |
|
|
|
view = LayoutInflater.from(mContext) |
|
|
|
|
|
|
|
.inflate(R.layout.rlv_item_search, viewGroup, false) |
|
|
|
return ViewHolder(view) |
|
|
|
return ViewHolder(view) |
|
|
|
} |
|
|
|
} |
|
|
|
BOOK_ITEM -> { |
|
|
|
BOOK_ITEM -> { |
|
|
|
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_item_book_list_search, viewGroup, false) |
|
|
|
view = LayoutInflater.from(mContext) |
|
|
|
|
|
|
|
.inflate(R.layout.rlv_item_book_list_search, viewGroup, false) |
|
|
|
return BookHolder(view) |
|
|
|
return BookHolder(view) |
|
|
|
} |
|
|
|
} |
|
|
|
EMPTY_ITEM -> { |
|
|
|
EMPTY_ITEM -> { |
|
|
|
view = LayoutInflater.from(mContext).inflate(R.layout.rlv_empty_view, viewGroup, false) |
|
|
|
view = |
|
|
|
|
|
|
|
LayoutInflater.from(mContext).inflate(R.layout.rlv_empty_view, viewGroup, false) |
|
|
|
return EmptyHolder(view) |
|
|
|
return EmptyHolder(view) |
|
|
|
} |
|
|
|
} |
|
|
|
PROCESS_ITEM -> { |
|
|
|
PROCESS_ITEM -> { |
|
|
|
view = LayoutInflater.from(mContext).inflate(R.layout.load_more_layout, viewGroup, false) |
|
|
|
view = LayoutInflater.from(mContext) |
|
|
|
|
|
|
|
.inflate(R.layout.load_more_layout, viewGroup, false) |
|
|
|
return MoreHolder(view) |
|
|
|
return MoreHolder(view) |
|
|
|
} |
|
|
|
} |
|
|
|
else -> throw IllegalArgumentException() |
|
|
|
else -> throw IllegalArgumentException() |
|
|
@ -87,7 +91,12 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: |
|
|
|
is ViewHolder -> { |
|
|
|
is ViewHolder -> { |
|
|
|
val bookBean = mList[i] |
|
|
|
val bookBean = mList[i] |
|
|
|
viewHolder.mTvBookName.text = bookBean.title |
|
|
|
viewHolder.mTvBookName.text = bookBean.title |
|
|
|
viewHolder.itemView.setOnClickListener { view -> mClickListener!!.onItemClick(view, i) } |
|
|
|
viewHolder.itemView.setOnClickListener { view -> |
|
|
|
|
|
|
|
mClickListener!!.onItemClick( |
|
|
|
|
|
|
|
view, |
|
|
|
|
|
|
|
i |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
is BookHolder -> { |
|
|
|
is BookHolder -> { |
|
|
|
val bookBean = mList[i] |
|
|
|
val bookBean = mList[i] |
|
|
@ -112,7 +121,7 @@ class SearchAdapter(private val mList: List<SearchResp.BookBean>, recyclerView: |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun getItemViewType(position: Int): Int { |
|
|
|
override fun getItemViewType(position: Int): Int { |
|
|
|
if (position == itemCount - 1) { |
|
|
|
if (mList.isNotEmpty() && position == itemCount - 1) { |
|
|
|
return PROCESS_ITEM |
|
|
|
return PROCESS_ITEM |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|