Skip to content

Commit

Permalink
refact: #35 inputVoice -> inputVoicePublisher 변경 및 코드 주석 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
TaekH committed Oct 8, 2023
1 parent aadd141 commit 2672a3f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion FREEWAY/FREEWAY/Presentation/BaseView/BaseViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class BaseViewModel {

// 입력된 데이터를 저장하는 BehaviorSubject
let inputText = BehaviorSubject<String>(value: "")
let inputVoice = PassthroughSubject<String, Never>()
let inputVoicePublisher = PassthroughSubject<String, Never>()
//TODO: MapsViewController의 ViewModel에 들어갈 부분
let searchPublisher = PassthroughSubject<String, Never>()
let inputTextPublisher = PassthroughSubject<String, Never>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ final class HomeViewController: UIViewController {
}

private func bind() {
viewModel.inputVoice.withRetained(self)
viewModel.inputVoicePublisher.withRetained(self)
.sink { `self`, resultText in
self.voiceSearchLottieView.resultTextLabel.text = resultText
}.store(in: &cancelBag)
Expand Down
23 changes: 12 additions & 11 deletions FREEWAY/FREEWAY/Presentation/SearchView/SearchViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ final class SearchViewController: UIViewController {
@objc func backButtonPressed(_ sender: UIButton) {
self.navigationController?.popViewController(animated: true)
}

//TODO: Combine으로 상태 수정
@objc func voiceButtonPressed(_ sender: UIButton) {
searchListViewModule.view.isHidden = true
setupLottieLayout()
Expand All @@ -91,12 +91,13 @@ final class SearchViewController: UIViewController {
self.voiceRecognitionManager.stopRecognition()
self.searchTextFieldView.voiceImage = "mic.fill"
self.voiceSearchLottieView.removeFromSuperview()
//TODO: 옵셔널 타입 제거 강남으로 이동하지 못하도록 설정
self.navigateToMapsViewControllerIfNeeded(self.viewModel.getStationName() ?? "강남")
}
}

private func bind() {
viewModel.inputVoice.withRetained(self)
viewModel.inputVoicePublisher.withRetained(self)
.sink { `self`, resultText in
self.voiceSearchLottieView.resultTextLabel.text = resultText
}.store(in: &cancelBag)
Expand Down Expand Up @@ -199,7 +200,15 @@ extension SearchViewController: UITextFieldDelegate {
viewModel.inputTextPublisher.send(textField.text ?? "")
}
}


func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if let searchText = textField.text {
navigateToMapsViewControllerIfNeeded(searchText)
}
return true
}
//MARK: UITextFieldDelegate와는 관련 없지만 사용되는 로직

//TODO: 추후 AlertManager로 들어갈 부분
private func showInvalidStationNameAlert() {
let alert = UIAlertController(title: "역 이름을 다시 한 번 확인해주세요!", message: "", preferredStyle: .alert)
Expand All @@ -219,14 +228,6 @@ extension SearchViewController: UITextFieldDelegate {
showInvalidStationNameAlert()
}
}

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
if let searchText = textField.text {
navigateToMapsViewControllerIfNeeded(searchText)
}
return true
}

}

extension SearchViewController: UITableViewDelegate {
Expand Down
2 changes: 1 addition & 1 deletion FREEWAY/FREEWAY/Services/VoiceRecognitionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class VoiceRecognitionManager: NSObject, SFSpeechRecognizerDelegate {
guard let self = self else { return }
if let result = result {
self.resultText = result.bestTranscription.formattedString
self.viewModel?.inputVoice.send(self.resultText ?? "")
self.viewModel?.inputVoicePublisher.send(self.resultText ?? "")
self.viewModel?.updateText(self.resultText)
self.delegate?.didRecognizeVoice(text: self.resultText ?? "")
}
Expand Down

0 comments on commit 2672a3f

Please sign in to comment.