Skip to content

Commit

Permalink
[Feat/#63] confirmDialog ViewModel 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
ss99x2002 committed Jul 15, 2023
1 parent 27810e3 commit 288a678
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import androidx.activity.viewModels
import androidx.lifecycle.viewModelScope
import com.sopt.umbba_android.R
import com.sopt.umbba_android.databinding.ActivityAnswerBinding
import com.sopt.umbba_android.util.ViewModelFactory
import com.sopt.umbba_android.util.binding.BindingActivity
import timber.log.Timber

class AnswerActivity : BindingActivity<ActivityAnswerBinding>(R.layout.activity_answer),
View.OnClickListener {
private val answerViewModel by viewModels<AnswerViewModel>()
private val answerViewModel:AnswerViewModel by viewModels { ViewModelFactory(this) }
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding.clickListener = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import androidx.activity.viewModels
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.viewModels
import com.sopt.umbba_android.R
import com.sopt.umbba_android.data.model.request.AnswerRequestDto
import com.sopt.umbba_android.databinding.FragmentConfirmAnswerDialogBinding
import com.sopt.umbba_android.util.ViewModelFactory
import timber.log.Timber

class ConfirmAnswerDialogFragment : DialogFragment() {

private var _binding: FragmentConfirmAnswerDialogBinding? = null
private val confirmAnswerDialogViewModel by viewModels<ConfirmAnswerDialogFragmentViewModel>()
private val answerViewModel: ConfirmAnswerDialogFragmentViewModel by viewModels { ViewModelFactory(requireActivity()) }
private val binding get() = requireNotNull(_binding) { "ConfirmAnswerDialogFragment is null" }

override fun onCreateView(
Expand Down Expand Up @@ -56,8 +59,7 @@ class ConfirmAnswerDialogFragment : DialogFragment() {
}
btnConfirm.setOnClickListener {
dismiss()
//TODO(저장 완하고 문답화면으로 돌아가는 로직 고고)
confirmAnswerDialogViewModel.postAnswer(tvAnswer.text.toString())
answerViewModel.postAnswer(AnswerRequestDto(arguments?.getString("answer")!!))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package com.sopt.umbba_android.presentation.qna

import android.util.Log
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.sopt.umbba_android.data.model.request.AnswerRequestDto
import com.sopt.umbba_android.data.repository.QuestionAnswerRepositoryImpl
import kotlinx.coroutines.launch

class ConfirmAnswerDialogFragmentViewModel : ViewModel() {
fun postAnswer(answer: String) {
//TODO(post Repo로 가는 함수 가보자고.)
class ConfirmAnswerDialogFragmentViewModel(private val questionAnswerRepositoryImpl: QuestionAnswerRepositoryImpl) : ViewModel() {
fun postAnswer(answerRequestDto: AnswerRequestDto) {
viewModelScope.launch {
questionAnswerRepositoryImpl.postAnswer(answerRequestDto)
.onSuccess {
Log.e("hyeon", "postAnswer 성공")
}.onFailure { error ->
Log.e("hyeon", "postAnswer 실패 " + error.message)
}
}
}
}

0 comments on commit 288a678

Please sign in to comment.