35 lines
1.3 KiB
Kotlin
35 lines
1.3 KiB
Kotlin
package com.sw.dualscreen.adapter
|
|
|
|
import android.content.Context
|
|
import android.view.LayoutInflater
|
|
import android.view.ViewGroup
|
|
import com.chad.library.adapter4.BaseQuickAdapter
|
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
|
import com.sw.dualscreen.databinding.ListItemSearchFoodBinding
|
|
import com.sw.dualscreen.ext.format2String
|
|
import com.sw.dualscreen.model.response.FoodInfo
|
|
|
|
class SearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
|
BaseQuickAdapter<FoodInfo, SearchFoodAdapter.VH>(list) {
|
|
|
|
inner class VH(var binding: ListItemSearchFoodBinding) : QuickViewHolder(binding.root)
|
|
|
|
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
|
val inflater = LayoutInflater.from(context)
|
|
val binding = ListItemSearchFoodBinding.inflate(inflater, parent, false)
|
|
return VH(binding)
|
|
}
|
|
|
|
override fun onBindViewHolder(holder: VH, position: Int, item: FoodInfo?) {
|
|
holder.binding.tvFoodName.run {
|
|
if (item!!.score == 0) {
|
|
text = item.foodName
|
|
} else {
|
|
val score = (item.score / 100.0).format2String(2)
|
|
text = item.foodName + if (item.score != 0) "-${score}%" else ""
|
|
}
|
|
isChecked = item.isChecked
|
|
}
|
|
}
|
|
|
|
} |