...
|
...
|
@@ -12,9 +12,13 @@ import com.br_technology.securitytrain_master.base.view.BaseAdapter |
|
|
import com.br_technology.securitytrain_master.base.view.BaseViewHolder
|
|
|
import com.br_technology.securitytrain_master.databinding.AdapterContentPracticeItemBinding
|
|
|
import com.br_technology.securitytrain_master.databinding.AdapterTopicBinding
|
|
|
import com.br_technology.securitytrain_master.ui.bean.Answer
|
|
|
import com.br_technology.securitytrain_master.ui.view.bank.bean.OptionArr
|
|
|
import com.br_technology.securitytrain_master.ui.view.bank.bean.TestSubject
|
|
|
import com.br_technology.securitytrain_master.view.listener.OnItemListener
|
|
|
import com.bumptech.glide.Glide
|
|
|
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
|
|
|
import com.bumptech.glide.request.RequestOptions
|
|
|
|
|
|
/**
|
|
|
* createTime:2021/7/30 15:45
|
...
|
...
|
@@ -75,23 +79,29 @@ class TopicAdapter : BaseAdapter<OptionArr, AdapterTopicBinding>() { |
|
|
|
|
|
@SuppressLint("SetTextI18n")
|
|
|
override fun onBind(holder: AdapterTopicBinding, position: Int, data: OptionArr) {
|
|
|
holder.name.text = "${data.option_name}.${data.value}"
|
|
|
setTextDefault(holder.name)
|
|
|
holder.tvName.text = "${data.option_name}.${data.value}"
|
|
|
if (data.pic.isNotEmpty()) {
|
|
|
Glide.with(holder.root.context)
|
|
|
.load(data.pic)
|
|
|
.apply(RequestOptions.bitmapTransform(RoundedCorners(12)))
|
|
|
.into(holder.ivPic)
|
|
|
}
|
|
|
setTextDefault(holder.contentTopic, holder.tvName)
|
|
|
// 单选 / 判断
|
|
|
if (type == 1 || type == 3) {
|
|
|
if (mSelectIndex.isNotEmpty() && mSelectIndex[0] == position) {
|
|
|
if (showCorrect) {
|
|
|
if (data.is_correct == 1) {
|
|
|
setTextGreen(holder.name)
|
|
|
setTextGreen(holder.contentTopic, holder.tvName)
|
|
|
} else {
|
|
|
setTextRed(holder.name)
|
|
|
setTextRed(holder.contentTopic, holder.tvName)
|
|
|
}
|
|
|
} else {
|
|
|
setTextGreen(holder.name)
|
|
|
setTextGreen(holder.contentTopic, holder.tvName)
|
|
|
}
|
|
|
} else {
|
|
|
if (showCorrect && data.is_correct == 1) {
|
|
|
setTextGreen(holder.name)
|
|
|
setTextGreen(holder.contentTopic, holder.tvName)
|
|
|
}
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -100,33 +110,33 @@ class TopicAdapter : BaseAdapter<OptionArr, AdapterTopicBinding>() { |
|
|
if (isSelected(position)) {
|
|
|
if (showCorrect) {
|
|
|
if (data.is_correct == 1) {
|
|
|
setTextGreen(holder.name)
|
|
|
setTextGreen(holder.contentTopic, holder.tvName)
|
|
|
} else {
|
|
|
setTextRed(holder.name)
|
|
|
setTextRed(holder.contentTopic, holder.tvName)
|
|
|
}
|
|
|
} else {
|
|
|
setTextGreen(holder.name)
|
|
|
setTextGreen(holder.contentTopic, holder.tvName)
|
|
|
}
|
|
|
} else {
|
|
|
if (showCorrect && data.is_correct == 1) {
|
|
|
setTextGreen(holder.name)
|
|
|
setTextGreen(holder.contentTopic, holder.tvName)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private fun setTextDefault(textView: TextView) {
|
|
|
textView.setBackgroundResource(R.drawable.stroke_eb_4)
|
|
|
private fun setTextDefault(view: View, textView: TextView) {
|
|
|
view.setBackgroundResource(R.drawable.stroke_eb_4)
|
|
|
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.color_32))
|
|
|
}
|
|
|
|
|
|
private fun setTextRed(textView: TextView) {
|
|
|
textView.setBackgroundResource(R.drawable.topic_back_error)
|
|
|
private fun setTextRed(view: View, textView: TextView) {
|
|
|
view.setBackgroundResource(R.drawable.topic_back_error)
|
|
|
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.color_e9))
|
|
|
}
|
|
|
|
|
|
private fun setTextGreen(textView: TextView) {
|
|
|
textView.setBackgroundResource(R.drawable.solid_a2_4_08a2)
|
|
|
private fun setTextGreen(view: View, textView: TextView) {
|
|
|
view.setBackgroundResource(R.drawable.solid_a2_4_08a2)
|
|
|
textView.setTextColor(ContextCompat.getColor(textView.context, R.color.color_e8))
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -134,7 +144,7 @@ class TopicAdapter : BaseAdapter<OptionArr, AdapterTopicBinding>() { |
|
|
class PracticePaperAdapter : BaseAdapter<TestSubject, AdapterContentPracticeItemBinding>() {
|
|
|
// 是否显示正确答案
|
|
|
var showCorrect = false
|
|
|
var selectResultData = mutableMapOf<Int, List<Int>>()
|
|
|
var selectResultData = HashMap<Int, List<Int>>()
|
|
|
|
|
|
override fun getViewBinding(
|
|
|
context: Context,
|
...
|
...
|
@@ -195,15 +205,46 @@ class PracticePaperAdapter : BaseAdapter<TestSubject, AdapterContentPracticeItem |
|
|
}
|
|
|
}
|
|
|
|
|
|
fun getResultData(): ArrayList<List<Int>> {
|
|
|
private fun getResultData(): ArrayList<List<Int>> {
|
|
|
val data = ArrayList<List<Int>>()
|
|
|
val result = selectResultData.values
|
|
|
val result = selectResultData.keys
|
|
|
val dataKey = mutableListOf<Int>()
|
|
|
for (item in result) {
|
|
|
data.add(item)
|
|
|
dataKey.add(item)
|
|
|
}
|
|
|
dataKey.sort()
|
|
|
for (index in dataKey) {
|
|
|
selectResultData.get(index)?.let {
|
|
|
data.add(it)
|
|
|
}
|
|
|
}
|
|
|
return data
|
|
|
}
|
|
|
|
|
|
fun getAnswer(): ArrayList<Answer> {
|
|
|
val data = ArrayList<Answer>()
|
|
|
val list = getResultData()
|
|
|
val listSubject = getData()
|
|
|
for (res in list) {
|
|
|
val pos = list.indexOf(res)
|
|
|
val ppp = listSubject[pos]
|
|
|
data.add(Answer(ppp.id, getAnswer(ppp.options_arr, res)))
|
|
|
}
|
|
|
return data
|
|
|
}
|
|
|
|
|
|
fun getAnswer(optionArr: List<OptionArr>, data: List<Int>): String {
|
|
|
var str = ""
|
|
|
if (data.isNotEmpty()) {
|
|
|
for (res in data) {
|
|
|
if (res < optionArr.size) {
|
|
|
str = str + optionArr[res].option_name + ","
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
return str.substringBeforeLast(",");
|
|
|
}
|
|
|
|
|
|
fun getCount(): Int {
|
|
|
var count = 0
|
|
|
for (data in selectResultData) {
|
...
|
...
|
@@ -216,15 +257,14 @@ class PracticePaperAdapter : BaseAdapter<TestSubject, AdapterContentPracticeItem |
|
|
|
|
|
fun getArrayList(): ArrayList<String> {
|
|
|
val list = ArrayList<String>()
|
|
|
val dataList = getResultData()
|
|
|
for (data in getData()) {
|
|
|
val position = getData().indexOf(data)
|
|
|
selectResultData[position]?.let { dataGet ->
|
|
|
if (dataList[position].isEmpty()) {
|
|
|
list.add("")
|
|
|
} else {
|
|
|
list.add(
|
|
|
if (isTrue(
|
|
|
data,
|
|
|
dataGet,
|
|
|
data.options_arr
|
|
|
)
|
|
|
if (isTrue(data, dataList[position], data.options_arr)
|
|
|
) "1" else "0"
|
|
|
)
|
|
|
}
|
...
|
...
|
|