Skip to content

Commit

Permalink
저장한 질문 취소하기 기능 완성
Browse files Browse the repository at this point in the history
  • Loading branch information
kichan05 committed Feb 12, 2022
1 parent 447d1b7 commit 4c23552
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class QnASliderActivity : BaseActivity<ActivityQnaSliderBinding>(R.layout.activi
btnQnaShare.setOnClickListener{ shareQuestion(this@QnASliderActivity, getCurrentQuestion()!!) }

btnQnaSaveQuestion.setOnClickListener { saveQuestion(getCurrentQuestion()!!) }

btnQnaRemoveQuestion.setOnClickListener { removeQuestion(getCurrentQuestion()!!) }
}

// viewModel.isCurrentQnASave.observe(this){
Expand All @@ -54,5 +56,10 @@ class QnASliderActivity : BaseActivity<ActivityQnaSliderBinding>(R.layout.activi
Toast.makeText(this, "질문을 추가했습니다.", Toast.LENGTH_LONG).show()
}

fun removeQuestion(questionData: Question) {
viewModel.removeQuestion(questionData)
Toast.makeText(this, "질문을 저장을 취소했습니다.", Toast.LENGTH_LONG).show()
}

fun getCurrentQuestion() = viewModel.getCurrentQuestion()
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ class QnASliderViewModel : ViewModel() {
}
}

fun removeQuestion(questionData: Question) {
viewModelScope.launch(Dispatchers.IO){
saveQuestionDB.questionDao().deleteQuestion(questionData.question)

val temp_list = saveQnaList.filter { it.question != questionData.question }
saveQnaList.clear()
saveQnaList.addAll(temp_list)

withContext(Dispatchers.Main){ saveQuestionListIncludeCurrentQuestion() }

// Log.d("delete", "삭제함 ${saveQuestionDB.questionDao().getAll().toList()}")
}
}

fun getCurrentQuestion() : Question? {
return if(0 <= currentPage && currentPage < questionList.size)
(questionList[currentPage] as QnAFragment).question
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ interface QuestionDao {

@Delete
fun delete(question: Question)

@Query("DELETE FROM save_questions WHERE question = :question")
fun deleteQuestion(question : String)
}

0 comments on commit 4c23552

Please sign in to comment.