Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dedf859
refactor: 식단 날짜 선택 ui 수정 및 현재 날짜 표시
huiwoo-jo Mar 12, 2025
dd0a85e
feat: 식단 카테고리 선택 버튼 추가 - 초기값 수정 필요
huiwoo-jo Mar 14, 2025
b954a52
fix: pause상태 후 월요일로 이동되는 문제 해결
huiwoo-jo Mar 14, 2025
b5e6e49
build: 식단 한식 ui 수정
huiwoo-jo Mar 14, 2025
d85c68e
build: 일품 메뉴 item 디자인 반영 - 데이터 형식 수정 필요
huiwoo-jo Mar 14, 2025
ea7f61f
build: 일품 메뉴 데이터 수정
huiwoo-jo Mar 14, 2025
1238e58
feat: 일품 메뉴 리스트 국명, 영문명, 가격 적용
huiwoo-jo Mar 14, 2025
0a38e20
feat: 식단 이미지 적용
huiwoo-jo Mar 14, 2025
8757317
fix: 날짜 선택에 따른 일품 메뉴 출력 오류 및 아이디 수정
huiwoo-jo Mar 14, 2025
f6a5276
build: 한식, 일품 선택 버튼 폰트 및 radius 적용
huiwoo-jo Mar 14, 2025
1c5c1d0
build: 한식 타이틀 및 리사이클러 아이템 폰트 적용
huiwoo-jo Mar 14, 2025
691d2a3
build: 한식, 일품 선택 버튼 그림자 제거
huiwoo-jo Mar 14, 2025
1552017
build: Timber 제거 및 코드 포맷팅
huiwoo-jo Mar 14, 2025
e4072b9
build: 한식, 일품 선택 변수를 상수화
huiwoo-jo Mar 14, 2025
fa9ca4a
build: 한식, 일품 컨테이너 id 변경
huiwoo-jo Mar 14, 2025
95bf561
build: 한식, 일품 id 변경
huiwoo-jo Mar 14, 2025
4416392
build: 한식, 일식 string 호출 방식 변경
huiwoo-jo Mar 27, 2025
56a59cc
build: cafeteria 색상 변경 중복 코드 간결화
huiwoo-jo Mar 27, 2025
58f2186
build: selectedDate 사용 방법 변경
huiwoo-jo Mar 27, 2025
890de9a
build: 한식 viewModel 변수명 변경 및 출력 방식 수정
huiwoo-jo Mar 27, 2025
e3af14e
build: no_menu 제거 및 주말 식당 이용 안내 추가 - 초기 출력 설정 필요
huiwoo-jo Mar 27, 2025
71c547c
build: findNearestMonday 함수 순서 변경
huiwoo-jo Mar 27, 2025
0c32d9f
fix: fragment 진입시 메뉴가 모두 뜨는 문제 임시 해결
huiwoo-jo Mar 27, 2025
8b5d2f3
reactor: 한식, 일품 출력 방식 문제 및 주말 판단 방식 변경
huiwoo-jo Apr 3, 2025
3326a2b
build: 코드 자동 포맷팅
huiwoo-jo Apr 3, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,26 @@ class CafeteriaRepository(
val price: Int,
val operatingDays: List<Weekdays>,
) {
PORKCUTLET("돈까스", 5_000, Weekdays.values().toList()),
CHEESE_PORKCUTLET("치즈돈까스", 5_500, Weekdays.values().toList()),
SWEET_POTATO_CHEESE_PORKCUTLET("고구마치즈돈까스", 6_000, Weekdays.values().toList()),
SPAM_KIMCHI_FRIED_RICE("스팸 김치 볶음밥", 4_900, listOf(Weekdays.MONDAY, Weekdays.TUESDAY)),
CHICKEN_MAYO_RICE("치킨 마요 덮밥", 4_900, listOf(Weekdays.WEDNESDAY)),
SPICY_MAYO_RICE("불닭 마요 덮밥", 4_900, listOf(Weekdays.WEDNESDAY)),
PORK_BELLY_RICE("삼겹살 덮밥", 5_500, listOf(Weekdays.THURSDAY)),
JANGJORIM_BUTTER_RICE("장조림 버터 비빔밥", 4_500, listOf(Weekdays.FRIDAY)),

RAMEN("라면", 3_500, Weekdays.values().toList()),
CHEESE_RAMEN("치즈라면", 4_000, Weekdays.values().toList()),
SEAFOOD_RAMEN("해물라면", 4_500, Weekdays.values().toList()),
SPAM_KIMCHI_FRIED_RICE("스팸김치볶음밥", 4_900, listOf(Weekdays.MONDAY, Weekdays.TUESDAY)),
HOT_CHICKEN_MAYO_RICE("불닭마요덮밥", 4_500, listOf(Weekdays.WEDNESDAY, Weekdays.THURSDAY)),
CHICKEN_MAYO_RICE("치킨마요덮밥", 4_500, listOf(Weekdays.WEDNESDAY, Weekdays.THURSDAY)),
OMELET_RICE("오므라이스", 5_500, listOf(Weekdays.FRIDAY));
CHEESE_RAMEN("치즈 라면", 4_000, Weekdays.values().toList()),
SEAFOOD_RAMEN("해물짬뽕 라면", 4_500, Weekdays.values().toList()),

CHAPAGETTI("짜파게티", 3_500, Weekdays.values().toList()),
CHAPAGETTI_EGG_CHEESE("짜계치", 4_000, Weekdays.values().toList()),
SPICY_RAMEN("불닭볶음면", 3_500, Weekdays.values().toList()),
CARBONARA_SPICY_RAMEN("까르보 불닭볶음면", 3_800, Weekdays.values().toList()),
CHEESE_SPICY_RAMEN("치즈 불닭볶음면", 4_000, Weekdays.values().toList()),

PORK_CUTLET("돈까스", 5_000, Weekdays.values().toList()),
CHEESE_PORK_CUTLET("치즈 돈까스", 5_500, Weekdays.values().toList()),
BRISKET_CHICKEN_CUTLET("통가슴살 치킨까스", 5_200, Weekdays.values().toList()),
SWEET_POTATO_CHEESE_PORK_CUTLET("고구마 치즈 돈까스", 6_000, Weekdays.values().toList()),
HOMEMADE_KING_PORK_CUTLET("수제 왕 돈까스", 6_000, Weekdays.values().toList()),
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.dongyang.android.youdongknowme.ui.adapter

import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.view.setPadding
import androidx.recyclerview.widget.RecyclerView
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.ItemCafeteriaAnotherBinding

class CafeteriaAnotherAdapter : RecyclerView.Adapter<CafeteriaAnotherAdapter.ViewHolder>() {

init {
setHasStableIds(true)
}

private var menu = arrayListOf<Array<String>>()

inner class ViewHolder(private val binding: ItemCafeteriaAnotherBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(item: Array<String>) {
binding.menuKr = item[0]
binding.menuEn = item[1].split('_')
.joinToString(" ") { word ->
word.lowercase().replaceFirstChar { firstChar -> firstChar.uppercase() }
}
binding.menuPrice = item[2]

val context = binding.root.context
val resourceName = "img_cafeteria_" + item[1].lowercase()
val drawableResId =
context.resources.getIdentifier(resourceName, "drawable", context.packageName)

if (drawableResId != 0) {
binding.imgAnother.setImageResource(drawableResId)
binding.imgAnother.setPadding(0)
} else {
binding.imgAnother.setImageResource(R.drawable.img_cafeteria_korean)
binding.imgAnother.setPadding(15)
}
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ItemCafeteriaAnotherBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
)
}

override fun getItemId(position: Int): Long {
return position.toLong()
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
holder.bind(menu[position])
}

@SuppressLint("NotifyDataSetChanged")
fun submitList(item: List<Array<String>>) {
menu.clear()
menu.addAll(item)
notifyDataSetChanged()
}

override fun getItemCount(): Int = menu.size
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,26 @@ import android.annotation.SuppressLint
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.dongyang.android.youdongknowme.databinding.ItemCafeteriaMenuBinding
import com.dongyang.android.youdongknowme.databinding.ItemCafeteriaKoreanBinding

class CafeteriaAdapter : RecyclerView.Adapter<CafeteriaAdapter.ViewHolder>() {
class CafeteriaKoreanAdapter : RecyclerView.Adapter<CafeteriaKoreanAdapter.ViewHolder>() {

init {
setHasStableIds(true)
}

private var menu = arrayListOf<String>()

inner class ViewHolder(private val binding: ItemCafeteriaMenuBinding) :
inner class ViewHolder(private val binding: ItemCafeteriaKoreanBinding) :
RecyclerView.ViewHolder(binding.root) {
fun bind(item: String) {
binding.menu = item
binding.koreanMenu = item
}
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
ItemCafeteriaMenuBinding.inflate(
ItemCafeteriaKoreanBinding.inflate(
LayoutInflater.from(parent.context), parent, false
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.dongyang.android.youdongknowme.databinding.ItemCalendarDayBinding
import com.kizitonwose.calendarview.CalendarView
import com.kizitonwose.calendarview.model.CalendarDay
import com.kizitonwose.calendarview.ui.ViewContainer
import java.time.LocalDate
import java.time.format.DateTimeFormatter

class CafeteriaContainer(
Expand All @@ -24,34 +25,44 @@ class CafeteriaContainer(

init {
view.setOnClickListener {
if (viewModel.selectedDate.value != day.date) {
notifyDateChanged(viewModel, calendarView, viewModel.selectedDate.value, day.date)
viewModel.selectedDate.value?.let { selectedDate ->
if (selectedDate != day.date) {
notifyDateChanged(viewModel, calendarView, selectedDate, day.date)
}
}
}
}

fun bind(day: CalendarDay) {
this.day = day
bind.itemCalendarDate.text = dateFormatter.format(day.date)
bind.itemCalendarDay.text = dayFormatter.format(day.date)
bind.itemCalendarMonth.text = monthFormatter.format(day.date)

if (day.date == viewModel.selectedDate.value) {
bind.mvItemCalendarDate.setCardBackgroundColor(
ContextCompat.getColor(
view.context,
R.color.blue300
)
)
bind.itemCalendarDate.setTextColor(ContextCompat.getColor(view.context, R.color.white))
} else {
bind.mvItemCalendarDate.setCardBackgroundColor(
ContextCompat.getColor(
view.context,
R.color.white
)
bind.apply {
tvItemCalendarDate.text = dateFormatter.format(day.date)
tvItemCalendarDay.text = dayFormatter.format(day.date)
tvItemCalendarMonth.text = monthFormatter.format(day.date)
}

val (bgColor, textColor) = when (day.date) {
viewModel.selectedDate.value -> R.color.blue300 to R.color.white
LocalDate.now() -> R.color.gray200 to R.color.gray500
else -> R.color.white to R.color.gray500
}

bind.mvItemCalendarContainer.setCardBackgroundColor(
ContextCompat.getColor(
view.context,
bgColor
)
bind.itemCalendarDate.setTextColor(ContextCompat.getColor(view.context, R.color.black))
)
setTextColor(textColor)
}

private fun setTextColor(colorRes: Int) {
val color = ContextCompat.getColor(view.context, colorRes)

bind.apply {
tvItemCalendarDate.setTextColor(color)
tvItemCalendarDay.setTextColor(color)
tvItemCalendarMonth.setTextColor(color)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import android.annotation.SuppressLint
import android.util.TypedValue
import android.view.MotionEvent
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.window.layout.WindowMetricsCalculator
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.FragmentCafeteriaBinding
import com.dongyang.android.youdongknowme.standard.base.BaseFragment
import com.dongyang.android.youdongknowme.ui.adapter.CafeteriaAdapter
import com.dongyang.android.youdongknowme.ui.adapter.CafeteriaAnotherAdapter
import com.dongyang.android.youdongknowme.ui.adapter.CafeteriaKoreanAdapter
import com.dongyang.android.youdongknowme.ui.view.util.EventObserver
import com.google.android.flexbox.FlexDirection
import com.google.android.flexbox.FlexboxLayoutManager
import com.kizitonwose.calendarview.model.CalendarDay
import com.kizitonwose.calendarview.ui.DayBinder
import com.kizitonwose.calendarview.utils.Size
Expand All @@ -27,31 +29,47 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
override val layoutResourceId: Int = R.layout.fragment_cafeteria
override val viewModel: CafeteriaViewModel by viewModel()

private lateinit var koreanMenuAdapter: CafeteriaAdapter
private lateinit var anotherMenuAdapter: CafeteriaAdapter
private lateinit var koreanMenuAdapter: CafeteriaKoreanAdapter
private lateinit var anotherMenuAdapter: CafeteriaAnotherAdapter

private val korean by lazy { getString(R.string.cafeteria_korean) }
private val another by lazy { getString(R.string.cafeteria_another) }

override fun initStartView() {
binding.vm = viewModel

koreanMenuAdapter = CafeteriaAdapter()
anotherMenuAdapter = CafeteriaAdapter()
koreanMenuAdapter = CafeteriaKoreanAdapter()
anotherMenuAdapter = CafeteriaAnotherAdapter()

binding.rvCafeteriaMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
binding.rvCafeteriaKoreanMenuList.apply {
val layoutManager = LinearLayoutManager(context)
this.adapter = this@CafeteriaFragment.koreanMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}

binding.rvCafeteriaAnotherMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
val layoutManager = LinearLayoutManager(context)
this.adapter = this@CafeteriaFragment.anotherMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}

binding.tgCategory.check(binding.btnKorean.id)
viewModel.setCategory(korean)

binding.tgCategory.addOnButtonCheckedListener { _, checkedId, isChecked ->
val category = when (checkedId) {
binding.btnKorean.id -> korean
binding.btnAnother.id -> another
else -> korean
}

if (isChecked) {
viewModel.setCategory(category)
}
}

val wmc =
WindowMetricsCalculator.getOrCreate().computeCurrentWindowMetrics(requireActivity())

Expand All @@ -72,8 +90,6 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo

override fun bind(container: CafeteriaContainer, day: CalendarDay) = container.bind(day)
}

viewModel.updateDaysMenu(findNearestMonday(LocalDate.now()))
}

override fun initDataBinding() {
Expand All @@ -86,13 +102,21 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
showToast(getString(resId))
})

viewModel.koreaMenus.observe(viewLifecycleOwner) {
viewModel.koreanMenus.observe(viewLifecycleOwner) {
koreanMenuAdapter.submitList(it)
}

viewModel.daysMenus.observe(viewLifecycleOwner) {
viewModel.anotherMenus.observe(viewLifecycleOwner) {
anotherMenuAdapter.submitList(it)
}

viewModel.selectedCategory.observe(viewLifecycleOwner) { selectedCategory ->
updateCafeteriaState(selectedCategory)
}

viewModel.selectedDate.observe(viewLifecycleOwner) {
viewModel.updateDaysMenu(it)
}
}

@SuppressLint("ClickableViewAccessibility")
Expand All @@ -109,7 +133,7 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo

binding.cafeteriaErrorContainer.refresh.setOnClickListener {
viewModel.fetchCafeteria()
viewModel.updateDaysMenu(findNearestMonday(LocalDate.now()))
viewModel.updateDaysMenu(viewModel.selectedDate.value ?: nearestMonday)
}

binding.cvCafeteriaCalendar.setOnTouchListener { _, event ->
Expand All @@ -123,9 +147,25 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
}
}

private fun updateCafeteriaState(selectedCategory: String) {
val activeColor = ContextCompat.getColor(requireContext(), R.color.white)
val inactiveColor = ContextCompat.getColor(requireContext(), R.color.gray200)
val isWeekend =
viewModel.selectedDate.value?.dayOfWeek == SATURDAY || viewModel.selectedDate.value?.dayOfWeek == SUNDAY

binding.tvCafeteriaWeekend.isVisible = isWeekend

binding.linearLayoutCafeteriaKorean.isVisible = selectedCategory == korean && !isWeekend
binding.linearLayoutCafeteriaAnother.isVisible = selectedCategory == another && !isWeekend

binding.btnKorean.setBackgroundColor(if (selectedCategory == korean) activeColor else inactiveColor)
binding.btnAnother.setBackgroundColor(if (selectedCategory == another) activeColor else inactiveColor)
}


private fun findNearestMonday(currentDate: LocalDate): LocalDate {
return when (currentDate.dayOfWeek) {
SATURDAY, SUNDAY -> {
SUNDAY -> {
currentDate.with(TemporalAdjusters.next(MONDAY))
}

Expand All @@ -138,14 +178,4 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
}
}
}

override fun onPause() {
super.onPause()
notifyDateChanged(
viewModel = viewModel,
calendarView = binding.cvCafeteriaCalendar,
oldDate = viewModel.selectedDate.value,
selectedDate = findNearestMonday(LocalDate.now())
)
}
}
Loading
Loading