From c7f72b0d1b6a5e56a5f7f948a2268e9f20319b98 Mon Sep 17 00:00:00 2001 From: Joseph Cha Date: Mon, 19 Aug 2024 13:20:53 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8#297:=20Share=20Extension=EC=97=90?= =?UTF-8?q?=EC=84=9C=20=EC=9E=AC=EA=B2=80=EC=83=89=20=ED=99=94=EB=A9=B4?= =?UTF-8?q?=EC=9D=98=20=EC=9B=90=ED=95=98=EB=8A=94=20=ED=85=8C=EC=9D=B4?= =?UTF-8?q?=EB=B8=94=EB=B7=B0=20=EC=85=80=20=ED=81=B4=EB=A6=AD=20=EC=8B=9C?= =?UTF-8?q?,=20=ED=81=B4=EB=A6=AD=ED=95=9C=20=EC=85=80=EC=9D=98=20?= =?UTF-8?q?=EC=9D=8C=EC=95=85=20=EC=A0=95=EB=B3=B4=20=EC=9D=B4=EC=A0=84=20?= =?UTF-8?q?=ED=99=94=EB=A9=B4=EC=9D=98=20=EC=A0=95=EB=B3=B4=EB=A1=9C=20?= =?UTF-8?q?=EA=B8=B0=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ReSearchingMusicForSharingView.swift | 11 ++++++++++- .../ShareExtension/View/ShareViewController.swift | 14 ++++++++++++++ .../ShareExtension/ViewModel/ShareViewModel.swift | 2 ++ 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift b/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift index 92b4e70..2db63a5 100644 --- a/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift +++ b/StreetDrop/ShareExtension/View/ReSearchingMusic/ReSearchingMusicForSharingView.swift @@ -12,11 +12,16 @@ import RxRelay import SnapKit final class ReSearchingMusicForSharingView: UIView { - private let reSearchingEventRelay: PublishRelay = .init() // View -> ViewController + private let reSearchingEventRelay: PublishRelay = .init() var reSearchingEvent: Observable { reSearchingEventRelay.asObservable() } + private let selectedMusicEventRelay: PublishRelay = .init() + var selectedMusicEvent: Observable { + selectedMusicEventRelay.asObservable() + } + // ViewController -> View let settingMusicDataRelay: PublishRelay<[Music]> = .init() private let disposeBag: DisposeBag = .init() @@ -128,6 +133,10 @@ private extension ReSearchingMusicForSharingView { .compactMap { [weak self] in self?.searchTextField.text ?? "" } .bind(to: reSearchingEventRelay) .disposed(by: disposeBag) + + tableView.rx.modelSelected(Music.self) + .bind(to: selectedMusicEventRelay) + .disposed(by: disposeBag) } func bindData() { diff --git a/StreetDrop/ShareExtension/View/ShareViewController.swift b/StreetDrop/ShareExtension/View/ShareViewController.swift index dabc922..8bc18a9 100644 --- a/StreetDrop/ShareExtension/View/ShareViewController.swift +++ b/StreetDrop/ShareExtension/View/ShareViewController.swift @@ -298,6 +298,20 @@ private extension ShareViewController { } .disposed(by: disposeBag) + reSearchingMusicForSharingView.selectedMusicEvent + .bind(with: self) { owner, music in + owner.viewModel.selectedMusic = music + owner.albumCoverImageView.kf.setImage(with: URL(string: music.albumImage)) + owner.songNameLabel.text = music.songName + owner.artistNameLabel.text = music.artistName + DispatchQueue.main.asyncAfter(deadline: .now() + 0.3, execute: { [weak self] in + guard let self = self else { return } + containerView.isHidden = false + reSearchingMusicForSharingView.isHidden = true + view.layoutIfNeeded() + }) + } + .disposed(by: disposeBag) } func bindViewModel() { diff --git a/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift b/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift index 5cf881d..8d69d85 100644 --- a/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift +++ b/StreetDrop/ShareExtension/ViewModel/ShareViewModel.swift @@ -24,6 +24,7 @@ final class ShareViewModel: NSObject, ShareViewModelType { private let searchMusicUsecase: SearchMusicUsecase private let disposeBag: DisposeBag = .init() var sharedSongName: String = "" + var selectedMusic: Music? init(searchMusicUsecase: SearchMusicUsecase = DefaultSearchingMusicUsecase()) { self.searchMusicUsecase = searchMusicUsecase @@ -69,6 +70,7 @@ final class ShareViewModel: NSObject, ShareViewModelType { return } owner.output.showSearchedMusicRelay.accept(firstMusic) + owner.selectedMusic = firstMusic } onFailure: { owner, error in }