Skip to content

Commit

Permalink
🐛 dark mode configration change
Browse files Browse the repository at this point in the history
  • Loading branch information
ii2001 committed Oct 23, 2024
1 parent ea5913d commit 0bd3a6a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
initializeSplashScreen()
setContentView(binding.root)
initializeNavigation()
if (savedInstanceState == null) {
initializeNavigation()
}
}

private fun initializeSplashScreen() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,33 @@ class RecipeStepFragment : Fragment() {
binding.vpStepRecipe.apply {
adapter = recipeStepPagerRecyclerAdapter
orientation = ViewPager2.ORIENTATION_HORIZONTAL
// ViewPager 설정 후 위치 복원
if (savedInstanceState != null) {
val position = savedInstanceState.getInt("current_step_position", 0)
setCurrentItem(position, false)
} else {
// ViewModel에서 위치 복원
setCurrentItem(viewModel.currentPosition, false)
}
}
observeViewModel()

binding.dotsIndicator.attachTo(binding.vpStepRecipe)

// 페이지 변경 시 ViewModel에 위치 저장
binding.vpStepRecipe.registerOnPageChangeCallback(
object : ViewPager2.OnPageChangeCallback() {
override fun onPageSelected(position: Int) {
super.onPageSelected(position)
viewModel.currentPosition = position
}
},
)
}

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
outState.putInt("current_step_position", binding.vpStepRecipe.currentItem)
}

override fun onDestroyView() {
Expand All @@ -85,6 +108,9 @@ class RecipeStepFragment : Fragment() {
private fun observeRecipeSteps() {
viewModel.recipeSteps.observe(viewLifecycleOwner) { recipeSteps ->
recipeStepPagerRecyclerAdapter.updateList(recipeSteps)
// 데이터 로드 후 위치 복원
val position = viewModel.currentPosition
binding.vpStepRecipe.setCurrentItem(position, false)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@ class RecipeStepViewModel
private var _recipeSteps: MutableLiveData<List<RecipeStep>> = MutableLiveData(emptyList())
val recipeSteps: LiveData<List<RecipeStep>>
get() = _recipeSteps

private val _quitEvent = MutableLiveData<Event<Boolean>>()
val quitEvent: LiveData<Event<Boolean>>
get() = _quitEvent

var currentPosition: Int = 0

fun fetchRecipeSteps() {
viewModelScope.launch {
val response = feedRepository.fetchRecipeSteps(recipeId)
Expand Down

0 comments on commit 0bd3a6a

Please sign in to comment.