Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

๐Ÿ”€ :: (#1215) ๋…ธ๋ž˜ ๋ฆฌ์ŠคํŠธ ์žฌ์ƒ ์‹œ Unnamed Playlist์— ์ด๋ฆ„ ์ง€์ • #1242

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
Loading