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

Dont select rows without action #755

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 39 additions & 27 deletions Zotero/Scenes/Detail/Items/Views/ItemsTableViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ final class ItemsTableViewHandler: NSObject {
case attachment(attachment: Attachment, parentKey: String?)
case doi(String)
case url(URL)
case selectItem(String)
}

private static let cellId = "ItemCell"
Expand Down Expand Up @@ -248,6 +249,36 @@ final class ItemsTableViewHandler: NSObject {
})
}

private func tapAction(for indexPath: IndexPath) -> TapAction? {
guard let item = self.snapshot?[indexPath.row] else { return nil }

if self.viewModel.state.isEditing {
return .selectItem(item.key)
}

guard let accessory = self.viewModel.state.itemAccessories[item.key] else {
switch item.rawType {
case ItemTypes.note:
return .note(item)

default:
return nil
}
}

switch accessory {
case .attachment(let attachment):
let parentKey = item.key == attachment.key ? nil : item.key
return .attachment(attachment: attachment, parentKey: parentKey)

case .doi(let doi):
return .doi(doi)

case .url(let url):
return .url(url)
}
}

// MARK: - Setups

private func setupTableView() {
Expand Down Expand Up @@ -342,6 +373,7 @@ extension ItemsTableViewHandler: UITableViewDataSource {
return true
})
cell.accessibilityCustomActions = [openInfoAction]
cell.selectionStyle = self.tapAction(for: indexPath) != nil ? .default : .none
}

return cell
Expand All @@ -350,37 +382,17 @@ extension ItemsTableViewHandler: UITableViewDataSource {

extension ItemsTableViewHandler: UITableViewDelegate {
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let item = self.snapshot?[indexPath.row] else { return }

if self.viewModel.state.isEditing {
self.viewModel.process(action: .selectItem(item.key))
return
}
guard let action = self.tapAction(for: indexPath) else { return }

tableView.deselectRow(at: indexPath, animated: true)
switch action {
case .attachment, .doi, .metadata, .note, .url:
tableView.deselectRow(at: indexPath, animated: true)

guard let accessory = self.viewModel.state.itemAccessories[item.key] else {
switch item.rawType {
case ItemTypes.note:
self.tapObserver.on(.next(.note(item)))

default:
break
}
return
case .selectItem:
break
}

switch accessory {
case .attachment(let attachment):
let parentKey = item.key == attachment.key ? nil : item.key
self.tapObserver.on(.next(.attachment(attachment: attachment, parentKey: parentKey)))

case .doi(let doi):
self.tapObserver.on(.next(.doi(doi)))

case .url(let url):
self.tapObserver.on(.next(.url(url)))
}
self.tapObserver.on(.next(action))
}

func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) {
Expand Down
3 changes: 3 additions & 0 deletions Zotero/Scenes/Detail/Items/Views/ItemsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,9 @@ final class ItemsViewController: UIViewController {
case .url(let url):
self.coordinatorDelegate?.show(url: url)

case .selectItem(let key):
self.viewModel.process(action: .selectItem(key))

case .note(let item):
guard let note = Note(item: item) else { return }
let tags = Array(item.tags.map({ Tag(tag: $0) }))
Expand Down