From 5bb7fa0391168d4f31c9c85deb27a83fff9c9d28 Mon Sep 17 00:00:00 2001 From: ss99x2002 Date: Sat, 15 Jul 2023 07:29:06 +0900 Subject: [PATCH] =?UTF-8?q?[Feat/#61]=20section=EC=97=90=20=EB=94=B0?= =?UTF-8?q?=EB=A5=B8=20=EB=B0=B0=EA=B2=BD=EC=9D=B4=EB=AF=B8=EC=A7=80=20?= =?UTF-8?q?=EC=A7=80=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/home/HomeFragment.kt | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/sopt/umbba_android/presentation/home/HomeFragment.kt b/app/src/main/java/com/sopt/umbba_android/presentation/home/HomeFragment.kt index 6975bfe0..9f7fcf6e 100644 --- a/app/src/main/java/com/sopt/umbba_android/presentation/home/HomeFragment.kt +++ b/app/src/main/java/com/sopt/umbba_android/presentation/home/HomeFragment.kt @@ -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(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() } @@ -26,9 +31,29 @@ class HomeFragment : BindingFragment(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 + } + ) + } } \ No newline at end of file