Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor : 식단 화면 QA 적용 및 수정 #201

Merged
merged 17 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
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
@@ -1,6 +1,9 @@
package com.dongyang.android.youdongknowme.ui.view.cafeteria

import android.annotation.SuppressLint
import android.view.MotionEvent
import android.view.View
import androidx.recyclerview.widget.RecyclerView
import androidx.window.layout.WindowMetricsCalculator
import com.dongyang.android.youdongknowme.R
import com.dongyang.android.youdongknowme.databinding.FragmentCafeteriaBinding
Expand All @@ -16,6 +19,7 @@ import org.koin.androidx.viewmodel.ext.android.viewModel
import java.time.DayOfWeek
import java.time.LocalDate
import java.time.YearMonth
import java.time.temporal.TemporalAdjusters
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

어떤 의존성인가요 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

시간을 조정하기 위한 호출입니다
가장 가까운 월요일을 찾기 위하여 사용합니다



class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewModel>(),
Expand All @@ -24,27 +28,27 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
override val layoutResourceId: Int = R.layout.fragment_cafeteria
override val viewModel: CafeteriaViewModel by viewModel()

private lateinit var stuKoreanMenuAdapter: CafeteriaAdapter
private lateinit var stuAnotherMenuAdapter: CafeteriaAdapter
private lateinit var koreanMenuAdapter: CafeteriaAdapter
private lateinit var anotherMenuAdapter: CafeteriaAdapter

override fun initStartView() {
binding.vm = viewModel

stuKoreanMenuAdapter = CafeteriaAdapter()
stuAnotherMenuAdapter = CafeteriaAdapter()
koreanMenuAdapter = CafeteriaAdapter()
anotherMenuAdapter = CafeteriaAdapter()

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

binding.rvCafeteriaAnotherMenuList.apply {
val layoutManager = FlexboxLayoutManager(context)
layoutManager.flexDirection = FlexDirection.ROW
this.adapter = this@CafeteriaFragment.stuAnotherMenuAdapter
this.adapter = this@CafeteriaFragment.anotherMenuAdapter
this.layoutManager = layoutManager
this.setHasFixedSize(true)
}
Expand Down Expand Up @@ -79,25 +83,54 @@ class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewMo
})

viewModel.menus.observe(viewLifecycleOwner) {
stuKoreanMenuAdapter.submitList(it)
koreanMenuAdapter.submitList(it)
// 일품 메뉴 : 일품 메뉴는 리스트로 제작하여 등록
stuAnotherMenuAdapter.submitList(listOf(getString(R.string.cafeteria_no_menu)))
anotherMenuAdapter.submitList(listOf(getString(R.string.cafeteria_no_menu)))
}

}

@SuppressLint("ClickableViewAccessibility")
override fun initAfterBinding() {
val nearestMonday = findNearestMonday(LocalDate.now())
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nearestMonday 가 무슨 뜻인가요 ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가장 가까운 월요일입니다!
평일일 경우에는 그 주의 월요일, 주말일 경우에는 다음주 월요일을 찾기 위하여 만들었습니다


binding.cvCafeteriaCalendar.setup(
YearMonth.now().minusMonths(2),
YearMonth.now().plusMonths(1),
DayOfWeek.values().random()
YearMonth.from(nearestMonday),
YearMonth.from(nearestMonday.plusDays(4)),
DayOfWeek.MONDAY
)

binding.cvCafeteriaCalendar.scrollToDate(LocalDate.now().minusDays(2))
binding.cvCafeteriaCalendar.scrollToDate(nearestMonday)

binding.cafeteriaErrorContainer.refresh.setOnClickListener {
viewModel.fetchCafeteria()
}

binding.cvCafeteriaCalendar.setOnTouchListener { _, event ->
when (event.actionMasked) {
MotionEvent.ACTION_DOWN, MotionEvent.ACTION_MOVE -> {
true
}

else -> false
}
}
}

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

DayOfWeek.MONDAY -> {
currentDate
}

else -> {
currentDate.with(TemporalAdjusters.previous(DayOfWeek.MONDAY))
}
}
}

override fun onPause() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CafeteriaViewModel(
val menuList = result.data
_cafeteriaList.value = menuList
_selectedDate.value = LocalDate.now()
updateMenuList(selectedDate.toString())
selectedDate.value?.let { updateMenuList(it) }
_isError.postValue(false)
_isLoading.postValue(false)
}
Expand All @@ -64,8 +64,11 @@ class CafeteriaViewModel(
}
}

fun updateMenuList(selectedDate: String) {
fun updateMenuList(selectedDate: LocalDate) {
val cafeteriaList = _cafeteriaList.value ?: emptyList()
_menus.postValue(cafeteriaList.find { it.date == selectedDate }?.menus ?: emptyMenu)
_selectedDate.value = selectedDate
_menus.postValue(
cafeteriaList.find { it.date == selectedDate.toString() }?.menus ?: emptyMenu
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selectedDate를 toString 으로 타입을 변경해야 하는데 selectedDate 자체를 LocalDate 타입으로 변경하신 이유가 궁금해요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

날짜의 변동을 확인하는 CafeteriaInterfacenotifyDateChanged을 위하여 LocalDate를 사용해야합니다. String에서 LocalDate로 변경이 불가능하여 LocalDate 타입으로 수정하였습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이전에 확인하지 못한 오류라 같이 수정하였습니다

)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface CalendarInterface {
oldDate: LocalDate?,
selectedDate: LocalDate
) {
viewModel.updateMenuList(selectedDate.toString())
viewModel.updateMenuList(selectedDate)
calendarView.notifyDateChanged(selectedDate)
oldDate?.let { calendarView.notifyDateChanged(it) }
}
Expand Down
54 changes: 36 additions & 18 deletions app/src/main/res/layout/fragment_cafeteria.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
android:id="@+id/cv_cafeteria_calendar"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:scrollbars="none"
app:cv_dayViewResource="@layout/item_calendar_day"
app:cv_hasBoundaries="false"
app:cv_inDateStyle="none"
Expand All @@ -51,7 +52,7 @@
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:paddingVertical="16dp"
android:paddingVertical="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cv_cafeteria_calendar">
Expand All @@ -63,27 +64,27 @@

<TextView
android:id="@+id/tv_cafeteria_info_place"
style="@style/PretendardRegular14"
style="@style/PretendardMedium14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="4dp"
android:layout_marginStart="12dp"
android:text="@string/cafeteria_place"
android:textColor="@color/line" />

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginStart="16dp"
android:src="@drawable/ic_timer" />

<TextView
android:id="@+id/tv_cafeteria_info_time"
style="@style/PretendardRegular14"
style="@style/PretendardMedium14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="4dp"
android:layout_marginStart="12dp"
android:text="@string/cafeteria_time"
android:textColor="@color/line"
app:layout_constraintEnd_toEndOf="parent" />
Expand All @@ -107,6 +108,21 @@
android:layout_gravity="center" />
</LinearLayout>

<com.google.android.material.chip.Chip
android:id="@+id/chip_weekend_cafeteria"
style="@style/Colors_Widget.MaterialComponents.Chip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:backgroundTint="@color/blue100"
android:clickable="false"
android:text="@string/cafetria_weekend"
android:textAlignment="center"
android:visibility="invisible"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cafeteria_info_container" />

<com.google.android.material.card.MaterialCardView
android:id="@+id/mv_cafeteria_menu"
bind_is_error="@{vm.cafeteriaList == null}"
Expand All @@ -115,20 +131,21 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="12dp"
android:outlineSpotShadowColor="@color/blue300"
app:cardCornerRadius="16dp"
app:cardElevation="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cafeteria_info_container">
app:layout_constraintTop_toBottomOf="@id/cafeteria_info_container"
app:strokeColor="@color/blue300"
app:strokeWidth="2dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:padding="8dp" >

<TextView
style="@style/PretendardBold14"
style="@style/PretendardBold20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand All @@ -140,8 +157,8 @@
android:id="@+id/rv_cafeteria_menu_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginVertical="8dp"
android:layout_marginStart="8dp"
tools:listitem="@layout/item_cafeteria_menu" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
Expand All @@ -154,20 +171,21 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="20dp"
android:outlineSpotShadowColor="@color/blue300"
app:cardCornerRadius="16dp"
app:cardElevation="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/mv_cafeteria_menu">
app:layout_constraintTop_toBottomOf="@id/mv_cafeteria_menu"
app:strokeColor="@color/blue300"
app:strokeWidth="2dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
android:orientation="vertical"
android:padding="8dp" >

<TextView
style="@style/PretendardBold14"
style="@style/PretendardBold20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
Expand All @@ -179,8 +197,8 @@
android:id="@+id/rv_cafeteria_another_menu_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginVertical="8dp"
android:layout_marginStart="8dp"
tools:listitem="@layout/item_cafeteria_menu" />

</LinearLayout>
Expand Down
11 changes: 5 additions & 6 deletions app/src/main/res/layout/item_calendar_day.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<androidx.constraintlayout.widget.ConstraintLayout xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
tools:background="@color/white">

<LinearLayout
Expand All @@ -21,7 +20,7 @@

<TextView
android:id="@+id/item_calendar_month"
style="@style/PretendardRegular12"
style="@style/PretendardMedium14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -34,14 +33,14 @@
android:layout_width="32dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginTop="12dp"
android:gravity="center"
app:cardElevation="0dp"
app:cardCornerRadius="10dp">

<TextView
android:id="@+id/item_calendar_date"
style="@style/PretendardRegular16"
style="@style/PretendardSemiBold16"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
Expand All @@ -52,11 +51,11 @@

<TextView
android:id="@+id/item_calendar_day"
style="@style/PretendardRegular12"
style="@style/PretendardMedium14"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="8dp"
android:layout_marginTop="12dp"
android:gravity="center"
android:textColor="@color/black"
tools:text="Mon" />
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@
<string name="cafeteria_no_menu">&#128517; 등록된 메뉴가 없어요.</string>
<string name="cafeteria_korean">🍚 한식</string>
<string name="cafeteria_another">🍛 일품</string>
<string name="cafetria_weekend">주말에는 식당을 운영하지 않아요.</string>
huiwoo-jo marked this conversation as resolved.
Show resolved Hide resolved

<!-- license -->
<string name="license_title">오픈소스 라이센스</string>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
</style>

<style name="Colors_Widget.MaterialComponents.Chip" parent="Widget.MaterialComponents.Chip.Choice">
<item name="android:textAppearance">@style/PretendardRegular14</item>
<item name="android:textAppearance">@style/PretendardMedium16</item>
<item name="android:textAlignment">center</item>
<item name="android:textColor">@color/black</item>
</style>
Expand Down
Loading