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 fa5b115 commit c0e6466
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,42 +62,18 @@ class QuestionAnswerActivity :

private fun observeListQnaResponse() {
viewModel.listQnaResponse.observe(this@QuestionAnswerActivity) {
setListQnaData(it)
setBtnEnable(true)
}
}

private fun observeQnaResponse() {
viewModel.qnaResponse.observe(this@QuestionAnswerActivity) {
setQnaData(it)
setAnswerText(it)
setClickEvent(it)
setBtnEnable(it.isMyAnswer)
}
}

private fun setListQnaData(data: ListQuestionAnswerResponseDto.QnaData) {
with(binding) {
layoutAppbar.titleText = data.section
tvTopic.text = "#${data.index} ${data.topic}"
tvQuestionMe.text = data.myQuestion
tvQuestionOther.text = data.opponentQuestion
tvFromOther.text = data.opponentUsername
tvFromMe.text = data.myUsername
}
}

private fun setQnaData(data: QuestionAnswerResponseDto.QnaData) {
with(binding) {
layoutAppbar.titleText = data.section
tvTopic.text = "#${data.index} ${data.topic}"
tvQuestionMe.text = data.myQuestion
tvQuestionOther.text = data.opponentQuestion
tvFromOther.text = data.opponentUsername
tvFromMe.text = data.myUsername
}
}

private fun setAnswerText(data: QuestionAnswerResponseDto.QnaData) {
with(binding) {
if (data.isOpponentAnswer == true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class QuestionAnswerViewModel(private val questionAnswerRepositoryImpl: Question

var isBeforeList = MutableLiveData<Boolean?>()

private var _sectionTitle = MutableLiveData<String>()
val sectionTitle: LiveData<String> = _sectionTitle

private var _isEnableBtn = MutableLiveData<Boolean>()
val isEnableBtn: LiveData<Boolean> = _isEnableBtn

fun getQuestionAnswer() {
viewModelScope.launch {
questionAnswerRepositoryImpl.getQuestionAnswer()
Expand All @@ -33,6 +39,7 @@ class QuestionAnswerViewModel(private val questionAnswerRepositoryImpl: Question
_qnaResponse.value = response.data
isMyAnswer.value = response.data.isMyAnswer
isOpponentAnswer.value = response.data.isOpponentAnswer
_sectionTitle.value = "#${response.data.index} ${response.data.section}"
appbarSection.value = response.data.section.toString()
}.onFailure { error ->
Log.e("hyeon", "getQuestionAnswer 실패 " + error.message)
Expand All @@ -46,6 +53,7 @@ class QuestionAnswerViewModel(private val questionAnswerRepositoryImpl: Question
.onSuccess { response ->
_listQnaResponse.value = response.data
appbarSection.value = response.data.section.toString()
_sectionTitle.value = "#${response.data.index} ${response.data.section}"
Log.e("hyeon", "getListQuestionAnswer 성공")
}.onFailure { error ->
Log.e("hyeon", "getListQuestionAnswer 실패" + error.message)
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/layout/activity_question_answer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/answer_title"
android:text="@{vm.sectionTitle}"
android:textAppearance="@style/BrandTypeBigRegular20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -52,7 +52,7 @@
android:layout_height="wrap_content"
android:layout_marginHorizontal="28dp"
android:layout_marginTop="32dp"
tool:text ="할머니와 엄마의 꿈은 달라?"
android:text="@{vm.isBeforeList ? vm.listQnaResponse.opponentQuestion : vm.qnaResponse.opponentQuestion}"
android:textAppearance="@style/AndroidSubHead1SemiBold20"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand Down Expand Up @@ -87,7 +87,7 @@
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginBottom="16dp"
android:text="@string/question_answer_from_mom"
android:text="@{vm.isBeforeList ? vm.listQnaResponse.opponentUsername : vm.qnaResponse.opponentUsername}"
android:textAppearance="@style/BrandTypeSmallSemiBold16"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent" />
Expand All @@ -99,7 +99,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="43dp"
android:layout_marginHorizontal="28dp"
android:text="@string/question_answer_quesiton_me"
android:text="@{vm.isBeforeList ? vm.listQnaResponse.myQuestion : vm.qnaResponse.myQuestion}"
android:gravity="right"
app:layout_constraintStart_toStartOf="parent"
android:textAppearance="@style/AndroidSubHead1SemiBold20"
Expand Down Expand Up @@ -135,7 +135,7 @@
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="@string/question_answer_from_me"
android:text="@{vm.isBeforeList ? vm.listQnaResponse.myUsername : vm.qnaResponse.myUsername}"
android:textAppearance="@style/BrandTypeSmallSemiBold16"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
Expand Down

0 comments on commit c0e6466

Please sign in to comment.