Skip to content

Commit

Permalink
#297: Share Extension의 음악 재검색 시, 음악 검색 비즈니스로직 수행 및 결과값 재검색 테이블 뷰에 나타냄
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph704 committed Aug 16, 2024
1 parent f147371 commit f3e6367
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class ReSearchingMusicForSharingView: UIView {

override init(frame: CGRect) {
super.init(frame: frame)
bindAction()
bindData()
configureUI()
}
Expand Down Expand Up @@ -114,6 +115,21 @@ final class ReSearchingMusicForSharingView: UIView {
}

private extension ReSearchingMusicForSharingView {
func bindAction() {
searchTextField.rx.text.orEmpty
.filter { $0.isEmpty }
.map { _ in }
.bind(with: self) { owner, _ in
owner.settingMusicDataRelay.accept([])
}
.disposed(by: disposeBag)

searchTextField.rx.controlEvent(.editingDidEndOnExit)
.compactMap { [weak self] in self?.searchTextField.text ?? "" }
.bind(to: reSearchingEventRelay)
.disposed(by: disposeBag)
}

func bindData() {
settingMusicDataRelay
.bind(
Expand Down
3 changes: 2 additions & 1 deletion StreetDrop/ShareExtension/View/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,8 @@ private extension ShareViewController {
let input: ShareViewModel.Input = .init(
viewDidLoadEvent: .just(Void()),
sharedMusicKeyWordEvent: sharedMusicKeyWordEvent.asObservable(),
changingMusicViewClickEvent: changingMusicView.rx.tapGesture().asObservable().mapVoid()
changingMusicViewClickEvent: changingMusicView.rx.tapGesture().asObservable().mapVoid(),
reSearchingEvent: reSearchingMusicForSharingView.reSearchingEvent
)
let output: ShareViewModel.Output = viewModel.convert(
input: input,
Expand Down
28 changes: 20 additions & 8 deletions StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ final class ShareViewModel: NSObject, ShareViewModelType {
let viewDidLoadEvent: Observable<Void>
let sharedMusicKeyWordEvent: Observable<String>
let changingMusicViewClickEvent: Observable<Void>
let reSearchingEvent: Observable<String>
}

struct Output {
Expand Down Expand Up @@ -77,21 +78,32 @@ final class ShareViewModel: NSObject, ShareViewModelType {

input.changingMusicViewClickEvent
.bind(with: self) { owner, _ in
owner.searchMusicUsecase.searchMusic(keyword: owner.sharedSongName)
.subscribe(with: self) { owner, musicList in
owner.output.showReSearchedMusicListRelay.accept(musicList)
} onFailure: { owner, error in
// TODO: 요셉, 실패 팝업 띄우기
}
.disposed(by: disposedBag)

owner.reSearchMusic(keyword: owner.sharedSongName, disposeBag: disposedBag)
}
.disposed(by: disposedBag)

input.reSearchingEvent
.bind(with: self) { owner, reSearchingKeyword in
owner.reSearchMusic(keyword: reSearchingKeyword, disposeBag: disposedBag)
}
.disposed(by: disposedBag)

return output
}
}

private extension ShareViewModel {
func reSearchMusic(keyword: String, disposeBag: DisposeBag) {
searchMusicUsecase.searchMusic(keyword: keyword)
.subscribe(with: self) { owner, musicList in
owner.output.showReSearchedMusicListRelay.accept(musicList)
} onFailure: { owner, error in
// TODO: 요셉, 실패 팝업 띄우기
}
.disposed(by: disposeBag)
}
}

extension ShareViewModel: CLLocationManagerDelegate {
func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
guard let location = locations.last else { return }
Expand Down

0 comments on commit f3e6367

Please sign in to comment.