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 676545c commit 0b862d8
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ extension PlaylistViewController: UITableViewDelegate {
}
return proposedDestinationIndexPath
}

public func tableView(
_ tableView: UITableView,
contextMenuConfigurationForRowAt indexPath: IndexPath,
point: CGPoint
) -> UIContextMenuConfiguration? {
if output.editState.value == true {
return nil
} else {
return UIContextMenuConfiguration(identifier: nil, previewProvider: { [didLongPressedSongSubject] in
didLongPressedSongSubject.onNext(indexPath.row)
return nil
})
}
}
}

extension PlaylistViewController: PlaylistTableViewCellDelegate {
Expand All @@ -132,8 +147,4 @@ extension PlaylistViewController: PlaylistTableViewCellDelegate {
playPlatform: model.title.isContainShortsTagTitle ? .youtube : .automatic
).play()
}

func superButtonTapped(index: Int) {
tappedCellIndex.onNext(index)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public final class PlaylistViewController: UIViewController, SongCartViewType {
var isSelectedAllSongs = PublishSubject<Bool>()
var tappedAddPlaylist = PublishSubject<Void>()
var tappedRemoveSongs = PublishSubject<Void>()
var didLongPressedSongSubject = PublishSubject<Int>()

private(set) var containSongsFactory: any ContainSongsFactory
private(set) var songDetailPresenter: any SongDetailPresentable
Expand All @@ -48,7 +49,8 @@ public final class PlaylistViewController: UIViewController, SongCartViewType {
selectAllSongsButtonDidTapEvent: isSelectedAllSongs.asObservable(),
addPlaylistButtonDidTapEvent: tappedAddPlaylist.asObservable(),
removeSongsButtonDidTapEvent: tappedRemoveSongs.asObservable(),
itemMovedEvent: playlistView.playlistTableView.rx.itemMoved.asObservable()
itemMovedEvent: playlistView.playlistTableView.rx.itemMoved.asObservable(),
didLongPressedSongEvent: didLongPressedSongSubject
)
lazy var output = self.viewModel.transform(from: input)

Expand Down Expand Up @@ -220,18 +222,27 @@ private extension PlaylistViewController {

playlistView.playlistTableView.rx.itemSelected
.withLatestFrom(output.playlists) { ($0, $1) }
.map { $0.1[$0.0.row] }
.bind(with: self, onNext: { [songDetailPresenter] owner, item in
let currentSongs = output.playlists.value
.map(\.id)

owner.dismiss(animated: true) {
songDetailPresenter.present(
ids: Array(currentSongs),
selectedID: item.id
)
.bind(with: self) { [songDetailPresenter, isEditingSubject = output.editState, tappedCellIndex] owner, item in

let isEditing = isEditingSubject.value
let (indexPath, playlists) = item

if isEditing {
tappedCellIndex.onNext(indexPath.row)
} else {
guard let selectedSong = playlists[safe: indexPath.row] else { return }

let currentSongs = playlists
.map(\.id)

owner.dismiss(animated: true) {
songDetailPresenter.present(
ids: Array(currentSongs),
selectedID: selectedSong.id
)
}
}
})
}
.disposed(by: disposeBag)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ final class PlaylistViewModel: ViewModelType {
let addPlaylistButtonDidTapEvent: Observable<Void>
let removeSongsButtonDidTapEvent: Observable<Void>
let itemMovedEvent: Observable<(sourceIndex: IndexPath, destinationIndex: IndexPath)>
let didLongPressedSongEvent: Observable<Int>
}

struct Output {
Expand Down Expand Up @@ -152,6 +153,23 @@ final class PlaylistViewModel: ViewModelType {
playlists.insert(movedData, at: destIndex)
output.playlists.accept(playlists)
}.disposed(by: disposeBag)

input.didLongPressedSongEvent
.compactMap { output.playlists.value[safe: $0] }
.bind(with: self) { owner, item in
owner.isEditing.toggle()

var mutableSelectedSongIds = output.selectedSongIds.value
if mutableSelectedSongIds.contains(item.id) {
mutableSelectedSongIds.remove(item.id)
} else {
mutableSelectedSongIds.insert(item.id)
}

output.editState.send(owner.isEditing)
output.selectedSongIds.accept(mutableSelectedSongIds)
}
.disposed(by: disposeBag)
}

private func bindTableView(output: Output) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public final class PlaylistView: UIView {
$0.sectionHeaderTopPadding = 0
$0.backgroundColor = DesignSystemAsset.BlueGrayColor.blueGray100.color
$0.showsVerticalScrollIndicator = true
$0.allowsSelectionDuringEditing = true
}

override init(frame: CGRect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import UIKit
import Utility

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

Expand Down Expand Up @@ -78,10 +77,6 @@ internal class PlaylistTableViewCell: UITableViewCell {
fatalError("")
}

override func prepareForReuse() {
super.prepareForReuse()
}

private func configureContents() {
self.backgroundColor = .clear
self.contentView.addSubview(self.thumbnailImageView)
Expand Down Expand Up @@ -110,11 +105,6 @@ internal class PlaylistTableViewCell: UITableViewCell {
$0.centerY.equalTo(contentView.snp.centerY)
$0.right.equalTo(contentView.snp.right).offset(-20)
}

superButton.snp.makeConstraints {
$0.left.top.bottom.equalToSuperview()
$0.right.equalToSuperview()
}
}
}

Expand Down Expand Up @@ -151,10 +141,6 @@ extension PlaylistTableViewCell {
owner.delegate?.playButtonDidTap(model: song)
}
.disposed(by: disposeBag)

superButton.addAction { [weak self] in
self?.delegate?.superButtonTapped(index: self?.model.index ?? 0)
}
}

private func updateButtonHidden(isEditing: Bool) {
Expand All @@ -163,7 +149,6 @@ extension PlaylistTableViewCell {
} else {
playImageView.isHidden = false
}
superButton.isHidden = !isEditing
}

private func updateConstraintPlayImageView(isEditing: Bool) {
Expand Down

0 comments on commit 0b862d8

Please sign in to comment.