优化
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
package com.sw.dualscreen.adapter
|
||||
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
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.ListItemSearchFoodBinding
|
||||
import com.sw.dualscreen.ext.format2String
|
||||
import com.sw.dualscreen.model.response.FoodInfo
|
||||
|
||||
class CollectFoodListAdapter(var list: MutableList<FoodInfo>) :
|
||||
BaseQuickAdapter<FoodInfo, CollectFoodListAdapter.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.root.setBackgroundResource(R.drawable.bg_text_collect)
|
||||
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
|
||||
setTextColor(
|
||||
if (isChecked) "#FF3232".toColorInt()
|
||||
else "#5E7585".toColorInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+11
-2
@@ -3,14 +3,16 @@ package com.sw.dualscreen.adapter
|
||||
import android.content.Context
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
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.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) {
|
||||
class MainFoodListAdapter(var list: MutableList<FoodInfo>) :
|
||||
BaseQuickAdapter<FoodInfo, MainFoodListAdapter.VH>(list) {
|
||||
|
||||
inner class VH(var binding: ListItemSearchFoodBinding) : QuickViewHolder(binding.root)
|
||||
|
||||
@@ -21,6 +23,7 @@ class SearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: VH, position: Int, item: FoodInfo?) {
|
||||
holder.binding.root.setBackgroundResource(R.drawable.bg_text_main)
|
||||
holder.binding.tvFoodName.run {
|
||||
if (item!!.score == 0) {
|
||||
text = item.foodName
|
||||
@@ -29,6 +32,12 @@ class SearchFoodAdapter(var list: MutableList<FoodInfo>) :
|
||||
text = item.foodName + (if (item.score != 0) "-${score}%" else "")
|
||||
}
|
||||
isChecked = item.isChecked
|
||||
setTextColor(
|
||||
|
||||
|
||||
if (isChecked) "#FF3232".toColorInt()
|
||||
else "#0A1428".toColorInt()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user