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

๐Ÿ”€ :: (#1248) ๋‹จ์ผ๊ณก ์žฌ์ƒ ์‹œ ์ œ๋ชฉ์— Shorts๋ฅผ ์˜๋ฏธํ•˜๋Š” ํ…์ŠคํŠธ๊ฐ€ ํฌํ•จ๋˜์–ด์žˆ์„ ์‹œYoutube๋กœ ์žฌ์ƒ #1249

Merged
merged 2 commits into from
Aug 28, 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 @@ -420,7 +420,10 @@ extension HomeViewController: HomeChartCellDelegate {
CommonAnalyticsLog.clickPlayButton(location: .home, type: .single)
)
PlayState.shared.append(item: .init(id: model.id, title: model.title, artist: model.artist))
WakmusicYoutubePlayer(id: model.id).play()
WakmusicYoutubePlayer(
id: model.id,
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}
}

Expand All @@ -438,7 +441,10 @@ extension HomeViewController: HomeNewSongCellDelegate {
CommonAnalyticsLog.clickPlayButton(location: .home, type: .single)
)
PlayState.shared.append(item: .init(id: model.id, title: model.title, artist: model.artist))
WakmusicYoutubePlayer(id: model.id).play()
WakmusicYoutubePlayer(
id: model.id,
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ final class MusicDetailReactor: Reactor {
}

enum NavigateType {
case youtube(id: String)
case youtube(id: String, playPlatform: WakmusicYoutubePlayer.PlayPlatform)
case credit(id: String)
case lyricsHighlighting(model: LyricHighlightingRequiredModel)
case musicPick(id: String)
Expand Down Expand Up @@ -296,7 +296,10 @@ private extension MusicDetailReactor {
LogManager.analytics(log)
}
PlayState.shared.append(item: PlaylistItem(id: song.videoID, title: song.title, artist: song.artistString))
return navigateMutation(navigate: .youtube(id: song.videoID))
return navigateMutation(navigate: .youtube(
id: song.videoID,
playPlatform: song.title.isContainShortsTagTitle ? .youtube : .automatic
))
}

func nextButtonDidTap() -> Observable<Mutation> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ final class MusicDetailViewController: BaseReactorViewController<MusicDetailReac
sharedState.compactMap(\.navigateType)
.bind(with: self) { owner, navigate in
switch navigate {
case let .youtube(id):
owner.openYoutube(id: id)
case let .youtube(id, playPlatform):
owner.openYoutube(id: id, playPlatform: playPlatform)
case let .credit(id):
owner.navigateCredits(id: id)
case let .lyricsHighlighting(model):
Expand Down Expand Up @@ -218,8 +218,8 @@ final class MusicDetailViewController: BaseReactorViewController<MusicDetailReac
}

private extension MusicDetailViewController {
func openYoutube(id: String) {
WakmusicYoutubePlayer(id: id).play()
func openYoutube(id: String, playPlatform: WakmusicYoutubePlayer.PlayPlatform = .automatic) {
WakmusicYoutubePlayer(id: id, playPlatform: playPlatform).play()
}

func navigateCredits(id: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,14 @@ extension MyPlaylistDetailViewController: PlayButtonGroupViewDelegate {

/// ํŽธ์ง‘๋ชจ๋“œ ์‹œ ์…€ ์„ ํƒ ์ด๋ฒคํŠธ
extension MyPlaylistDetailViewController: PlaylistTableViewCellDelegate {
func playButtonDidTap(key: String) {
WakmusicYoutubePlayer(id: key).play()
func playButtonDidTap(model: PlaylistItemModel) {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlist, type: .single)
)
WakmusicYoutubePlayer(
id: model.id,
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}

func superButtonTapped(index: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,14 @@ extension PlaylistViewController: UITableViewDelegate {
}

extension PlaylistViewController: PlaylistTableViewCellDelegate {
func playButtonDidTap(key: String) {
func playButtonDidTap(model: PlaylistItemModel) {
LogManager.analytics(
CommonAnalyticsLog.clickPlayButton(location: .playlist, type: .single)
)
WakmusicYoutubePlayer(id: key).play()
WakmusicYoutubePlayer(
id: model.id,
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}

func superButtonTapped(index: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Utility

internal protocol PlaylistTableViewCellDelegate: AnyObject {
func superButtonTapped(index: Int)
func playButtonDidTap(key: String)
func playButtonDidTap(model: PlaylistItemModel)
}

internal class PlaylistTableViewCell: UITableViewCell {
Expand Down Expand Up @@ -148,7 +148,7 @@ extension PlaylistTableViewCell {
return
}

owner.delegate?.playButtonDidTap(key: song.id)
owner.delegate?.playButtonDidTap(model: song)
}
.disposed(by: disposeBag)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ extension BeforeSearchContentViewController: UICollectionViewDelegate {

switch model {
case let .youtube(model: model):
// ์ฃผ๊ฐ„ ์™๋ฎค
WakmusicYoutubePlayer(id: model.id).play()
LogManager.analytics(SearchAnalyticsLog.clickLatestWakmuYoutubeVideo)
case let .recommend(model: model):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
LogManager.printDebug("โŒ Deinit \(Self.self)")
}

func mutate(action: Action) -> Observable<Mutation> {

Check warning on line 93 in Projects/Features/StorageFeature/Sources/Reactors/LikeStorageReactor.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 12 (cyclomatic_complexity)
switch action {
case .viewDidLoad:
return viewDidLoad()
Expand Down Expand Up @@ -196,7 +196,7 @@
)
}

func reduce(state: State, mutation: Mutation) -> State {

Check warning on line 199 in Projects/Features/StorageFeature/Sources/Reactors/LikeStorageReactor.swift

View workflow job for this annotation

GitHub Actions / swiftlint

Cyclomatic Complexity Violation: Function should have complexity 10 or less; currently complexity is 14 (cyclomatic_complexity)
var newState = state

switch mutation {
Expand Down Expand Up @@ -311,7 +311,10 @@
func playWithAddToCurrentPlaylist(song: FavoriteSongEntity) -> Observable<Mutation> {
let appendingPlaylisItem = PlaylistItem(id: song.songID, title: song.title, artist: song.artist)
PlayState.shared.append(item: appendingPlaylisItem)
WakmusicYoutubePlayer(id: song.songID).play()
WakmusicYoutubePlayer(
id: song.songID,
playPlatform: song.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
return .empty()
}

Expand Down Expand Up @@ -404,4 +407,4 @@
])
}
}
}

Check warning on line 410 in Projects/Features/StorageFeature/Sources/Reactors/LikeStorageReactor.swift

View workflow job for this annotation

GitHub Actions / swiftlint

File Length Violation: File should contain 400 lines or less: currently contains 410 (file_length)
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ public extension String {
formatter.dateFormat = format
return formatter.date(from: self) ?? .init()
}

var isContainShortsTagTitle: Bool {
return self.lowercased().contains("#Shorts".lowercased())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,60 @@ import Foundation
import LinkPresentation
import UIKit

private enum OpenerPlatform {
case youtube
case youtubeMusic
}
public struct WakmusicYoutubePlayer: WakmusicPlayer {
fileprivate enum OpenerPlatform {
case youtube
case youtubeMusic
}

private enum VideoPlayType {
case videos(ids: [String])
case playlist(listID: String)
}
private enum VideoPlayType {
case videos(ids: [String])
case playlist(listID: String)
}

public enum PlayPlatform {
case youtube
case youtubeMusic
case automatic
}

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 {
case .youtube: return .youtube
case .youtubeMusic: return .youtubeMusic
}
}
private let openerPlatform: OpenerPlatform

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

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

public init(
listID: String,
playPlatform: PlayPlatform = .automatic,
youtubeURLGenerator: any YoutubeURLGeneratable = YoutubeURLGenerator()
) {
self.youtubeVideoType = .playlist(listID: listID)
self.title = nil
self.openerPlatform = playPlatform.toOpenerPlatform
self.youtubeURLGenerator = youtubeURLGenerator
}

Expand Down Expand Up @@ -197,3 +203,22 @@ private extension URL {
return components.url
}
}

private extension WakmusicYoutubePlayer.PlayPlatform {
var toOpenerPlatform: WakmusicYoutubePlayer.OpenerPlatform {
switch self {
case .youtube: return .youtube
case .youtubeMusic: return .youtubeMusic
case .automatic: return PreferenceManager.songPlayPlatformType?.toOpnerPlatform ?? .youtube
}
}
}

private extension YoutubePlayType {
var toOpnerPlatform: WakmusicYoutubePlayer.OpenerPlatform {
switch self {
case .youtube: return .youtube
case .youtubeMusic: return .youtubeMusic
}
}
}
Loading