Skip to content

Commit

Permalink
♻️ [refactor] AppCoordinator 내부 기능 분리 및 리팩토링 #20
Browse files Browse the repository at this point in the history
- 기존에 음악을 함께 초이스하던 부분을 제거하고 오로지 뷰 컨트롤러만 띄우도록 개선
- MusicPlayerManager 내부에 플레이어 재생중 상태를 변경할 수 있는 기능 추가
- choice 내부 파라미터 타입 변경 및 로직 수정
  • Loading branch information
leeari95 committed Jul 23, 2022
1 parent a900b84 commit 60d4297
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,12 @@ final class AppCoordinator: Coordinator {
rootViewController.addChild(viewController)
}

func showMusicPlayer(_ viewController: PlayerViewController, item: Item) {
func showPlayerViewController() {
guard playerViewController == nil else {
MusicPlayerManager.shared.choice(item)
playerViewController?.view.isHidden = false
return
}
let viewController = PlayerViewController()
playerViewController = viewController
rootViewController.view.addSubviews(viewController.view)
rootViewController.view.bringSubviewToFront(rootViewController.tabBar)
Expand All @@ -82,7 +82,6 @@ final class AppCoordinator: Coordinator {
$0
])
}
MusicPlayerManager.shared.choice(item)
}

func minimize() {
Expand All @@ -104,6 +103,5 @@ final class AppCoordinator: Coordinator {

func removePlayerViewController() {
playerViewController?.view.isHidden = true
MusicPlayerManager.shared.close()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,15 @@ final class ItemDetailViewModel {
.subscribe(onNext: { _ in
if let coordinator = self.coordinator as? CatalogCoordinator {
let coordinator = coordinator.parentCoordinator as? AppCoordinator
coordinator?.showMusicPlayer(PlayerViewController(), item: self.item)
coordinator?.showPlayerViewController()
} else if let coordinator = self.coordinator as? DashboardCoordinator {
let coordinator = coordinator.parentCoordinator as? AppCoordinator
coordinator?.showMusicPlayer(PlayerViewController(), item: self.item)
coordinator?.showPlayerViewController()
} else if let coordinator = self.coordinator as? CollectionCoordinator {
let coordinator = coordinator.parentCoordinator as? AppCoordinator
coordinator?.showMusicPlayer(PlayerViewController(), item: self.item)
coordinator?.showPlayerViewController()
}
MusicPlayerManager.shared.choice(self.item)
}).disposed(by: disposeBag)

Items.shared.itemList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ extension MusicPlayerManager {
isPlaying.accept(isPlaying.value == true ? false : true)
}

func updatePlayingState(to isNotPlaying: Bool) {
isPlaying.accept(isNotPlaying)
}

func updatePlayerMode(to mode: PlayerMode) {
switch mode {
case .shuffle:
Expand All @@ -287,15 +291,14 @@ extension MusicPlayerManager {
changeSong(at: -1)
}

func choice(_ item: Item) {
func choice(_ item: Item?) {
close()
currentSong.accept(item)
isPlaying.accept(true)
setUpNotification()
}

func close() {
player = nil
isPlaying.accept(false)
elapsedTime.accept("0:00")
durationTime.accept("0:00")
Expand Down

0 comments on commit 60d4297

Please sign in to comment.