Skip to content

Commit

Permalink
[Refac/#89] 답변확인 화면 데이터바인딩 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
ss99x2002 committed Jul 19, 2023
1 parent 26c2c73 commit 6b0d024
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ class ConfirmAnswerDialogFragment : DialogFragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
viewModel.setDataFromBundle(Bundle())
setBackgroundDesign()
setPreviewAnswer()
setBtnClickEvent()
observeResponseStatus()
}
Expand All @@ -51,15 +51,6 @@ class ConfirmAnswerDialogFragment : DialogFragment() {
}
}

private fun setPreviewAnswer() {
with(binding) {
tvAnswer.text = arguments?.getString("answer")
tvTopic.text = arguments?.getString("topic")
tvSection.text = arguments?.getString("section")
tvQuestion.text = arguments?.getString("question")
}
}

private fun setBackgroundDesign() {
dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package com.sopt.umbba_android.presentation.qna.viewmodel
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.sopt.umbba_android.data.entity.AnswerIntentResponse

class AnswerViewModel : ViewModel() {
var answer = MutableLiveData<String>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.sopt.umbba_android.presentation.qna.viewmodel

import android.os.Bundle
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
Expand All @@ -12,6 +13,18 @@ class ConfirmAnswerDialogFragmentViewModel(private val questionAnswerRepositoryI
ViewModel() {

var responseStatus = MutableLiveData<Int>()
var answer = MutableLiveData<String>()
var question = MutableLiveData<String>()
var section = MutableLiveData<String>()
var topic = MutableLiveData<String>()

fun setDataFromBundle(bundle: Bundle) {
answer.value = bundle.getString("answer")
question.value = bundle.getString("question")
section.value = bundle.getString("section")
topic.value = bundle.getString("topic")
}

fun postAnswer(answerRequestDto: AnswerRequestDto) {
viewModelScope.launch {
questionAnswerRepositoryImpl.postAnswer(answerRequestDto)
Expand Down
13 changes: 8 additions & 5 deletions app/src/main/res/layout/fragment_confirm_answer_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
xmlns:tools="http://schemas.android.com/tools">

<data>

<variable
name="vm"
type="com.sopt.umbba_android.presentation.qna.viewmodel.ConfirmAnswerDialogFragmentViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -35,7 +37,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="어린 시절" />
android:text="@{vm.section}" />

</androidx.constraintlayout.widget.ConstraintLayout>

Expand All @@ -49,19 +51,20 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cl_section"
tools:text="#1 가장 오래된 기억" />
android:text="@{vm.topic}" />

<TextView
android:id="@+id/tv_question"
style="@style/AndroidSubHead1SemiBold20"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:textColor="@color/umbba_black"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_topic"
tools:text="당신과 어머니의 꿈은 달라?" />
android:text="@{vm.question}" />

<TextView
android:id="@+id/tv_answer"
Expand All @@ -75,7 +78,7 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_question"
tools:text="@string/content_example" />
android:text="@{vm.answer}" />

<TextView
android:id="@+id/tv_save_answer"
Expand Down

0 comments on commit 6b0d024

Please sign in to comment.