Skip to content

Commit

Permalink
#297: Share ViewController의 '원하는 음악이 아닌가요' 클릭 시, 재검색 화면 나타내고 유튜브뮤직에서…
Browse files Browse the repository at this point in the history
… 공유된 곡이름 통해 검색 및 테이블 뷰 데이터들 나타냄
  • Loading branch information
joseph704 committed Aug 16, 2024
1 parent a903076 commit f147371
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
33 changes: 32 additions & 1 deletion StreetDrop/ShareExtension/View/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import SafariServices
import Kingfisher
import RxSwift
import RxRelay
import RxGesture
import SnapKit

final class ShareViewController: UIViewController {
Expand Down Expand Up @@ -196,6 +197,17 @@ final class ShareViewController: UIViewController {
return button
}()

private let reSearchingMusicForSharingView: ReSearchingMusicForSharingView = {
let reSearchingMusicForSharingView: ReSearchingMusicForSharingView = .init()
reSearchingMusicForSharingView.isHidden = true
reSearchingMusicForSharingView.backgroundColor = .gray800
reSearchingMusicForSharingView.layer.cornerRadius = 20
reSearchingMusicForSharingView.layer.borderWidth = 1
reSearchingMusicForSharingView.layer.borderColor = UIColor.gray600.cgColor

return reSearchingMusicForSharingView
}()

override func viewDidLoad() {
super.viewDidLoad()
bindAction()
Expand Down Expand Up @@ -291,7 +303,8 @@ private extension ShareViewController {
func bindViewModel() {
let input: ShareViewModel.Input = .init(
viewDidLoadEvent: .just(Void()),
sharedMusicKeyWordEvent: sharedMusicKeyWordEvent.asObservable()
sharedMusicKeyWordEvent: sharedMusicKeyWordEvent.asObservable(),
changingMusicViewClickEvent: changingMusicView.rx.tapGesture().asObservable().mapVoid()
)
let output: ShareViewModel.Output = viewModel.convert(
input: input,
Expand All @@ -311,17 +324,34 @@ private extension ShareViewController {
owner.artistNameLabel.text = music.artistName
}
.disposed(by: disposeBag)

output.showReSearchedMusicList
.bind(with: self) { owner, musicList in
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { [weak self] in
guard let self = self else { return }
containerView.isHidden = true
reSearchingMusicForSharingView.isHidden = false
view.layoutIfNeeded()
})
owner.reSearchingMusicForSharingView.settingMusicDataRelay.accept(musicList)
}
.disposed(by: disposeBag)
}

func configureUI() {
view.addSubview(containerView)
view.addSubview(reSearchingMusicForSharingView)
view.backgroundColor = UIColor.black.withAlphaComponent(0.5)

containerView.snp.makeConstraints {
$0.height.equalTo(596)
$0.horizontalEdges.bottom.equalToSuperview()
}

reSearchingMusicForSharingView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

[
dropButton,
villageNameLabel,
Expand Down Expand Up @@ -440,6 +470,7 @@ private extension ShareViewController {

fetchVideoDetails(videoID: videoID) { [weak self] songName, artistName in
self?.sharedMusicKeyWordEvent.accept("\(songName ?? "")-\(artistName ?? "")")
self?.viewModel.sharedSongName = songName ?? ""
}
}

Expand Down
19 changes: 19 additions & 0 deletions StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ final class ShareViewModel: NSObject, ShareViewModelType {
private let locationManger: CLLocationManager = .init()
private let searchMusicUsecase: SearchMusicUsecase
private let disposeBag: DisposeBag = .init()
var sharedSongName: String = ""

init(searchMusicUsecase: SearchMusicUsecase = DefaultSearchingMusicUsecase()) {
self.searchMusicUsecase = searchMusicUsecase
Expand All @@ -31,6 +32,7 @@ final class ShareViewModel: NSObject, ShareViewModelType {
struct Input {
let viewDidLoadEvent: Observable<Void>
let sharedMusicKeyWordEvent: Observable<String>
let changingMusicViewClickEvent: Observable<Void>
}

struct Output {
Expand All @@ -42,6 +44,10 @@ final class ShareViewModel: NSObject, ShareViewModelType {
var showSearchedMusic: Observable<Music> {
showSearchedMusicRelay.asObservable()
}
fileprivate let showReSearchedMusicListRelay: PublishRelay<[Music]> = .init()
var showReSearchedMusicList: Observable<[Music]> {
showReSearchedMusicListRelay.asObservable()
}
}

func convert(input: Input, disposedBag: DisposeBag) -> Output {
Expand Down Expand Up @@ -69,6 +75,19 @@ final class ShareViewModel: NSObject, ShareViewModelType {
}
.disposed(by: disposedBag)

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)

}
.disposed(by: disposedBag)

return output
}
}
Expand Down

0 comments on commit f147371

Please sign in to comment.