Skip to content

Commit

Permalink
[Feat/#61] section에 따른 배경이미지 지정
Browse files Browse the repository at this point in the history
  • Loading branch information
ss99x2002 committed Jul 14, 2023
1 parent 1f7edf5 commit 5bb7fa0
Showing 1 changed file with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
package com.sopt.umbba_android.presentation.home

import android.annotation.SuppressLint
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import coil.load
import com.sopt.umbba_android.R
import com.sopt.umbba_android.data.model.response.HomeResponseDto
import com.sopt.umbba_android.databinding.FragmentHomeBinding
import com.sopt.umbba_android.presentation.qna.QuestionAnswerActivity
import com.sopt.umbba_android.util.ViewModelFactory
import com.sopt.umbba_android.util.binding.BindingFragment

class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home) {
private val viewModel: HomeViewModel by viewModels { ViewModelFactory(requireContext()) }
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setBackground()
observeData()
setClickEvent()
}

Expand All @@ -26,9 +31,29 @@ class HomeFragment : BindingFragment<FragmentHomeBinding>(R.layout.fragment_home
}
}

private fun setBackground() {
private fun observeData() {
viewModel.homeData.observe(requireActivity()) {
setData(it)
setBackground(it.section)
}
}

@SuppressLint("StringFormatMatches")
private fun setData(data: HomeResponseDto.HomeData) {
with(binding) {
ivBackground.load(R.drawable.bg_home1)
tvTitle.text = getString(R.string.main_topic, data.index, data.topic)
}
}

private fun setBackground(section: String) {
binding.ivBackground.load(
when (section) {
"어린시절" -> R.drawable.bg_home1
"학창시절" -> R.drawable.bg_home2
"청춘시절" -> R.drawable.bg_home3
"연애시절" -> R.drawable.bg_home4
else -> R.drawable.bg_home5
}
)
}
}

0 comments on commit 5bb7fa0

Please sign in to comment.