Skip to content

Commit

Permalink
fix: food history view
Browse files Browse the repository at this point in the history
  • Loading branch information
moon0900 committed Dec 16, 2024
1 parent b29db1f commit cd6d565
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,13 @@ class FoodHistoryAdapter(
private val onItemClickListener: (FoodHistory) -> Unit)
: RecyclerView.Adapter<FoodHistoryAdapter.FoodHistoryViewHolder>() {

init {
sortItems()
}

// 뷰 홀더 생성
inner class FoodHistoryViewHolder(val historyView: FoodHistoryView)
: RecyclerView.ViewHolder(historyView)
{
fun bind(history: FoodHistory) {
historyView.setData(history.timestamp, history.kcal, history.imgUri)
historyView.setOnClickListener{ onItemClickListener(history) }
historyView.cardView.setOnClickListener{ onItemClickListener(history) }
}
}

Expand All @@ -36,15 +32,4 @@ class FoodHistoryAdapter(

override fun getItemCount() = items.size

// 데이터 업데이트 시 정렬
fun updateItems(newItems: List<FoodHistory>) {
sortItems(newItems)
notifyDataSetChanged()
}

// 데이터 정렬
private fun sortItems(newItems: List<FoodHistory> = items) {

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import android.net.Uri
import android.util.AttributeSet
import android.util.Log
import android.view.LayoutInflater
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.cardview.widget.CardView
Expand All @@ -21,27 +22,28 @@ import java.text.SimpleDateFormat
import java.util.Locale

class FoodHistoryView(context: Context, attrs: AttributeSet?) :
CardView(context, attrs) {
FrameLayout(context, attrs) {

// 뷰 컴포넌트들을 클래스 속성으로 정의
private val historyImg : ImageView
private val historyLabel : TextView
private val kcalTextView : TextView
val cardView: CardView

init {
// Bar View의 XML 레이아웃을 인플레이트
LayoutInflater.from(context).inflate(R.layout.food_history_item, this, true)
// 레이아웃 파라미터 설정
layoutParams = ConstraintLayout.LayoutParams(
ConstraintLayout.LayoutParams.MATCH_PARENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT,
ConstraintLayout.LayoutParams.WRAP_CONTENT
)

// 레이아웃 내 뷰 초기화
historyImg = findViewById(R.id.imageView)
historyLabel = findViewById(R.id.label)
kcalTextView = findViewById(R.id.kcal)

cardView = findViewById(R.id.cardView)

// attrs 입력값 속성 처리
attrs?.let{
Expand Down

0 comments on commit cd6d565

Please sign in to comment.