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

[Feat] 현재 시간에 따른 아침/점심/저녁 구분 #201

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Changes from all 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
13 changes: 11 additions & 2 deletions app/src/main/java/com/eatssu/android/ui/main/ViewPager2Adapter.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.eatssu.android.ui.main

import android.util.Log
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.eatssu.android.data.enums.Time
import com.eatssu.android.ui.main.menu.MenuFragment
import java.time.LocalTime

class ViewPager2Adapter(fragmentActivity: FragmentActivity) :
FragmentStateAdapter(fragmentActivity) {
Expand Down Expand Up @@ -36,6 +36,15 @@ class ViewPager2Adapter(fragmentActivity: FragmentActivity) :
fun getDefaultFragmentPosition(): Int {
// 여기에서 디폴트로 노출할 Fragment의 위치를 반환해줍니다.
// 예를 들어, 첫 번째 Fragment를 디폴트로 설정하려면 0을 반환합니다.
return 1

val time = LocalTime.now()

val selectedIndex: Int = when (time.hour) {
in 0..10 -> 0 //아침
in 10..16 -> 1 //점심
in 16..24 -> 2 //저녁
else -> 1
}
return selectedIndex
}
}
Loading