Skip to content

Commit

Permalink
Merge pull request #1242 from wakmusic/1215-unnamed-playlist-naming
Browse files Browse the repository at this point in the history
🔀 :: (#1215) 노래 리스트 재생 시 Unnamed Playlist에 이름 지정
  • Loading branch information
baekteun authored Aug 27, 2024
2 parents 923bbfb + a1654ec commit 6f33b0a
Show file tree
Hide file tree
Showing 14 changed files with 64 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ extension ArtistMusicContentViewController: SongCartViewDelegate {
)
PlayState.shared.loadAndAppendSongsToPlaylist(songs)
input.allSongSelected.onNext(false)
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: "왁타버스 뮤직").play()

default: return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ private extension ChartContentViewController {

output.groupPlaySongs
.bind(with: self, onNext: { owner, source in
guard !source.isEmpty else {
guard !source.songs.isEmpty else {
owner.output.showToast.onNext("차트 데이터가 없습니다.")
return
}
PlayState.shared.loadAndAppendSongsToPlaylist(source)
WakmusicYoutubePlayer(ids: source.map { $0.id }).play()
PlayState.shared.loadAndAppendSongsToPlaylist(source.songs)
WakmusicYoutubePlayer(ids: source.songs.map { $0.id }, title: source.playlistTitle).play()
})
.disposed(by: disposeBag)

Expand Down Expand Up @@ -303,7 +303,7 @@ extension ChartContentViewController: SongCartViewDelegate {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .chart, type: .multiple)
)
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: "왁타버스 뮤직").play()

case .remove:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ public protocol ChartPlayPopupViewControllerDelegate: AnyObject {
public enum HalfPlayType {
case front
case back

var playlistTitleString: String {
switch self {
case .front:
return "왁뮤차트 TOP100 1위 ~ 50위"
case .back:
return "왁뮤차트 TOP100 51위 ~ 100위"
}
}
}

final class ChartPlayPopupViewController: UIViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public final class ChartContentViewModel: ViewModelType {
let updateTime: BehaviorRelay<String> = BehaviorRelay(value: "")
let indexOfSelectedSongs: BehaviorRelay<[Int]> = BehaviorRelay(value: [])
let songEntityOfSelectedSongs: BehaviorRelay<[SongEntity]> = BehaviorRelay(value: [])
let groupPlaySongs: PublishSubject<[SongEntity]> = PublishSubject()
let groupPlaySongs: PublishSubject<(playlistTitle: String, songs: [SongEntity])> = PublishSubject()
let showToast: PublishSubject<String> = PublishSubject()
let showLogin: PublishSubject<Void> = .init()
}
Expand Down Expand Up @@ -123,13 +123,13 @@ public final class ChartContentViewModel: ViewModelType {

input.halfPlayTapped
.withLatestFrom(output.dataSource) { ($0, $1) }
.map { [weak self] type, source -> [ChartRankingEntity] in
self?.halfSplitArray(array: source, type: type) ?? []
.bind(with: self) { owner, tuple in
let (type, songs) = tuple
let chartsArray = owner.halfSplitArray(array: songs, type: type)
let songsArray = owner.toSongEntities(array: chartsArray)
let title = type.playlistTitleString
output.groupPlaySongs.onNext((title, songsArray))
}
.map { [weak self] entities -> [SongEntity] in
self?.toSongEntities(array: entities) ?? []
}
.bind(to: output.groupPlaySongs)
.disposed(by: disposeBag)

input.shufflePlayTapped
Expand All @@ -140,6 +140,7 @@ public final class ChartContentViewModel: ViewModelType {
.map { [weak self] entities -> [SongEntity] in
self?.toSongEntities(array: entities) ?? []
}
.map { ("왁뮤차트 TOP100 랜덤", $0) }
.bind(to: output.groupPlaySongs)
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ final class CreditSongListTabItemReactor: Reactor {
private var page: Int = 1
private var isLastPage: Bool = false
let initialState: State
private let workerName: String
let workerName: String
private let creditSortType: CreditSongSortType
private let songDetailPresenter: any SongDetailPresentable
private let fetchCreditSongListUseCase: any FetchCreditSongListUseCase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,9 @@ extension CreditSongListTabItemViewController {
}

private func playYoutube(ids: [String]) {
WakmusicYoutubePlayer(ids: ids).play()
let worker = reactor?.workerName ?? "작업자"
let title = "\(worker)님과 함께하는 랜뮤"
WakmusicYoutubePlayer(ids: ids, title: title).play()
}

private func presentContainSongs(ids: [String]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ extension NewSongsContentViewController: SongCartViewDelegate {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .recentMusic, type: .multiple)
)
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: "왁타버스 뮤직").play()

case .remove:
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -544,23 +544,29 @@ extension MyPlaylistDetailViewController: PlayButtonGroupViewDelegate {
let currentState = reactor.currentState
var songs = currentState.playlistModels

let playlistName = reactor.currentState.header.title
let title: String

switch event {
case .allPlay:
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlistDetail, type: .all)
)
LogManager.analytics(PlaylistAnalyticsLog.clickPlaylistPlayButton(type: "all", key: reactor.key))
title = "\(playlistName) (전체)"

case .shufflePlay:
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlistDetail, type: .random)
)
LogManager.analytics(PlaylistAnalyticsLog.clickPlaylistPlayButton(type: "random", key: reactor.key))
songs.shuffle()
title = "\(playlistName) (랜덤)"
}

PlayState.shared.append(contentsOf: songs.map { PlaylistItem(id: $0.id, title: $0.title, artist: $0.artist) })
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()

WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: title).play()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ extension PlaylistViewController: UITableViewDelegate {
.map(\.id)
.shuffled()
.prefix(50)
WakmusicYoutubePlayer(ids: Array(songIDs)).play()
WakmusicYoutubePlayer(ids: Array(songIDs), title: "왁타버스 뮤직 재생목록 (랜덤)").play()
}
return randomPlayButton
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -371,23 +371,28 @@ extension UnknownPlaylistDetailViewController: PlayButtonGroupViewDelegate {
let currentState = reactor.currentState
var songs = currentState.dataSource

let playlistName = reactor.currentState.header.title
let title: String

switch event {
case .allPlay:
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlistDetail, type: .all)
)
LogManager.analytics(PlaylistAnalyticsLog.clickPlaylistPlayButton(type: "all", key: reactor.key))
title = "\(playlistName) (전체)"

case .shufflePlay:
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlistDetail, type: .random)
)
LogManager.analytics(PlaylistAnalyticsLog.clickPlaylistPlayButton(type: "random", key: reactor.key))
songs.shuffle()
title = "\(playlistName) (랜덤)"
}

PlayState.shared.append(contentsOf: songs.map { PlaylistItem(item: $0) })
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: title).play()
}
}

Expand Down Expand Up @@ -435,7 +440,7 @@ extension UnknownPlaylistDetailViewController: SongCartViewDelegate {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlistDetail, type: .multiple)
)
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: "왁타버스 뮤직").play()
reactor.action.onNext(.deselectAll)

case .remove:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ extension WakmusicPlaylistDetailViewController: SongCartViewDelegate {
CommonAnalyticsLog.clickPlayButton(location: .playlistDetail, type: .multiple)
)
PlayState.shared.append(contentsOf: songs.map { PlaylistItem(item: $0) })
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: "왁타버스 뮤직").play()
reactor.action.onNext(.deselectAll)

case .remove:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ extension SongSearchResultViewController: SongCartViewDelegate {
}

PlayState.shared.append(contentsOf: songs.map { PlaylistItem(item: $0) })
WakmusicYoutubePlayer(ids: songs.map { $0.id }).play()
WakmusicYoutubePlayer(ids: songs.map { $0.id }, title: "왁타버스 뮤직").play()
reactor.action.onNext(.deselectAll)

case .remove:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ extension ListStorageReactor {
PlayState.shared.appendSongsToPlaylist(appendingPlaylistItems)
let ids = appendingPlaylistItems.map { $0.id }
.prefix(50)
WakmusicYoutubePlayer(ids: Array(ids)).play()
WakmusicYoutubePlayer(ids: Array(ids), title: "왁타버스 뮤직").play()
self?.storageCommonService.isEditingState.onNext(false)
})
.flatMap { songs -> Observable<Mutation> in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ private enum VideoPlayType {
public struct WakmusicYoutubePlayer: WakmusicPlayer {
private let youtubeURLGenerator: any YoutubeURLGeneratable
private let youtubeVideoType: VideoPlayType
private let title: String?
private var openerPlatform: OpenerPlatform {
let platform = PreferenceManager.songPlayPlatformType ?? .youtube
switch platform {
Expand All @@ -25,17 +26,21 @@ public struct WakmusicYoutubePlayer: WakmusicPlayer {

public init(
id: String,
title: String? = nil,
youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator()
) {
self.youtubeVideoType = .videos(ids: [id])
self.title = title
self.youtubeURLGenerator = youtubeURLGenerator
}

public init(
ids: [String],
title: String? = nil,
youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator()
) {
self.youtubeVideoType = .videos(ids: ids)
self.title = title
self.youtubeURLGenerator = youtubeURLGenerator
}

Expand All @@ -44,6 +49,7 @@ public struct WakmusicYoutubePlayer: WakmusicPlayer {
youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator()
) {
self.youtubeVideoType = .playlist(listID: listID)
self.title = nil
self.youtubeURLGenerator = youtubeURLGenerator
}

Expand All @@ -63,7 +69,11 @@ private extension WakmusicYoutubePlayer {
guard let url = await urlForYoutube(ids: ids) else {
return
}
await UIApplication.shared.open(url)
if let title, !title.isEmpty, let titledURL = url.appendingTitleParam(title: title) {
await UIApplication.shared.open(titledURL)
} else {
await UIApplication.shared.open(url)
}
}
}

Expand Down Expand Up @@ -179,3 +189,11 @@ private extension WakmusicYoutubePlayer {
return redirectedURL
}
}

private extension URL {
func appendingTitleParam(title: String) -> URL? {
guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else { return nil }
components.queryItems?.append(URLQueryItem(name: "title", value: title))
return components.url
}
}

0 comments on commit 6f33b0a

Please sign in to comment.