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

πŸ”€ :: [#1309] Long Press μ§„μž…μ μ˜ UXκ°€ 비정상적인 이슈 #1311

Merged
merged 5 commits into from
Oct 13, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,8 @@ private extension MyPlaylistDetailReactor {
func didLongPressedPlaylist(indexPath: IndexPath) -> Observable<Mutation> {
guard !currentState.isEditing else { return .empty() }
return .concat(
beginEditing(),
updateItemSelected(indexPath.row)
updateItemSelected(indexPath.row),
beginEditing()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ final class MyPlaylistDetailViewController: BaseReactorViewController<MyPlaylist
super.bind(reactor: reactor)
tableView.rx.setDelegate(self)
.disposed(by: disposeBag)
tableView.dragDelegate = self
}

override func bindAction(reactor: MyPlaylistDetailReactor) {
Expand Down Expand Up @@ -494,7 +495,7 @@ extension MyPlaylistDetailViewController {
}

/// ν…Œμ΄λΈ” λ·° 델리게이트
extension MyPlaylistDetailViewController: UITableViewDelegate {
extension MyPlaylistDetailViewController: UITableViewDelegate, UITableViewDragDelegate {
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return CGFloat(60.0)
}
Expand Down Expand Up @@ -535,19 +536,14 @@ extension MyPlaylistDetailViewController: UITableViewDelegate {
return false // νŽΈμ§‘λͺ¨λ“œ μ‹œ μ…€μ˜ λ“€μ—¬μ“°κΈ°λ₯Ό μ—†μ• λ €λ©΄ falseλ₯Ό λ¦¬ν„΄ν•©λ‹ˆλ‹€.
}

func tableView(
public 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
})
}
itemsForBeginning session: any UIDragSession,
at indexPath: IndexPath
) -> [UIDragItem] {
let dragItem = UIDragItem(itemProvider: NSItemProvider())
reactor?.action.onNext(.didLongPressedPlaylist(indexPath))
return [dragItem]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extension PlaylistViewController: SongCartViewDelegate {
}
}

extension PlaylistViewController: UITableViewDelegate {
extension PlaylistViewController: UITableViewDelegate, UITableViewDragDelegate {
public func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCell
.EditingStyle {
return .none // νŽΈμ§‘λͺ¨λ“œ μ‹œ μ™Όμͺ½ λ²„νŠΌμ„ 숨기렀면 .none을 λ¦¬ν„΄ν•©λ‹ˆλ‹€.
Expand Down Expand Up @@ -123,17 +123,12 @@ extension PlaylistViewController: UITableViewDelegate {

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
})
}
itemsForBeginning session: any UIDragSession,
at indexPath: IndexPath
) -> [UIDragItem] {
let dragItem = UIDragItem(itemProvider: NSItemProvider())
didLongPressedSongSubject.onNext(indexPath.row)
return [dragItem]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public final class PlaylistViewController: UIViewController, SongCartViewType {
override public func viewDidLoad() {
super.viewDidLoad()
playlistView.playlistTableView.rx.setDelegate(self).disposed(by: disposeBag)
playlistView.playlistTableView.dragDelegate = self
// playlistView.playlistTableView.dragInteractionEnabled = true
bindViewModel()
bindActions()
}
Expand Down Expand Up @@ -173,13 +175,18 @@ private extension PlaylistViewController {
}

private func bindPlaylistTableView(output: PlaylistViewModel.Output) {
output.editState.sink { [weak self] isEditing in
output.editState.sink { [weak self] isEditing, reloadStrategy in
guard let self else { return }
self.playlistView.titleLabel.text = isEditing ? "μž¬μƒλͺ©λ‘ νŽΈμ§‘" : "μž¬μƒλͺ©λ‘"
self.playlistView.editButton.setTitle(isEditing ? "μ™„λ£Œ" : "νŽΈμ§‘", for: .normal)
self.playlistView.editButton.setColor(isHighlight: isEditing)
self.playlistView.playlistTableView.setEditing(isEditing, animated: true)
self.playlistView.playlistTableView.reloadData()
switch reloadStrategy {
case .reloadAll:
self.playlistView.playlistTableView.reloadData()
case .reloadSection:
self.playlistView.playlistTableView.reloadSections([0], with: .none)
}
}.store(in: &subscription)

output.playlists
Expand Down Expand Up @@ -228,7 +235,7 @@ private extension PlaylistViewController {
tappedCellIndex
] owner, item in

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

if isEditing {
Expand Down Expand Up @@ -306,7 +313,7 @@ extension PlaylistViewController {
cell.selectionStyle = .none

let index = indexPath.row
let isEditing = output.editState.value
let (isEditing, _) = output.editState.value

cell.setContent(
model: model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,13 @@ final class PlaylistViewModel: ViewModelType {
}

struct Output {
enum EditingReloadStrategy {
case reloadSection
case reloadAll
}

var shouldClosePlaylist = PassthroughSubject<Void, Never>()
var editState = CurrentValueSubject<Bool, Never>(false)
var editState = CurrentValueSubject<(Bool, EditingReloadStrategy), Never>((false, .reloadAll))
let playlists: BehaviorRelay<[PlaylistItemModel]> = BehaviorRelay(value: [])
let selectedSongIds: BehaviorRelay<Set<String>> = BehaviorRelay(value: [])
let countOfSongs = CurrentValueSubject<Int, Never>(0)
Expand Down Expand Up @@ -82,11 +87,11 @@ final class PlaylistViewModel: ViewModelType {
LogManager.analytics(log)

self.isEditing.toggle()
output.editState.send(self.isEditing)
output.editState.send((self.isEditing, .reloadAll))
}.store(in: &subscription)

input.playlistTableviewCellDidTapEvent
.filter { _ in output.editState.value == false }
.filter { _ in output.editState.value.0 == false }
.subscribe(onNext: { indexPath in
})
.disposed(by: disposeBag)
Expand Down Expand Up @@ -120,7 +125,7 @@ final class PlaylistViewModel: ViewModelType {
.withUnretained(self)
.subscribe(onNext: { owner, _ in
output.selectedSongIds.accept([])
output.editState.send(false)
output.editState.send((false, .reloadAll))
owner.isEditing = false
})
.disposed(by: disposeBag)
Expand All @@ -132,7 +137,7 @@ final class PlaylistViewModel: ViewModelType {
if selectedIds.count == output.playlists.value.count {
output.playlists.accept([])
output.selectedSongIds.accept([])
output.editState.send(false)
output.editState.send((false, .reloadAll))
output.shouldClosePlaylist.send()
} else {
let removedPlaylists = output.playlists.value
Expand All @@ -157,6 +162,8 @@ final class PlaylistViewModel: ViewModelType {
input.didLongPressedSongEvent
.compactMap { output.playlists.value[safe: $0] }
.bind(with: self) { owner, item in
guard !owner.isEditing else { return }

owner.isEditing.toggle()

var mutableSelectedSongIds = output.selectedSongIds.value
Expand All @@ -166,7 +173,7 @@ final class PlaylistViewModel: ViewModelType {
mutableSelectedSongIds.insert(item.id)
}

output.editState.send(owner.isEditing)
output.editState.send((owner.isEditing, .reloadSection))
output.selectedSongIds.accept(mutableSelectedSongIds)
}
.disposed(by: disposeBag)
Expand All @@ -186,7 +193,7 @@ final class PlaylistViewModel: ViewModelType {
// νŽΈμ§‘ μ’…λ£Œ μ‹œ, μ…€ 선택 μ΄ˆκΈ°ν™”
output.editState
.dropFirst()
.filter { $0 == false }
.filter { $0.0 == false }
.sink { [playState] _ in
output.selectedSongIds.accept([])
playState.update(contentsOf: output.playlists.value.toPlayStateItem())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,9 @@ final class LikeStorageReactor: Reactor {
func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let switchEditingStateMutation = storageCommonService.isEditingState
.skip(1)
.filter { [weak self] in
$0 != self?.currentState.isEditing
}
.withUnretained(self)
.flatMap { owner, editingState -> Observable<Mutation> in
let log = if !editingState {
Expand All @@ -161,18 +164,23 @@ final class LikeStorageReactor: Reactor {
.just(.updateIsShowActivityIndicator(false)),
.just(.updateSelectedItemCount(0)),
.just(.hideSongCart),
owner.setAllSelection(isSelected: false),
.just(.switchEditingState(false))
)
} else {
return .concat(
.just(.updateSelectedItemCount(0)),
.just(.undoDataSource),
.just(.hideSongCart),
owner.setAllSelection(isSelected: false),
.just(.switchEditingState(false))
)
}
} else {
return .just(.switchEditingState(editingState))
return .concat(
.just(.switchEditingState(editingState)),
owner.setAllSelection(isSelected: false)
)
}
}

Expand Down Expand Up @@ -292,8 +300,10 @@ extension LikeStorageReactor {
func didLongPressedPlaylist(indexPath: IndexPath) -> Observable<Mutation> {
guard !currentState.isEditing else { return .empty() }
storageCommonService.isEditingState.onNext(true)
changeSelectingState(indexPath.row)
return .just(.switchEditingState(true))
return .concat(
.just(.switchEditingState(true)),
changeSelectingState(indexPath.row)
)
}

func presentAddToPlaylistPopup() -> Observable<Mutation> {
Expand Down Expand Up @@ -365,15 +375,19 @@ extension LikeStorageReactor {

/// 전체 곑 선택 / ν•΄μ œ
func tapAll(_ flag: Bool) -> Observable<Mutation> {
return setAllSelection(isSelected: flag)
}

func setAllSelection(isSelected: Bool) -> Observable<Mutation> {
guard var tmp = currentState.dataSource.first?.items else {
LogManager.printError("favorite datasource is empty")
return .empty()
}

let count = flag ? tmp.count : 0
let count = isSelected ? tmp.count : 0

for i in 0 ..< tmp.count {
tmp[i].isSelected = flag
tmp[i].isSelected = isSelected
}

return .concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,9 @@ final class ListStorageReactor: Reactor {
func transform(mutation: Observable<Mutation>) -> Observable<Mutation> {
let switchEditingStateMutation = storageCommonService.isEditingState
.skip(1)
.filter { [weak self] in
$0 != self?.currentState.isEditing
}
.withUnretained(self)
.flatMap { owner, editingState -> Observable<Mutation> in
let log = if !editingState {
Expand All @@ -188,19 +191,24 @@ final class ListStorageReactor: Reactor {
owner.mutateEditPlayListOrder(),
.just(.updateIsShowActivityIndicator(false)),
.just(.updateSelectedItemCount(0)),
owner.setAllSelection(isSelected: false),
.just(.hideSongCart),
.just(.switchEditingState(false))
)
} else {
return .concat(
.just(.updateSelectedItemCount(0)),
owner.setAllSelection(isSelected: false),
.just(.undoDataSource),
.just(.hideSongCart),
.just(.switchEditingState(false))
)
}
} else {
return .just(.switchEditingState(editingState))
return .concat(
.just(.switchEditingState(editingState)),
owner.setAllSelection(isSelected: false)
)
}
}

Expand Down Expand Up @@ -471,15 +479,19 @@ extension ListStorageReactor {

/// 전체 곑 선택 / ν•΄μ œ
func tapAll(_ flag: Bool) -> Observable<Mutation> {
return setAllSelection(isSelected: flag)
}

func setAllSelection(isSelected: Bool) -> Observable<Mutation> {
guard var tmp = currentState.dataSource.first?.items else {
LogManager.printError("playlist datasource is empty")
return .empty()
}

let count = flag ? tmp.count : 0
let count = isSelected ? tmp.count : 0

for i in 0 ..< tmp.count {
tmp[i].isSelected = flag
tmp[i].isSelected = isSelected
}

return .concat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ final class LikeStorageViewController: BaseReactorViewController<LikeStorageReac

private func setTableView() {
likeStorageView.tableView.rx.setDelegate(self).disposed(by: disposeBag)
likeStorageView.tableView.dragDelegate = self
}

override func bindState(reactor: LikeStorageReactor) {
Expand Down Expand Up @@ -293,7 +294,7 @@ extension LikeStorageViewController: LikeStorageTableViewCellDelegate {
}
}

extension LikeStorageViewController: UITableViewDelegate {
extension LikeStorageViewController: UITableViewDelegate, UITableViewDragDelegate {
public func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 60
}
Expand All @@ -307,19 +308,14 @@ extension LikeStorageViewController: UITableViewDelegate {
return false // νŽΈμ§‘λͺ¨λ“œ μ‹œ μ…€μ˜ λ“€μ—¬μ“°κΈ°λ₯Ό μ—†μ• λ €λ©΄ falseλ₯Ό λ¦¬ν„΄ν•©λ‹ˆλ‹€.
}

func tableView(
public 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
})
}
itemsForBeginning session: any UIDragSession,
at indexPath: IndexPath
) -> [UIDragItem] {
let dragItem = UIDragItem(itemProvider: NSItemProvider())
reactor?.action.onNext(.didLongPressedPlaylist(indexPath))
return [dragItem]
}
}

Expand Down
Loading
Loading