作者 zhangji

修改我的证据bug

... ... @@ -19,7 +19,7 @@ import java.util.ArrayList
*/
abstract class BaseMultiAdapter<T, VB : ViewBinding> : RecyclerView.Adapter<BaseViewHolder<VB>>() {
protected val list: MutableList<T> = ArrayList()
private var listener: OnItemClickListener<T>? = null
protected var listener: OnItemClickListener<T>? = null
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseViewHolder<VB> {
return BaseViewHolder(
... ... @@ -40,14 +40,10 @@ abstract class BaseMultiAdapter<T, VB : ViewBinding> : RecyclerView.Adapter<Base
): VB
override fun onBindViewHolder(holder: BaseViewHolder<VB>, position: Int) {
if (list.isEmpty()) return
onBind(holder.item, position, list[position])
holder.itemView.setOnClickListener {
listener?.onClick(position, list[position])
}
onBind(holder.item, position)
}
abstract fun onBind(holder: VB, position: Int, data: T)
abstract fun onBind(holder: VB, position: Int)
override fun getItemCount(): Int {
... ...
... ... @@ -19,11 +19,14 @@ import com.br_technology.securitytrain_master.ui.home.pojo.RecommendData
class ResultAdapter : BaseMultiAdapter<RecommendData, ViewBinding>() {
override fun onBind(holder: ViewBinding, position: Int, data: RecommendData) {
override fun onBind(holder: ViewBinding, position: Int) {
if (holder is AdapterRecommendDataBinding) {
holder.pic.glideRound(data.pic, 16)
holder.name.text = data.name
holder.info.text = data.info
holder.pic.glideRound(list[position].pic, 16)
holder.name.text = list[position].name
holder.info.text = list[position].info
holder.root.setOnClickListener {
listener?.onClick(position,list[position])
}
}
}
... ...
package com.br_technology.securitytrain_master.ui.mine.activity
import android.widget.Toast
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.databinding.ActivityMyCredentialsBinding
import com.br_technology.securitytrain_master.expand.addItemDecoration2
import com.br_technology.securitytrain_master.expand.dp2px
import com.br_technology.securitytrain_master.ui.home.activity.TextDetailActivity
import com.br_technology.securitytrain_master.ui.home.adapter.ResultAdapter
import com.br_technology.securitytrain_master.ui.home.pojo.RecommendData
... ... @@ -27,14 +30,32 @@ class MyCredentialsActivity :
override fun initData() {
super.initData()
binding.apply {
recyclerview.addItemDecoration2(2, 8.dp2px(), 16.dp2px())
val recommendList = mutableListOf(
RecommendData(
R.mipmap.my_credentials_upload_bg,
R.mipmap.card_back,
"思维",
"从这个角度"
),
RecommendData(
R.mipmap.card_back,
"思维",
"从这个角度"
),
RecommendData(
R.mipmap.card_back,
"思维",
"从这个角度"
),
)
val myCredentialsAdapter = MyCredentialsAdapter()
myCredentialsAdapter.addListener(object :OnItemClickListener<RecommendData>{
override fun onClick(position: Int, data: RecommendData) {
Toast.makeText(this@MyCredentialsActivity, "aaaaaaaa", Toast.LENGTH_SHORT).show()
}
})
recyclerview.adapter = myCredentialsAdapter
myCredentialsAdapter.addList(recommendList)
}
... ...
... ... @@ -4,6 +4,7 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.br_technology.securitytrain_master.R
import com.br_technology.securitytrain_master.base.view.BaseAdapter
import com.br_technology.securitytrain_master.base.view.BaseMultiAdapter
import com.br_technology.securitytrain_master.base.view.BaseViewHolder
... ... @@ -19,23 +20,48 @@ import com.br_technology.securitytrain_master.ui.home.pojo.VideoCourse
* Author: Captain
* Description: 初见时你很迷人
*/
class MyCredentialsAdapter : BaseAdapter<RecommendData, ItemMyCredentialsUploadBinding>() {
class MyCredentialsAdapter : BaseMultiAdapter<RecommendData, ViewBinding>() {
override fun getViewBinding(
context: Context,
parent: ViewGroup,
viewType: Int,
from: LayoutInflater
): ItemMyCredentialsUploadBinding {
return ItemMyCredentialsUploadBinding.inflate(from)
): ViewBinding {
return if (viewType == 0) {
ItemMyCredentialsUploadBinding.inflate(from, parent, false)
} else {
ItemMycredentialsShowBinding.inflate(from, parent, false)
}
}
override fun onBind(holder: ViewBinding, position: Int) {
if (holder is ItemMycredentialsShowBinding) {
holder.root.setOnClickListener {
listener?.onClick(position, list[position])
}
}
if (holder is ItemMyCredentialsUploadBinding) {
holder.root.setOnClickListener {
listener?.onClick(position, RecommendData(R.mipmap.card_back, "", ""))
}
}
}
override fun getItemCount(): Int {
return if (list.isEmpty()) {
1
} else {
list.size + 1
}
}
override fun onBind(
holder: ItemMyCredentialsUploadBinding,
position: Int,
data: RecommendData
) {
holder.ivBg.glideRound(data.pic, 16)
override fun getItemViewType(position: Int): Int {
return if (position == list.size) {
0
} else {
1
}
}
}
\ No newline at end of file
... ...
... ... @@ -17,8 +17,11 @@
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:overScrollMode="never"
app:layoutManager="androidx.recyclerview.widget.GridLayoutManager"
android:paddingBottom="16dp"
app:spanCount="2" />
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/solid_ff_8"
android:orientation="vertical">
<ImageView
android:id="@+id/iv_bg"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"
android:contentDescription="@string/logo"
android:scaleType="fitXY"
android:src="@mipmap/my_credentials_upload_bg" />
</LinearLayout>
\ No newline at end of file
... ...
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/solid_ff_8"
android:orientation="vertical">
<LinearLayout
android:layout_width="160dp"
android:layout_height="226dp"
android:layout_marginStart="20dp"
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:background="@drawable/solid_ffffff_8"
android:orientation="vertical">
android:contentDescription="@string/logo"
android:src="@mipmap/card_back" />
<ImageView
android:id="@+id/iv_bg"
android:layout_marginTop="16dp"
android:layout_gravity="center_horizontal"
android:layout_width="128dp"
android:layout_height="128dp"
android:src="@mipmap/ic_launcher" />
<TextView
android:id="@+id/tv_name"
android:text="三级电焊证"
android:textColor="@color/color_32"
android:textSize="14sp"
android:layout_marginTop="12dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/tv_time"
android:layout_marginBottom="16dp"
android:text="有效期:2020-09-09"
android:textColor="@color/color_96"
android:textSize="12sp"
android:layout_marginTop="8dp"
android:layout_gravity="center_horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="12dp"
android:gravity="center_vertical"
android:minHeight="26dp"
android:text="三级电焊证"
android:textColor="@color/color_32"
android:textSize="14sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:gravity="center_vertical"
android:text="有效期:2020-09-10"
android:textColor="@color/color_96"
android:textSize="12sp" />
</LinearLayout>
\ No newline at end of file
... ...