-
Notifications
You must be signed in to change notification settings - Fork 0
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
Changes from 14 commits
2857dcb
8ca72d5
aaa31ab
824569f
a58b7ce
7350f4d
afd2ff7
75da2fd
e90dc71
4c29d41
a8cad49
3488ade
08003a5
c227a86
eb97cf3
d416eec
6976a2e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
@@ -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 | ||
|
||
|
||
class CafeteriaFragment : BaseFragment<FragmentCafeteriaBinding, CafeteriaViewModel>(), | ||
|
@@ -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) | ||
} | ||
|
@@ -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()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
} | ||
|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 날짜의 변동을 확인하는 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이전에 확인하지 못한 오류라 같이 수정하였습니다 |
||
) | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
어떤 의존성인가요 ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
시간을 조정하기 위한 호출입니다
가장 가까운 월요일을 찾기 위하여 사용합니다