38 lines
1.4 KiB
Kotlin
38 lines
1.4 KiB
Kotlin
package com.sw.dualscreen.adapter
|
|
|
|
import android.content.Context
|
|
import android.view.LayoutInflater
|
|
import android.view.ViewGroup
|
|
import androidx.core.content.ContextCompat
|
|
import androidx.core.graphics.toColorInt
|
|
import com.chad.library.adapter4.BaseQuickAdapter
|
|
import com.chad.library.adapter4.viewholder.QuickViewHolder
|
|
import com.sw.dualscreen.R
|
|
import com.sw.dualscreen.databinding.ListItemSearchFood2Binding
|
|
import com.sw.dualscreen.ext.format2String
|
|
import com.sw.dualscreen.model.response.FoodInfo
|
|
|
|
class DialogSearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
|
BaseQuickAdapter<FoodInfo, DialogSearchFoodAdapter.VH>(list) {
|
|
|
|
inner class VH(var binding: ListItemSearchFood2Binding) : QuickViewHolder(binding.root)
|
|
|
|
override fun onCreateViewHolder(context: Context, parent: ViewGroup, viewType: Int): VH {
|
|
val inflater = LayoutInflater.from(context)
|
|
val binding = ListItemSearchFood2Binding.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
|
|
}
|
|
}
|
|
|
|
} |