Skip to content

Commit

Permalink
#142 feat: MusicSession 임시로 상세 뷰 컨트롤러에 연결
Browse files Browse the repository at this point in the history
  • Loading branch information
radiantchoi committed Dec 1, 2022
1 parent 13d00f8 commit f270b50
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Segno/Segno.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,7 @@
DEVELOPMENT_TEAM = 4QG3GC35LA;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Segno/Resource/Info.plist;
INFOPLIST_KEY_NSAppleMusicUsageDescription = "";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "음악 검색 기능을 위해 마이크 사용 허가가 필요합니다.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
Expand Down Expand Up @@ -817,6 +818,7 @@
DEVELOPMENT_TEAM = 4QG3GC35LA;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = Segno/Resource/Info.plist;
INFOPLIST_KEY_NSAppleMusicUsageDescription = "";
INFOPLIST_KEY_NSMicrophoneUsageDescription = "음악 검색 기능을 위해 마이크 사용 허가가 필요합니다.";
INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES;
INFOPLIST_KEY_UILaunchStoryboardName = LaunchScreen;
Expand Down
6 changes: 6 additions & 0 deletions Segno/Segno/Entity/DiaryDetail.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,9 @@ struct DiaryDetail: Encodable {
)
}
}

#if DEBUG
extension DiaryDetail {
static let dummy = DiaryDetail(identifier: "1", title: "테스트", tags: ["테스트"], imagePath: "", bodyText: "테스트", musicInfo: MusicInfo.yokohama, location: nil)
}
#endif
15 changes: 15 additions & 0 deletions Segno/Segno/Entity/MusicInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,19 @@ struct MusicInfo: Encodable {
self.album = shazamSong.album
self.imageURL = shazamSong.imageURL
}

// 수동 더미
init(isrc: String, title: String, artist: String, album: String, imageURL: URL? = nil) {
self.isrc = isrc
self.title = title
self.artist = artist
self.album = album
self.imageURL = imageURL
}
}

#if DEBUG
extension MusicInfo {
static let yokohama = MusicInfo(isrc: "JPF920900301", title: "Yokohama City", artist: "paris match", album: "Passion8", imageURL: URL(string: "https://is1-ssl.mzstatic.com/image/thumb/Music124/v4/1e/69/38/1e693867-a4e3-19a2-aba5-2a35eaed49a6/VEATP-37522.jpg/800x800bb.jpg"))
}
#endif
15 changes: 15 additions & 0 deletions Segno/Segno/Presentation/View/MusicContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
import UIKit

import Kingfisher
import RxSwift
import SnapKit

protocol MusicContentViewDelegate: AnyObject {
func playButtonTapped()
}

final class MusicContentView: UIView {
private enum Metric {
static let fontSize: CGFloat = 16
Expand All @@ -19,6 +24,9 @@ final class MusicContentView: UIView {
static let playButtonSize: CGFloat = 30
}

private let disposeBag = DisposeBag()
weak var delegate: MusicContentViewDelegate?

private lazy var albumArtImageView: UIImageView = {
let imageView = UIImageView()
imageView.backgroundColor = .systemMint
Expand All @@ -42,13 +50,20 @@ final class MusicContentView: UIView {
let button = UIButton()
button.setImage(UIImage(systemName: "play.fill"), for: .normal)
button.tintColor = .appColor(.black)
button.rx.tap
.bind { [weak self] in
self?.delegate?.playButtonTapped()
}
.disposed(by: disposeBag)
return button
}()

override init(frame: CGRect) {
super.init(frame: frame)

setLayout()
// 임시로 정해진 데이터를 넣었습니다.
setMusic(info: MusicInfo.yokohama)
}

required init?(coder: NSCoder) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class DiaryDetailViewController: UIViewController {
}

private let disposeBag = DisposeBag()
private let musicSession = MusicSession() // 임시로 여기에 놓습니다
private let viewModel: DiaryDetailViewModel
weak var delegate: DiaryDetailViewDelegate?

Expand Down Expand Up @@ -91,6 +92,7 @@ final class DiaryDetailViewController: UIViewController {

private lazy var musicContentView: MusicContentView = {
let musicContentView = MusicContentView()
musicContentView.delegate = self
return musicContentView
}()

Expand All @@ -116,12 +118,19 @@ final class DiaryDetailViewController: UIViewController {
setupLayout()
bindDiaryItem()
getDiary()

// 뮤직세션 테스트용으로, 임시로 정해진 데이터를 넣어 두었습니다.
musicSession.fetchMusic(term: MusicInfo.yokohama)
}

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
self.view.endEditing(true)
}

private func bindPlayButton() {
musicContentView
}

private func setupLayout() {
view.backgroundColor = .appColor(.background)

Expand Down Expand Up @@ -231,6 +240,12 @@ final class DiaryDetailViewController: UIViewController {
}
}

extension DiaryDetailViewController: MusicContentViewDelegate {
func playButtonTapped() {
musicSession.playMusic()
}
}

extension DiaryDetailViewController: LocationContentViewDelegate {
func mapButtonTapped(location: Location) {
delegate?.mapButtonTapped(viewController: self, location: location)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ extension DiaryEditViewController {
let artist = song.artist

let musicInfo = MusicInfo(shazamSong: song) // 뷰모델에서 이 작업을 할 때, 향후 사용될 엔티티
debugPrint(musicInfo.isrc)
debugPrint(musicInfo)

DispatchQueue.main.async {
self.musicInfoLabel.text = "\(artist) - \(title)"
Expand Down

0 comments on commit f270b50

Please sign in to comment.