Skip to content

Commit

Permalink
✨ :: [#1306] 보관함 화면 Long Press 편집모드 진입 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
baekteun committed Oct 9, 2024
1 parent 3832e01 commit 676545c
Show file tree
Hide file tree
Showing 8 changed files with 86 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ final class LikeStorageReactor: Reactor {
case itemMoved(ItemMovedEvent)
case songDidTap(Int)
case tapAll(isSelecting: Bool)
case didLongPressedPlaylist(IndexPath)
case playDidTap(song: FavoriteSongEntity)
case addToPlaylistButtonDidTap // 노래담기
case presentAddToPlaylistPopup
Expand Down Expand Up @@ -104,6 +105,9 @@ final class LikeStorageReactor: Reactor {
case let .songDidTap(index):
return changeSelectingState(index)

case let .didLongPressedPlaylist(indexPath):
return didLongPressedPlaylist(indexPath: indexPath)

case let .playDidTap(song):
return playWithAddToCurrentPlaylist(song: song)

Expand Down Expand Up @@ -285,6 +289,13 @@ extension LikeStorageReactor {
return .just(.showAddToPlaylistPopup(selectedItemIDs))
}

func didLongPressedPlaylist(indexPath: IndexPath) -> Observable<Mutation> {
guard !currentState.isEditing else { return .empty() }
storageCommonService.isEditingState.onNext(true)
changeSelectingState(indexPath.row)
return .just(.switchEditingState(true))
}

func presentAddToPlaylistPopup() -> Observable<Mutation> {
guard var tmp = currentState.dataSource.first?.items else {
LogManager.printError("favorite datasource is empty")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ final class ListStorageReactor: Reactor {
case viewDidLoad
case refresh
case itemMoved(ItemMovedEvent)
case cellDidTap(Int)
case listDidTap(IndexPath)
case didSelectPlaylist(IndexPath)
case didLongPressedPlaylist(IndexPath)
case playDidTap(Int)
case tapAll(isSelecting: Bool)
case loginButtonDidTap
Expand Down Expand Up @@ -117,11 +117,11 @@ final class ListStorageReactor: Reactor {
case let .itemMoved((sourceIndex, destinationIndex)):
return updateOrder(src: sourceIndex.row, dest: destinationIndex.row)

case let .cellDidTap(index):
return changeSelectingState(index)
case let .didSelectPlaylist(indexPath):
return didSelectPlaylistCell(indexPath: indexPath)

case let .listDidTap(indexPath):
return showDetail(indexPath)
case let .didLongPressedPlaylist(indexPath):
return didLongPressedPlaylist(indexPath: indexPath)

case let .playDidTap(index):
return playWithAddToCurrentPlaylist(index)
Expand Down Expand Up @@ -333,6 +333,23 @@ extension ListStorageReactor {
)
}

func didLongPressedPlaylist(indexPath: IndexPath) -> Observable<Mutation> {
guard !currentState.isEditing else { return .empty() }
storageCommonService.isEditingState.onNext(true)
return .concat(
changeSelectingState(indexPath.row),
.just(.switchEditingState(true))
)
}

func didSelectPlaylistCell(indexPath: IndexPath) -> Observable<Mutation> {
if currentState.isEditing {
return changeSelectingState(indexPath.row)
} else {
return showDetail(indexPath)
}
}

func showDetail(_ indexPath: IndexPath) -> Observable<Mutation> {
let selectedList = currentState.dataSource[indexPath.section].items[indexPath.row]
let key = selectedList.key
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,21 @@ final class LikeStorageViewController: BaseReactorViewController<LikeStorageReac

likeStorageView.tableView.rx.itemSelected
.withLatestFrom(reactor.state.map(\.dataSource)) { ($0, $1) }
.compactMap { $0.1[safe: $0.0.section]?.items[safe: $0.0.row] }
.bind(with: self, onNext: { owner, song in
LogManager.analytics(StorageAnalyticsLog.clickMyLikeListMusicButton(id: song.songID))

PlayState.shared.append(item: .init(id: song.songID, title: song.title, artist: song.artist))
let playlistIDs = PlayState.shared.currentPlaylist
.map(\.id)
owner.songDetailPresenter.present(ids: playlistIDs, selectedID: song.songID)
.bind(with: self, onNext: { owner, data in
let (indexPath, dataSource) = data

if owner.reactor?.currentState.isEditing == true {
self.reactor?.action.onNext(.songDidTap(indexPath.row))
} else {
guard let song = dataSource[safe: indexPath.section]?.items[safe: indexPath.row] else { return }

LogManager.analytics(StorageAnalyticsLog.clickMyLikeListMusicButton(id: song.songID))

PlayState.shared.append(item: .init(id: song.songID, title: song.title, artist: song.artist))
let playlistIDs = PlayState.shared.currentPlaylist
.map(\.id)
owner.songDetailPresenter.present(ids: playlistIDs, selectedID: song.songID)
}
})
.disposed(by: disposeBag)
}
Expand Down Expand Up @@ -279,8 +286,6 @@ extension LikeStorageViewController: SongCartViewDelegate {
extension LikeStorageViewController: LikeStorageTableViewCellDelegate {
public func buttonTapped(type: LikeStorageTableViewCellDelegateConstant) {
switch type {
case let .cellTapped(indexPath):
self.reactor?.action.onNext(.songDidTap(indexPath.row))
case let .playTapped(song):
LogManager.analytics(CommonAnalyticsLog.clickPlayButton(location: .storageLike, type: .single))
self.reactor?.action.onNext(.playDidTap(song: song))
Expand All @@ -301,6 +306,21 @@ extension LikeStorageViewController: UITableViewDelegate {
public func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false // 편집모드 시 셀의 들여쓰기를 없애려면 false를 리턴합니다.
}

func tableView(
_ tableView: UITableView,
contextMenuConfigurationForRowAt indexPath: IndexPath,
point: CGPoint
) -> UIContextMenuConfiguration? {
if reactor?.currentState.isEditing == true {
return nil
} else {
return UIContextMenuConfiguration(identifier: nil, previewProvider: { [reactor] in
reactor?.action.onNext(.didLongPressedPlaylist(indexPath))
return nil
})
}
}
}

extension LikeStorageViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,16 +329,9 @@ extension ListStorageViewController: SongCartViewDelegate {
extension ListStorageViewController: ListStorageTableViewCellDelegate {
public func buttonTapped(type: ListStorageTableViewCellDelegateConstant) {
switch type {
case let .listTapped(passModel):
LogManager.analytics(CommonAnalyticsLog.clickPlaylistItem(location: .storage, key: passModel.key))
self.reactor?.action.onNext(.listDidTap(passModel.indexPath))

case let .playTapped(passModel):
LogManager.analytics(CommonAnalyticsLog.clickPlayButton(location: .storagePlaylist, type: .playlist))
self.reactor?.action.onNext(.playDidTap(passModel.indexPath.row))

case let .cellTapped(passModel):
self.reactor?.action.onNext(.cellDidTap(passModel.indexPath.row))
}
}
}
Expand All @@ -364,6 +357,25 @@ extension ListStorageViewController: UITableViewDelegate {
public func tableView(_ tableView: UITableView, shouldIndentWhileEditingRowAt indexPath: IndexPath) -> Bool {
return false // 편집모드 시 셀의 들여쓰기를 없애려면 false를 리턴합니다.
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
reactor?.action.onNext(.didSelectPlaylist(indexPath))
}

func tableView(
_ tableView: UITableView,
contextMenuConfigurationForRowAt indexPath: IndexPath,
point: CGPoint
) -> UIContextMenuConfiguration? {
if reactor?.currentState.isEditing == true {
return nil
} else {
return UIContextMenuConfiguration(identifier: nil, previewProvider: { [reactor] in
reactor?.action.onNext(.didLongPressedPlaylist(indexPath))
return nil
})
}
}
}

extension ListStorageViewController {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public protocol LikeStorageTableViewCellDelegate: AnyObject {
}

public enum LikeStorageTableViewCellDelegateConstant {
case cellTapped(indexPath: IndexPath)
case playTapped(song: FavoriteSongEntity)
}

Expand Down Expand Up @@ -60,8 +59,6 @@ class LikeStorageTableViewCell: UITableViewCell {
)
}

private let cellSelectButton = UIButton()

weak var delegate: LikeStorageTableViewCellDelegate?
var indexPath: IndexPath?
var model: FavoriteSongEntity?
Expand Down Expand Up @@ -93,7 +90,6 @@ extension LikeStorageTableViewCell {
self.artistLabel.text = model.artist

self.backgroundColor = model.isSelected ? DesignSystemAsset.BlueGrayColor.blueGray200.color : UIColor.clear
self.cellSelectButton.isHidden = !isEditing
self.playButton.isHidden = isEditing

self.playButton.snp.updateConstraints {
Expand All @@ -107,7 +103,6 @@ private extension LikeStorageTableViewCell {
self.contentView.addSubviews(
albumImageView,
verticalStackView,
cellSelectButton,
playButton
)
verticalStackView.addArrangedSubviews(titleLabel, artistLabel)
Expand Down Expand Up @@ -140,16 +135,9 @@ private extension LikeStorageTableViewCell {
artistLabel.snp.makeConstraints {
$0.height.equalTo(18)
}

cellSelectButton.snp.makeConstraints {
$0.verticalEdges.equalToSuperview()
$0.left.equalToSuperview()
$0.right.equalTo(verticalStackView.snp.right)
}
}

func setAction() {
self.cellSelectButton.addTarget(self, action: #selector(cellSelectButtonAction), for: .touchUpInside)
self.playButton.addTarget(self, action: #selector(playButtonAction), for: .touchUpInside)
}
}
Expand All @@ -159,9 +147,4 @@ private extension LikeStorageTableViewCell {
guard let model else { return }
delegate?.buttonTapped(type: .playTapped(song: model))
}

@objc func cellSelectButtonAction() {
guard let indexPath else { return }
delegate?.buttonTapped(type: .cellTapped(indexPath: indexPath))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class LikeStorageView: UIView {
$0.backgroundColor = .clear
$0.register(LikeStorageTableViewCell.self, forCellReuseIdentifier: LikeStorageTableViewCell.reuseIdentifer)
$0.separatorStyle = .none
$0.allowsSelectionDuringEditing = true
}

fileprivate let loginWarningView = LoginWarningView(text: "로그인 하고\n좋아요를 확인해보세요.") { return }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public protocol ListStorageTableViewCellDelegate: AnyObject {
}

public enum ListStorageTableViewCellDelegateConstant {
case cellTapped((indexPath: IndexPath, key: String))
case listTapped((indexPath: IndexPath, key: String))
case playTapped((indexPath: IndexPath, key: String))
}

Expand Down Expand Up @@ -65,9 +63,6 @@ class ListStorageTableViewCell: UITableViewCell {

private let countContainerView: UIView = UIView()

private let cellSelectButton = UIButton()
private let listSelectButton = UIButton()

weak var delegate: ListStorageTableViewCellDelegate?
var passToModel: (IndexPath, String) = (IndexPath(row: 0, section: 0), "")

Expand All @@ -89,9 +84,7 @@ extension ListStorageTableViewCell {
self.contentView.addSubviews(
playlistImageView,
verticalStackView,
playButton,
cellSelectButton,
listSelectButton
playButton
)
verticalStackView.addArrangedSubviews(nameLabel, countContainerView)
countContainerView.addSubviews(countLabel, lockImageView)
Expand All @@ -116,18 +109,6 @@ extension ListStorageTableViewCell {
$0.right.equalToSuperview().inset(20)
}

cellSelectButton.snp.makeConstraints {
$0.verticalEdges.equalToSuperview()
$0.left.equalToSuperview()
$0.right.equalTo(verticalStackView.snp.right)
}

listSelectButton.snp.makeConstraints {
$0.verticalEdges.equalToSuperview()
$0.left.equalToSuperview()
$0.right.equalTo(verticalStackView.snp.right)
}

nameLabel.snp.makeConstraints {
$0.height.equalTo(22)
}
Expand All @@ -146,8 +127,6 @@ extension ListStorageTableViewCell {
}

func setAction() {
self.cellSelectButton.addTarget(self, action: #selector(cellSelectButtonAction), for: .touchUpInside)
self.listSelectButton.addTarget(self, action: #selector(listSelectButtonAction), for: .touchUpInside)
self.playButton.addTarget(self, action: #selector(playButtonAction), for: .touchUpInside)
}

Expand All @@ -171,8 +150,6 @@ extension ListStorageTableViewCell {
)

self.backgroundColor = model.isSelected ? DesignSystemAsset.BlueGrayColor.blueGray200.color : UIColor.clear
self.cellSelectButton.isHidden = !isEditing
self.listSelectButton.isHidden = isEditing
self.playButton.isHidden = isEditing
self.lockImageView.isHidden = !model.private

Expand All @@ -198,14 +175,6 @@ extension ListStorageTableViewCell {
}

extension ListStorageTableViewCell {
@objc func cellSelectButtonAction() {
delegate?.buttonTapped(type: .cellTapped(passToModel))
}

@objc func listSelectButtonAction() {
delegate?.buttonTapped(type: .listTapped(passToModel))
}

@objc func playButtonAction() {
delegate?.buttonTapped(type: .playTapped(passToModel))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class ListStorageView: UIView {
$0.backgroundColor = .clear
$0.register(ListStorageTableViewCell.self, forCellReuseIdentifier: ListStorageTableViewCell.reuseIdentifer)
$0.separatorStyle = .none
$0.allowsSelectionDuringEditing = true
}

fileprivate let drawFruitButton = UIButton().then {
Expand Down

0 comments on commit 676545c

Please sign in to comment.