Skip to content

Commit

Permalink
#297: Share Extension, 음악 재검색 UI 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph704 committed Aug 16, 2024
1 parent 8590a26 commit a903076
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
//
// ReSearchingMusicForSharingView.swift
// ShareExtension
//
// Created by 차요셉 on 8/16/24.
//

import UIKit

import RxSwift
import RxRelay
import SnapKit

final class ReSearchingMusicForSharingView: UIView {
private let reSearchingEventRelay: PublishRelay<String> = .init()
// View -> ViewController
var reSearchingEvent: Observable<String> {
reSearchingEventRelay.asObservable()
}
// ViewController -> View
let settingMusicDataRelay: PublishRelay<[Music]> = .init()
private let disposeBag: DisposeBag = .init()

override init(frame: CGRect) {
super.init(frame: frame)
bindData()
configureUI()
}

@available(*, unavailable)
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private let backbutton: UIButton = {
let button: UIButton = .init()
button.setImage(.init(named: "backButton"), for: .normal)

return button
}()

private let titleLabel: UILabel = {
let label: UILabel = .init()
label.text = "직접 검색"
label.textColor = .textPrimary
label.font = .pretendard(size: 16, weight: 700)
label.setLineHeight(lineHeight: 24)

return label
}()

private let exitButton: UIButton = {
let button: UIButton = .init()
button.setImage(.init(named: "exit"), for: .normal)

return button
}()

private lazy var searchTextField: UITextField = {
let textField: UITextField = UITextField()
textField.backgroundColor = UIColor.gray700
textField.attributedPlaceholder = NSAttributedString(
string: "드랍할 음악 검색",
attributes: [
.foregroundColor: UIColor.gray400
]
)
textField.textColor = .textPrimary
textField.layer.cornerRadius = 12.0

textField.returnKeyType = .search

let leftPaddingView = UIView(
frame: CGRect(
x: 0,
y: 0,
width: 16,
height: 44
)
)
textField.leftView = leftPaddingView
textField.leftViewMode = .always

textField.rightView = searchCancelView
textField.rightViewMode = .whileEditing
return textField
}()

private lazy var searchCancelView: UIView = {
let view: UIView = .init()

return view
}()

private lazy var searchCancelButton: UIButton = {
let button: UIButton = .init()
button.setImage(UIImage(named: "cancleButton"), for: .normal)

return button
}()

private lazy var tableView: UITableView = {
let tableView: UITableView = .init()
tableView.backgroundColor = .clear
tableView.register(
ReSearchingMusicTableViewCell.self,
forCellReuseIdentifier: ReSearchingMusicTableViewCell.identifier
)
tableView.rowHeight = 80
tableView.keyboardDismissMode = .onDrag

return tableView
}()
}

private extension ReSearchingMusicForSharingView {
func bindData() {
settingMusicDataRelay
.bind(
to: tableView.rx.items(
cellIdentifier: ReSearchingMusicTableViewCell.identifier,
cellType: ReSearchingMusicTableViewCell.self
)
) { (row, music, reSearchingMusicTableViewCell) in
reSearchingMusicTableViewCell.setData(music: music)
}
.disposed(by: disposeBag)
}

func configureUI() {
[
backbutton,
titleLabel,
searchTextField,
exitButton,
tableView
].forEach {
addSubview($0)
}

searchCancelView.addSubview(searchCancelButton)

backbutton.snp.makeConstraints {
$0.width.height.equalTo(32)
$0.top.equalToSuperview().inset(14)
$0.leading.equalToSuperview().inset(24)
}

titleLabel.snp.makeConstraints {
$0.height.equalTo(18)
$0.top.equalToSuperview().inset(18)
$0.centerX.equalToSuperview()
}

exitButton.snp.makeConstraints {
$0.width.equalTo(44)
$0.height.equalTo(32)
$0.top.equalToSuperview().inset(14)
$0.trailing.equalToSuperview().inset(24)
}

searchTextField.snp.makeConstraints {
$0.height.equalTo(44)
$0.top.equalTo(titleLabel.snp.bottom).offset(26)
$0.horizontalEdges.equalToSuperview().inset(24)
}

tableView.snp.makeConstraints {
$0.top.equalTo(searchTextField.snp.bottom).offset(12)
$0.horizontalEdges.bottom.equalToSuperview()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
//
// ReSearchingMusicTableViewCell.swift
// ShareExtension
//
// Created by 차요셉 on 8/16/24.
//

import UIKit

import RxSwift
import SnapKit
import Kingfisher

final class ReSearchingMusicTableViewCell: UITableViewCell {
static let identifier = "SearchingMusicTableViewCell"
private var disposeBag: DisposeBag = DisposeBag()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.backgroundColor = .clear
self.selectionStyle = .none
self.configureUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been impl")
}

override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
}

override func prepareForReuse() {
super.prepareForReuse()
self.albumImageView.image = nil
self.disposeBag = DisposeBag()
}

func setData(music: Music) {
albumImageView.setImage(with: music.albumImage)
songNameLabel.text = music.songName
artistNameLabel.text = music.artistName
durationTimeLabel.text = music.durationTime
}

private lazy var albumImageView: UIImageView = {
let imageView: UIImageView = .init()
imageView.layer.cornerRadius = 12.0
imageView.contentMode = .scaleAspectFill
imageView.clipsToBounds = true
return imageView
}()

private lazy var songNameLabel: UILabel = {
let label: UILabel = .init()
label.font = .pretendard(size: 16, weight: 600)
label.setLineHeight(lineHeight: 24)
label.textColor = UIColor.white
label.numberOfLines = 1
return label
}()

private lazy var artistNameLabel: UILabel = {
let label: UILabel = .init()
label.font = .pretendard(size: 12, weight: 400)
label.setLineHeight(lineHeight: 16)
label.numberOfLines = 1
label.textColor = UIColor.gray200
return label
}()

private lazy var durationTimeLabel: UILabel = {
let label: UILabel = .init()
label.font = .pretendard(size: 12, weight: 400)
label.setLineHeight(lineHeight: 16)
label.numberOfLines = 1
label.textColor = UIColor.gray200
label.adjustsFontSizeToFitWidth = true

return label
}()
}

private extension ReSearchingMusicTableViewCell {
func configureUI() {
[
albumImageView,
songNameLabel,
artistNameLabel,
durationTimeLabel
].forEach {
addSubview($0)
}

albumImageView.snp.makeConstraints {
$0.width.height.equalTo(56)
$0.centerY.equalToSuperview()
$0.leading.equalToSuperview().offset(24)
}

songNameLabel.snp.makeConstraints {
$0.height.equalTo(24)
$0.top.equalToSuperview().inset(19)
$0.leading.equalTo(albumImageView.snp.trailing).offset(12)
$0.trailing.equalToSuperview().inset(60)
}

artistNameLabel.snp.makeConstraints {
$0.top.equalTo(songNameLabel.snp.bottom).offset(2)
$0.leading.equalTo(albumImageView.snp.trailing).offset(12)
$0.trailing.equalTo(durationTimeLabel.snp.leading)
}

durationTimeLabel.snp.makeConstraints {
$0.width.equalTo(36)
$0.height.equalTo(16)
$0.bottom.equalTo(artistNameLabel.snp.bottom)
$0.trailing.equalToSuperview().inset(24)
}
}
}

16 changes: 16 additions & 0 deletions StreetDrop/StreetDrop.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,8 @@
C44A549A2BBC097E00354F8F /* FetchingPopUpInfomationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44A54992BBC097E00354F8F /* FetchingPopUpInfomationUseCase.swift */; };
C44A549C2BBC099E00354F8F /* DefaultFetchingPopUpInfomationUseCase.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44A549B2BBC099E00354F8F /* DefaultFetchingPopUpInfomationUseCase.swift */; };
C44A549E2BBC0DC500354F8F /* TipPopUpViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44A549D2BBC0DC500354F8F /* TipPopUpViewController.swift */; };
C44DE1F92C6EDC04004F211C /* ReSearchingMusicForSharingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44DE1F82C6EDC04004F211C /* ReSearchingMusicForSharingView.swift */; };
C44DE1FB2C6EE07D004F211C /* ReSearchingMusicTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = C44DE1FA2C6EE07D004F211C /* ReSearchingMusicTableViewCell.swift */; };
C45A4CB02A3710AC00EE9C36 /* ImageCacheError.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45A4CAF2A3710AC00EE9C36 /* ImageCacheError.swift */; };
C45BF3972A1D0ADF00CEDE74 /* UserDefaultKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45BF3962A1D0ADF00CEDE74 /* UserDefaultKey.swift */; };
C45BF39E2A1D113200CEDE74 /* UserDefaultsRecentMusicSearches.swift in Sources */ = {isa = PBXBuildFile; fileRef = C45BF39D2A1D113200CEDE74 /* UserDefaultsRecentMusicSearches.swift */; };
Expand Down Expand Up @@ -741,6 +743,8 @@
C44A54992BBC097E00354F8F /* FetchingPopUpInfomationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FetchingPopUpInfomationUseCase.swift; sourceTree = "<group>"; };
C44A549B2BBC099E00354F8F /* DefaultFetchingPopUpInfomationUseCase.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DefaultFetchingPopUpInfomationUseCase.swift; sourceTree = "<group>"; };
C44A549D2BBC0DC500354F8F /* TipPopUpViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TipPopUpViewController.swift; sourceTree = "<group>"; };
C44DE1F82C6EDC04004F211C /* ReSearchingMusicForSharingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReSearchingMusicForSharingView.swift; sourceTree = "<group>"; };
C44DE1FA2C6EE07D004F211C /* ReSearchingMusicTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReSearchingMusicTableViewCell.swift; sourceTree = "<group>"; };
C45A4CAF2A3710AC00EE9C36 /* ImageCacheError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImageCacheError.swift; sourceTree = "<group>"; };
C45BF3962A1D0ADF00CEDE74 /* UserDefaultKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultKey.swift; sourceTree = "<group>"; };
C45BF39D2A1D113200CEDE74 /* UserDefaultsRecentMusicSearches.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsRecentMusicSearches.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1768,6 +1772,7 @@
isa = PBXGroup;
children = (
C42182BC2C697F9700B73A99 /* ShareViewController.swift */,
C44DE1FC2C6EE089004F211C /* ReSearchingMusic */,
);
path = View;
sourceTree = "<group>";
Expand Down Expand Up @@ -1836,6 +1841,15 @@
path = PopUp;
sourceTree = "<group>";
};
C44DE1FC2C6EE089004F211C /* ReSearchingMusic */ = {
isa = PBXGroup;
children = (
C44DE1F82C6EDC04004F211C /* ReSearchingMusicForSharingView.swift */,
C44DE1FA2C6EE07D004F211C /* ReSearchingMusicTableViewCell.swift */,
);
path = ReSearchingMusic;
sourceTree = "<group>";
};
C45BF3982A1D0AE200CEDE74 /* Constant */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2904,6 +2918,7 @@
C432DF4B2C69F7F3003DBA18 /* Music.swift in Sources */,
C432DF4C2C69F7F3003DBA18 /* RecommendMusic.swift in Sources */,
C432DF4D2C69F7F3003DBA18 /* ModalOption.swift in Sources */,
C44DE1F92C6EDC04004F211C /* ReSearchingMusicForSharingView.swift in Sources */,
C432DF4E2C69F7F3003DBA18 /* MyLevelProgress.swift in Sources */,
C432DF4F2C69F7F3003DBA18 /* LevelPolicy.swift in Sources */,
C432DF502C69F7F3003DBA18 /* PopUpInfomation.swift in Sources */,
Expand All @@ -2930,6 +2945,7 @@
C432DF652C69F7F3003DBA18 /* DefaultClaimingCommentUseCase.swift in Sources */,
C432DF662C69F7F3003DBA18 /* DeletingMusicUseCase.swift in Sources */,
C432DF672C69F7F3003DBA18 /* DefaultDeletingMusicUseCase.swift in Sources */,
C44DE1FB2C6EE07D004F211C /* ReSearchingMusicTableViewCell.swift in Sources */,
C432DF682C69F7F3003DBA18 /* BlockUserUseCase.swift in Sources */,
C432DF692C69F7F3003DBA18 /* DefaultBlockUserUseCase.swift in Sources */,
C432DF6A2C69F7F3003DBA18 /* FetchingMyInfoUseCase.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "exit.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit a903076

Please sign in to comment.