From 894cbff0e38864dbd669a695593f588435e451e5 Mon Sep 17 00:00:00 2001 From: dkyuuum Date: Thu, 15 Feb 2024 11:36:12 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=ED=96=A5=ED=9B=84=20=EA=B3=84=ED=9A=8D?= =?UTF-8?q?=20=EC=8B=9C=EA=B0=84=ED=91=9C=20=ED=95=99=EA=B8=B0/=EA=B3=BC?= =?UTF-8?q?=EB=AA=A9=20=EC=84=A0=ED=83=9D=20#50?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/model/plan/SavelicenseRequest.kt | 12 +- .../data/model/plan/SemesterTimeResponse.kt | 17 +- .../project/ui/plan/PlanSemesterAdapter.kt | 37 +- .../project/ui/plan/PlanSemesterFragment.kt | 55 +-- .../project/ui/plan/PlanSettingFragment.kt | 71 +-- .../project/ui/plan/PlanTimeFragment.kt | 68 ++- .../project/ui/plan/PlanTrackFragment.kt | 37 +- .../mobile/project/ui/plan/PlanViewModel.kt | 409 ++++++++++-------- .../project/ui/plan/PlanlicenseFragment.kt | 162 +++---- .../main/res/layout/fragment_planlicense.xml | 2 +- app/src/main/res/layout/plan_subject_list.xml | 130 +++--- app/src/main/res/layout/semester_choose.xml | 38 +- .../main/res/navigation/mobile_navigation.xml | 16 +- 13 files changed, 541 insertions(+), 513 deletions(-) diff --git a/app/src/main/java/umc/com/mobile/project/data/model/plan/SavelicenseRequest.kt b/app/src/main/java/umc/com/mobile/project/data/model/plan/SavelicenseRequest.kt index 478df2e..08022d8 100644 --- a/app/src/main/java/umc/com/mobile/project/data/model/plan/SavelicenseRequest.kt +++ b/app/src/main/java/umc/com/mobile/project/data/model/plan/SavelicenseRequest.kt @@ -4,13 +4,17 @@ import java.time.LocalDate data class SaveInfo( - val name: String, - val date: String + val name: String, + val date: String ) + + + data class SavelicenseRequest( - val info: List -) + val info : List, + + ) diff --git a/app/src/main/java/umc/com/mobile/project/data/model/plan/SemesterTimeResponse.kt b/app/src/main/java/umc/com/mobile/project/data/model/plan/SemesterTimeResponse.kt index 7a9e492..2b3b917 100644 --- a/app/src/main/java/umc/com/mobile/project/data/model/plan/SemesterTimeResponse.kt +++ b/app/src/main/java/umc/com/mobile/project/data/model/plan/SemesterTimeResponse.kt @@ -1,17 +1,14 @@ package umc.com.mobile.project.data.model.plan data class SemesterTimeResponse( - val isSuccess: Boolean, - val code: String, - val message: String, - val result: List, -) { - - -} + val isSuccess: Boolean, + val code: String, + val message: String, + val result: List, +) data class semesterResult( - val hakkiNum: String, - val hakkiText: String, + val hakkiNum: String, + val hakkiText: String, ) diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterAdapter.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterAdapter.kt index 912f19e..1360383 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterAdapter.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterAdapter.kt @@ -7,31 +7,28 @@ import umc.com.mobile.project.data.model.plan.semesterResult import umc.com.mobile.project.databinding.ItemChooseSemesterBinding class PlanSemesterAdapter( semesterList: List): RecyclerView.Adapter(){ - var semesterList: List = semesterList - set(value) { - field = value - notifyDataSetChanged() - //데이터가 바뀌었다 알려줌. - } + var semesterList: List = semesterList + set(value) { + field = value + notifyDataSetChanged() + //데이터가 바뀌었다 알려줌. + } - override fun getItemCount(): Int { - return semesterList?.size ?: 0 - } + override fun getItemCount(): Int { + return semesterList?.size ?: 0 + } - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlanSemesterAdapter.NonSubjectViewHolder { - val itemBinding = ItemChooseSemesterBinding.inflate(LayoutInflater.from(parent.context), parent, false) - return PlanSemesterAdapter.NonSubjectViewHolder(itemBinding) - } + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PlanSemesterAdapter.NonSubjectViewHolder { + val itemBinding = ItemChooseSemesterBinding.inflate(LayoutInflater.from(parent.context), parent, false) + return PlanSemesterAdapter.NonSubjectViewHolder(itemBinding) + } - override fun onBindViewHolder(holder: PlanSemesterAdapter.NonSubjectViewHolder, position: Int) { + override fun onBindViewHolder(holder: PlanSemesterAdapter.NonSubjectViewHolder, position: Int) { - val semesterInfo = semesterList[position] - if (semesterInfo != null) { - holder.itemBinding.planTimeSemesterItem.text = semesterInfo.hakkiText - } + holder.itemBinding.planTimeSemesterItem.text =semesterList[position]?.hakkiText.toString() - } + } - class NonSubjectViewHolder(val itemBinding: ItemChooseSemesterBinding) : RecyclerView.ViewHolder(itemBinding.root) + class NonSubjectViewHolder(val itemBinding: ItemChooseSemesterBinding) : RecyclerView.ViewHolder(itemBinding.root) } \ No newline at end of file diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterFragment.kt index c173abb..d1f412e 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSemesterFragment.kt @@ -16,59 +16,42 @@ import umc.com.mobile.project.databinding.FragmentPlanlicenseBinding import android.widget.EditText import androidx.core.view.setMargins import androidx.lifecycle.Observer -import androidx.recyclerview.widget.LinearLayoutManager - +import umc.com.mobile.project.data.model.plan.SaveInfo import umc.com.mobile.project.data.model.plan.SavelicenseRequest import umc.com.mobile.project.data.model.plan.semesterResult import umc.com.mobile.project.databinding.SemesterChooseBinding import java.time.LocalDate class PlanSemesterFragment : Fragment() { - private var _binding: SemesterChooseBinding? = null - private val viewModel: PlanViewModel by viewModels() - private val binding get() = _binding!! - - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = SemesterChooseBinding.inflate(inflater, container, false) - - - - - - return binding.root - } + private var _binding: SemesterChooseBinding? = null + private val viewModel: PlanViewModel by viewModels() + private val binding get() = _binding!! + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = SemesterChooseBinding.inflate(inflater, container, false) - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - val adapter = PlanSemesterAdapter(listOf()) // 초기 데이터로 빈 리스트 사용 - // RecyclerView에 어댑터와 레이아웃 매니저 설정 - binding.recyclerViewPlanSemester.adapter = adapter - binding.recyclerViewPlanSemester.layoutManager = LinearLayoutManager(context) + return binding.root + } - viewModel.planSemesterInfo.observe(viewLifecycleOwner) { semesterInfo -> - // 데이터가 업데이트되면 어댑터의 리스트 업데이트 - adapter.semesterList = semesterInfo?.result ?: emptyList() - adapter.notifyDataSetChanged() - } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) - viewModel.getSemesterInfo() // 데이터 로드 - } + } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSettingFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSettingFragment.kt index 51b01b1..ee95e4a 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSettingFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanSettingFragment.kt @@ -17,57 +17,58 @@ import umc.com.mobile.project.ui.gradInfo.adapter.GradInfoVPAdapter import umc.com.mobile.project.ui.gradInfo.viewmodel.GradInfoViewModel class PlanSettingFragment : Fragment() { - private var _binding:PlanTimeTabMainBinding? = null - private val viewModel: PlanViewModel by viewModels() - private val binding get() = _binding!! + private var _binding:PlanTimeTabMainBinding? = null + private val viewModel: PlanViewModel by viewModels() + private val binding get() = _binding!! - private lateinit var viewPager : ViewPager2 - private lateinit var tabLayout : TabLayout + private lateinit var viewPager : ViewPager2 + private lateinit var tabLayout : TabLayout - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = PlanTimeTabMainBinding.inflate(inflater, container, false) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = PlanTimeTabMainBinding.inflate(inflater, container, false) - initTabLayout() - initViewPager() + initTabLayout() + initViewPager() - return binding.root - } + return binding.root + } - private fun initTabLayout() { + private fun initTabLayout() { - val tabTitle = arrayOf("시간표", "자격증", "자유") + val tabTitle = arrayOf("시간표", "자격증", "자유") - viewPager = binding.viewPagerTimeTabMain - tabLayout = binding.tabLayoutPlanTime + viewPager = binding.viewPagerTimeTabMain + tabLayout = binding.tabLayoutPlanTime - val adapter = PlanVPAdapter(this) + val adapter = PlanVPAdapter(this) - adapter.addFragment(PlanTimeFragment()) - adapter.addFragment(PlanlicenseFragment()) - adapter.addFragment(PlanFreeFragment()) - viewPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL - viewPager.adapter = adapter + adapter.addFragment(PlanlicenseFragment()) + adapter.addFragment(PlanTimeFragment()) + adapter.addFragment(PlanFreeFragment()) - TabLayoutMediator(tabLayout, viewPager - ) { tab, position -> tab.text = tabTitle[position] }.attach() - } + viewPager.orientation = ViewPager2.ORIENTATION_HORIZONTAL + viewPager.adapter = adapter - private fun initViewPager() { + TabLayoutMediator(tabLayout, viewPager + ) { tab, position -> tab.text = tabTitle[position] }.attach() + } - binding.viewPagerTimeTabMain.isUserInputEnabled = false - } + private fun initViewPager() { + binding.viewPagerTimeTabMain.isUserInputEnabled = false + } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } + + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } \ No newline at end of file diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTimeFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTimeFragment.kt index 8def1b7..5964ae4 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTimeFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTimeFragment.kt @@ -17,64 +17,54 @@ import umc.com.mobile.project.ui.common.NavigationUtil.navigate import umc.com.mobile.project.ui.plan.PlanViewModel class PlanTimeFragment : Fragment() { - private var _binding: PlanSubjectListBinding? = null - private val viewModel: PlanViewModel by viewModels() - private val binding get() = _binding!! + private var _binding: PlanSubjectListBinding? = null + private val viewModel: PlanViewModel by viewModels() + private val binding get() = _binding!! - override fun onCreateView( - inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? - ): View { - _binding = PlanSubjectListBinding.inflate(inflater, container, false) + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle? + ): View { + _binding = PlanSubjectListBinding.inflate(inflater, container, false) + binding.planSubjectListSemester.setOnClickListener{ + navigate(R.id.action_planTimeFragment_to_planSemesterFragment) + } + viewModel.getListTimeInfo() + val adapter = viewModel.listTimeInfo.value?.let { PlanRecyclerAdapter(it.result) } + binding.recyclerView.adapter = adapter + binding.recyclerView.layoutManager = + LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) - viewModel.getListTimeInfo() - val adapter = viewModel.listTimeInfo.value?.let { PlanRecyclerAdapter(it.result) } - binding.recyclerView.adapter = adapter - binding.recyclerView.layoutManager = - LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) + viewModel.listTimeInfo.observe(viewLifecycleOwner) { timenewList -> + if (timenewList != null) { + if (adapter != null) { + adapter.timeList=timenewList.result + adapter.notifyDataSetChanged() + } + } - viewModel.listTimeInfo.observe(viewLifecycleOwner) { timenewList -> - if (timenewList != null) { - if (adapter != null) { - adapter.timeList=timenewList.result - adapter.notifyDataSetChanged() - } - } + } - } + return binding.root + } - return binding.root - } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - binding.planSubjectListSemester.setOnClickListener { - findNavController().navigate(R.id.action_planTimeFragment_to_planSemesterFragment) - } - } - - - - - - - - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTrackFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTrackFragment.kt index 75f1bf6..be1cf89 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTrackFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanTrackFragment.kt @@ -16,6 +16,7 @@ import umc.com.mobile.project.databinding.FragmentPlanlicenseBinding import android.widget.EditText import androidx.core.view.setMargins import androidx.lifecycle.Observer +import umc.com.mobile.project.data.model.plan.SaveInfo import umc.com.mobile.project.data.model.plan.SavelicenseRequest import umc.com.mobile.project.data.model.plan.semesterResult import umc.com.mobile.project.databinding.PlanTimeChooseTrackBinding @@ -23,35 +24,35 @@ import umc.com.mobile.project.databinding.SemesterChooseBinding import java.time.LocalDate class PlanTrackFragment : Fragment() { - private var _binding: PlanTimeChooseTrackBinding? = null - private val viewModel: PlanViewModel by viewModels() - private val binding get() = _binding!! + private var _binding: PlanTimeChooseTrackBinding? = null + private val viewModel: PlanViewModel by viewModels() + private val binding get() = _binding!! - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = PlanTimeChooseTrackBinding.inflate(inflater, container, false) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = PlanTimeChooseTrackBinding.inflate(inflater, container, false) - return binding.root - } + return binding.root + } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) - } + } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } } diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanViewModel.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanViewModel.kt index 268e519..dc83956 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanViewModel.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanViewModel.kt @@ -10,6 +10,7 @@ import retrofit2.Callback import retrofit2.Response import umc.com.mobile.project.data.model.plan.BringlicenseResponse import umc.com.mobile.project.data.model.plan.ListTimeResponse +import umc.com.mobile.project.data.model.plan.PlanTrackResponse import umc.com.mobile.project.data.model.plan.SaveInfo import umc.com.mobile.project.data.model.plan.SavelicenseRequest @@ -22,204 +23,238 @@ import umc.com.mobile.project.data.network.api.PlanApi class PlanViewModel : ViewModel() { - //api - private val planApiService = ApiClient.createService() + //api + private val planApiService = ApiClient.createService() - private val _hakki: MutableLiveData = MutableLiveData() - val hakki: LiveData - get() = _hakki + private val _hakki: MutableLiveData = MutableLiveData() + val hakki: LiveData + get() = _hakki - private val _track: MutableLiveData = MutableLiveData() - val track: LiveData - get() = _track + private val _track: MutableLiveData = MutableLiveData() + val track: LiveData + get() = _track - private val _planSemesterInfo : MutableLiveData = MutableLiveData() - val planSemesterInfo :LiveData - get()=_planSemesterInfo + private val _planSemesterInfo : MutableLiveData = MutableLiveData() + val planSemesterInfo :LiveData + get()=_planSemesterInfo + private val _planTrackInfo : MutableLiveData = MutableLiveData() + val planTrackInfo :LiveData + get()=_planTrackInfo - private val _planTimeStatus: MutableLiveData = MutableLiveData() - val planTimeStatus: LiveData - get() = _planTimeStatus - private val _bringLicenseInfo = MutableLiveData() + private val _planTimeStatus: MutableLiveData = MutableLiveData() + val planTimeStatus: LiveData + get() = _planTimeStatus - - private val _listTimeInfo = MutableLiveData() - - val listTimeInfo: LiveData - get() = _listTimeInfo - - val bringLicenseInfo: LiveData - get() = _bringLicenseInfo - - - - - - private val _licenseInfo: MutableLiveData = MutableLiveData() - val licenseInfo: LiveData - get() = _licenseInfo + private val _bringLicenseInfo = MutableLiveData() - private val _error: MutableLiveData = MutableLiveData() - val error: LiveData - get() = _error - - - private val _savelicenseInfo : MutableLiveData =MutableLiveData() - val savelicenseInfo : LiveData - get()=_savelicenseInfo - - - // 기존에 있던 text LiveData - private val _text = MutableLiveData().apply { - value = "This is Plan Fragment" - } - val text: LiveData = _text - - // 새로 추가된 isFilledAllOptions LiveData - private val _isFilledAllOptions = MutableLiveData().apply { - value = false // 초기값 설정 - } - val isFilledAllOptions: LiveData = _isFilledAllOptions - - // isFilledAllOptions의 값을 업데이트하는 메서드 - fun updateIsFilledAllOptions(isFilled: Boolean) { - _isFilledAllOptions.value = isFilled - } - - - fun getListTimeInfo() { - _hakki.value?.let { - _track.value?.let { it1 -> - planApiService.getListTime(it, it1).enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.isSuccessful) { - if (response.body() != null) { - _listTimeInfo.postValue(response.body()) - Log.d("Planlicense", "${response.body()}") - } else { - _error.postValue("서버 응답이 올바르지 않습니다.") - } - } else { - _error.postValue("사용자 정보를 가져오지 못했습니다.") - try { - throw response.errorBody()?.string()?.let { - RuntimeException(it) - } ?: RuntimeException("Unknown error") - } catch (e: Exception) { - Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") - } - } - } - - override fun onFailure(call: Call, t: Throwable) { - _error.postValue("네트워크 오류: ${t.message}") - Log.d("gradInfo", "completion: ${t.message}") - } - }) - } - } - } - - - fun getLicenseInfo() { - planApiService.getUPlicense().enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.isSuccessful) { - if (response.body() != null) { - _licenseInfo.postValue(response.body()) - Log.d("Planlicense", "${response.body()}") - } else { - _error.postValue("서버 응답이 올바르지 않습니다.") - } - } else { - _error.postValue("사용자 정보를 가져오지 못했습니다.") - try { - throw response.errorBody()?.string()?.let { - RuntimeException(it) - } ?: RuntimeException("Unknown error") - } catch (e: Exception) { - Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") - } - } - } - - override fun onFailure(call: Call, t: Throwable) { - _error.postValue("네트워크 오류: ${t.message}") - Log.d("gradInfo", "completion: ${t.message}") - } - }) - } - - - fun saveLicense(request: List) { - - planApiService.saveLicense(request).enqueue(object : Callback { - override fun onResponse(call: Call, response: Response - ) { - if (response.isSuccessful) { - _bringLicenseInfo.postValue(response.body()) - Log.d("PlanViewModel", "License saved successfully: ${response.body()}") - } else { - _error.postValue("자격증 정보 저장 실패: ${response.errorBody()?.string()}") - Log.e( - "PlanViewModel", - "Error saving license: ${response.errorBody()?.string()}" - ) - } - } - - override fun onFailure(call: Call, t: Throwable) { - _error.postValue("네트워크 오류: ${t.message}") - Log.e("PlanViewModel", "Network error: ${t.message}") - } - }) - } - - - - fun getSemesterInfo() { - planApiService.getSemesterInfo().enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.isSuccessful) { - if (response.body() != null) { - _planSemesterInfo.postValue(response.body()) - Log.d("PlanSemester", "${response.body()}") - } else { - _error.postValue("서버 응답이 올바르지 않습니다.") - } - } else { - _error.postValue("사용자 정보를 가져오지 못했습니다.") - try { - throw response.errorBody()?.string()?.let { - RuntimeException(it) - } ?: RuntimeException("Unknown error") - } catch (e: Exception) { - Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") - } - } - } - - override fun onFailure(call: Call, t: Throwable) { - _error.postValue("네트워크 오류: ${t.message}") - Log.d("gradInfo", "completion: ${t.message}") - } - }) - } -} + private val _listTimeInfo = MutableLiveData() + + val listTimeInfo: LiveData + get() = _listTimeInfo + + val bringLicenseInfo: LiveData + get() = _bringLicenseInfo + + + + + + private val _licenseInfo: MutableLiveData = MutableLiveData() + val licenseInfo: LiveData + get() = _licenseInfo + + + private val _error: MutableLiveData = MutableLiveData() + val error: LiveData + get() = _error + + + private val _savelicenseInfo : MutableLiveData =MutableLiveData() + val savelicenseInfo : LiveData + get()=_savelicenseInfo + + + // 기존에 있던 text LiveData + private val _text = MutableLiveData().apply { + value = "This is Plan Fragment" + } + val text: LiveData = _text + + // 새로 추가된 isFilledAllOptions LiveData + private val _isFilledAllOptions = MutableLiveData().apply { + value = false // 초기값 설정 + } + val isFilledAllOptions: LiveData = _isFilledAllOptions + + // isFilledAllOptions의 값을 업데이트하는 메서드 + fun updateIsFilledAllOptions(isFilled: Boolean) { + _isFilledAllOptions.value = isFilled + } + + + fun getListTimeInfo() { + _hakki.value?.let { + _track.value?.let { it1 -> + planApiService.getListTime(it, it1).enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful) { + if (response.body() != null) { + _listTimeInfo.postValue(response.body()) + Log.d("Planlicense", "${response.body()}") + } else { + _error.postValue("서버 응답이 올바르지 않습니다.") + } + } else { + _error.postValue("사용자 정보를 가져오지 못했습니다.") + try { + throw response.errorBody()?.string()?.let { + RuntimeException(it) + } ?: RuntimeException("Unknown error") + } catch (e: Exception) { + Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + _error.postValue("네트워크 오류: ${t.message}") + Log.d("gradInfo", "completion: ${t.message}") + } + }) + } + } + } + + + fun getLicenseInfo() { + planApiService.getUPlicense().enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful) { + if (response.body() != null) { + _licenseInfo.postValue(response.body()) + Log.d("Planlicense", "${response.body()}") + } else { + _error.postValue("서버 응답이 올바르지 않습니다.") + } + } else { + _error.postValue("사용자 정보를 가져오지 못했습니다.") + try { + throw response.errorBody()?.string()?.let { + RuntimeException(it) + } ?: RuntimeException("Unknown error") + } catch (e: Exception) { + Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + _error.postValue("네트워크 오류: ${t.message}") + Log.d("gradInfo", "completion: ${t.message}") + } + }) + } + + + fun saveLicense(request: List) { + + planApiService.saveLicense(request).enqueue(object : Callback { + override fun onResponse(call: Call, response: Response + ) { + if (response.isSuccessful) { + _bringLicenseInfo.postValue(response.body()) + Log.d("PlanViewModel", "License saved successfully: ${response.body()}") + } else { + _error.postValue("자격증 정보 저장 실패: ${response.errorBody()?.string()}") + Log.e( + "PlanViewModel", + "Error saving license: ${response.errorBody()?.string()}" + ) + } + } + + override fun onFailure(call: Call, t: Throwable) { + _error.postValue("네트워크 오류: ${t.message}") + Log.e("PlanViewModel", "Network error: ${t.message}") + } + }) + } + + + + fun getSemesterInfo() { + planApiService.getSemesterInfo().enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.isSuccessful) { + if (response.body() != null) { + _planSemesterInfo.postValue(response.body()) + Log.d("PlanSemester", "${response.body()}") + } else { + _error.postValue("서버 응답이 올바르지 않습니다.") + } + } else { + _error.postValue("사용자 정보를 가져오지 못했습니다.") + try { + throw response.errorBody()?.string()?.let { + RuntimeException(it) + } ?: RuntimeException("Unknown error") + } catch (e: Exception) { + Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + _error.postValue("네트워크 오류: ${t.message}") + Log.d("gradInfo", "completion: ${t.message}") + } + }) + } + + + fun getTrackInfo(hakki: String) { + planApiService.getTrackInfo(hakki).enqueue(object : Callback { + override fun onResponse(call: Call, response: Response) { + if (response.isSuccessful) { + if (response.body() != null) { + _planTrackInfo.postValue(response.body()) + Log.d("PlanTrackInfo", "${response.body()}") + } else { + _error.postValue("서버 응답이 올바르지 않습니다.") + } + } else { + _error.postValue("사용자 정보를 가져오지 못했습니다.") + try { + throw response.errorBody()?.string()?.let { + RuntimeException(it) + } ?: RuntimeException("Unknown error") + } catch (e: Exception) { + Log.e("PlanInfo", "PlanResponse API 오류: ${e.message}") + } + } + } + + override fun onFailure(call: Call, t: Throwable) { + _error.postValue("네트워크 오류: ${t.message}") + Log.d("gradInfo", "completion: ${t.message}") + } + }) + } +} diff --git a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanlicenseFragment.kt b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanlicenseFragment.kt index 92f2d90..5ca427b 100644 --- a/app/src/main/java/umc/com/mobile/project/ui/plan/PlanlicenseFragment.kt +++ b/app/src/main/java/umc/com/mobile/project/ui/plan/PlanlicenseFragment.kt @@ -15,125 +15,125 @@ import umc.com.mobile.project.R import umc.com.mobile.project.databinding.FragmentPlanlicenseBinding class PlanlicenseFragment : Fragment() { - private var _binding: FragmentPlanlicenseBinding? = null - private val viewModel: PlanViewModel by viewModels() - private val binding get() = _binding!! + private var _binding: FragmentPlanlicenseBinding? = null + private val viewModel: PlanViewModel by viewModels() + private val binding get() = _binding!! - override fun onCreateView( - inflater: LayoutInflater, - container: ViewGroup?, - savedInstanceState: Bundle? - ): View { - _binding = FragmentPlanlicenseBinding.inflate(inflater, container, false) + override fun onCreateView( + inflater: LayoutInflater, + container: ViewGroup?, + savedInstanceState: Bundle? + ): View { + _binding = FragmentPlanlicenseBinding.inflate(inflater, container, false) - viewModel.getLicenseInfo() // api 연결 + viewModel.getLicenseInfo() // api 연결 - // UPlicenseResponse-자격증 정보 불러오기 - viewModel.licenseInfo.observe(viewLifecycleOwner) { licenseInfo -> - licenseInfo?.result?.let { resultList -> - // 첫 번째 Result 객체에 접근하여 데이터 매핑 - resultList.getOrNull(0)?.let { firstResult -> - binding.planLicenseName.setText(firstResult.name) - binding.planLicenseDate.setText(firstResult.date) - } + // UPlicenseResponse-자격증 정보 불러오기 + viewModel.licenseInfo.observe(viewLifecycleOwner) { licenseInfo -> + licenseInfo?.result?.let { resultList -> + // 첫 번째 Result 객체에 접근하여 데이터 매핑 + resultList.getOrNull(0)?.let { firstResult -> + binding.planLicenseName.setText(firstResult.name) + binding.planLicenseDate.setText(firstResult.date) + } - // 두 번째 Result 객체에 접근하여 데이터 매핑 - resultList.getOrNull(1)?.let { secondResult -> - binding.planLicenseName2.setText(secondResult.name) - binding.planLicenseDate2.setText(secondResult.date) + // 두 번째 Result 객체에 접근하여 데이터 매핑 + resultList.getOrNull(1)?.let { secondResult -> + binding.planLicenseName2.setText(secondResult.name) + binding.planLicenseDate2.setText(secondResult.date) - } + } - resultList.getOrNull(2)?.let { thirdResult -> - binding.planLicenseName3.setText(thirdResult.name) - binding.planLicenseDate3.setText(thirdResult.date) + resultList.getOrNull(2)?.let { thirdResult -> + binding.planLicenseName3.setText(thirdResult.name) + binding.planLicenseDate3.setText(thirdResult.date) - } + } - resultList.getOrNull(3)?.let { fourthResult -> - binding.planLicenseName4.setText(fourthResult.name) - binding.planLicenseDate4.setText(fourthResult.date) - } - } - } + resultList.getOrNull(3)?.let { fourthResult -> + binding.planLicenseName4.setText(fourthResult.name) + binding.planLicenseDate4.setText(fourthResult.date) + } + } + } - return binding.root - } + return binding.root + } - private fun submitData() { + private fun submitData() { - val name = binding.planLicenseName.text.toString() - val date = binding.planLicenseDate.text.toString() + val name = binding.planLicenseName.text.toString() + val date = binding.planLicenseDate.text.toString() - // SaveInfo 객체 리스트 생성 - val saveInfoList = listOf(SaveInfo(name, date)) + // SaveInfo 객체 리스트 생성 + val saveInfoList = listOf(SaveInfo(name, date)) - // SavelicenseRequest 객체 생성 + // SavelicenseRequest 객체 생성 - // API 호출 - viewModel.saveLicense(saveInfoList) + // API 호출 + viewModel.saveLicense(saveInfoList) - } + } - private fun setupEditTextListener(){ - val textWatcher = object : TextWatcher { - override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { - // 필요 없음 - } + private fun setupEditTextListener(){ + val textWatcher = object : TextWatcher { + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) { + // 필요 없음 + } - override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { - // 입력이 변경될 때마다 호출됩니다. - checkIfAnyInputIsFilled() - } + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { + // 입력이 변경될 때마다 호출됩니다. + checkIfAnyInputIsFilled() + } - override fun afterTextChanged(s: Editable?) { - // 필요 없음 - } - } - binding.planLicenseName.addTextChangedListener(textWatcher) - } + override fun afterTextChanged(s: Editable?) { + // 필요 없음 + } + } + binding.planLicenseName.addTextChangedListener(textWatcher) + } - private fun checkIfAnyInputIsFilled() { - val isAnyFieldFilled = binding.planLicenseName.text.trim().isNotEmpty() - //버튼 활성화 업데이트 - binding.licenseButtonStore.isEnabled = isAnyFieldFilled + private fun checkIfAnyInputIsFilled() { + val isAnyFieldFilled = binding.planLicenseName.text.trim().isNotEmpty() + //버튼 활성화 업데이트 + binding.licenseButtonStore.isEnabled = isAnyFieldFilled - // 버튼 색상도 업데이트 - val colorResId = if (isAnyFieldFilled) R.color.skyBlue else R.color.gray - val color = ContextCompat.getColor(requireContext(), colorResId) - binding.licenseButtonStore.backgroundTintList = ColorStateList.valueOf(color) + // 버튼 색상도 업데이트 + val colorResId = if (isAnyFieldFilled) R.color.skyBlue else R.color.gray + val color = ContextCompat.getColor(requireContext(), colorResId) + binding.licenseButtonStore.backgroundTintList = ColorStateList.valueOf(color) - } + } - override fun onViewCreated(view: View, savedInstanceState: Bundle?) { - super.onViewCreated(view, savedInstanceState) - setupEditTextListener() - checkIfAnyInputIsFilled() // 초기 상태 확인 - binding.licenseButtonStore.setOnClickListener { - submitData() // 사용자 입력을 기반으로 API 호출 - } + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + setupEditTextListener() + checkIfAnyInputIsFilled() // 초기 상태 확인 + binding.licenseButtonStore.setOnClickListener { + submitData() // 사용자 입력을 기반으로 API 호출 + } - } + } - override fun onDestroyView() { - super.onDestroyView() - _binding = null - } - } + override fun onDestroyView() { + super.onDestroyView() + _binding = null + } +} diff --git a/app/src/main/res/layout/fragment_planlicense.xml b/app/src/main/res/layout/fragment_planlicense.xml index 1524014..8e895b1 100644 --- a/app/src/main/res/layout/fragment_planlicense.xml +++ b/app/src/main/res/layout/fragment_planlicense.xml @@ -78,7 +78,7 @@ app:layout_gravity="fill" app:layout_rowWeight="1" android:gravity="center" - /> + /> - - - - - - - - - + + + + + + + + + + + + + - /> - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/layout/semester_choose.xml b/app/src/main/res/layout/semester_choose.xml index 6a2f4b4..7a4ae24 100644 --- a/app/src/main/res/layout/semester_choose.xml +++ b/app/src/main/res/layout/semester_choose.xml @@ -1,17 +1,10 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/navigation/mobile_navigation.xml b/app/src/main/res/navigation/mobile_navigation.xml index 8d3c430..0323287 100644 --- a/app/src/main/res/navigation/mobile_navigation.xml +++ b/app/src/main/res/navigation/mobile_navigation.xml @@ -233,12 +233,19 @@ android:name="umc.com.mobile.project.ui.setting.SettingNotificationFragment" android:label="@string/title_setting_notification" tools:layout="@layout/fragment_setting_notification" /> - + tools:layout="@layout/plan_time_tab_main" > + + + - + \ No newline at end of file