refactor: use `tableView.allowsMultipleSelection`

This commit is contained in:
ihugo 2021-04-25 18:28:47 +08:00
parent db48e56dd9
commit e9d015720b
4 changed files with 27 additions and 19 deletions

View File

@ -48,7 +48,13 @@ extension ReportSection {
)
}
cell.setupSelected(attribute.isSelected)
// defalut to select the report status
if attribute.isSelected {
tableView.selectRow(at: indexPath, animated: false, scrollPosition: .none)
} else {
tableView.deselectRow(at: indexPath, animated: false)
}
return cell
default:
return nil

View File

@ -68,6 +68,7 @@ class ReportViewController: UIViewController, NeedsDependency {
tableView.backgroundColor = .clear
tableView.translatesAutoresizingMaskIntoConstraints = false
tableView.delegate = self
tableView.allowsMultipleSelection = true
return tableView
}()
@ -277,7 +278,13 @@ extension ReportViewController: UITableViewDelegate {
guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else {
return
}
didToggleSelected.send(item)
}
func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
guard let item = viewModel.diffableDataSource?.itemIdentifier(for: indexPath) else {
return
}
didToggleSelected.send(item)
}
}

View File

@ -113,7 +113,6 @@ class ReportViewModel: NSObject {
input.didToggleSelected.sink { [weak self] (item) in
guard let self = self else { return }
guard case let .reportStatus(objectID, attribute) = item else { return }
guard var snapshot = self.diffableDataSource?.snapshot() else { return }
let managedObjectContext = self.statusFetchedResultsController.fetchedResultsController.managedObjectContext
guard let status = managedObjectContext.object(with: objectID) as? Status else {
return
@ -126,9 +125,6 @@ class ReportViewModel: NSObject {
self.reportQuery.remove(statusID: status.id)
}
snapshot.reloadItems([item])
self.diffableDataSource?.apply(snapshot, animatingDifferences: false)
let continueEnable = (self.reportQuery.statusIDs?.count ?? 0) > 0
self.continueEnableSubject.send(continueEnable)
}

View File

@ -20,7 +20,6 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell {
var disposeBag = Set<AnyCancellable>()
var pollCountdownSubscription: AnyCancellable?
var observations = Set<NSKeyValueObservation>()
var checked: Bool = false
let statusView = StatusView()
let separatorLine = UIView.separatorLine
@ -42,7 +41,6 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell {
override func prepareForReuse() {
super.prepareForReuse()
checked = false
statusView.updateContentWarningDisplay(isHidden: true, animated: false)
statusView.statusMosaicImageViewContainer.contentWarningOverlayView.isUserInteractionEnabled = true
statusView.pollTableView.dataSource = nil
@ -75,11 +73,22 @@ final class ReportedStatusTableViewCell: UITableViewCell, StatusCell {
if highlighted {
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
checkbox.tintColor = Asset.Colors.Label.highlight.color
} else if !checked {
} else if !isSelected {
checkbox.image = UIImage(systemName: "circle")
checkbox.tintColor = Asset.Colors.Label.secondary.color
}
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if isSelected {
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
} else {
checkbox.image = UIImage(systemName: "circle")
}
checkbox.tintColor = Asset.Colors.Label.secondary.color
}
}
extension ReportedStatusTableViewCell {
@ -127,16 +136,6 @@ extension ReportedStatusTableViewCell {
resetSeparatorLineLayout()
}
func setupSelected(_ selected: Bool) {
checked = selected
if selected {
checkbox.image = UIImage(systemName: "checkmark.circle.fill")
} else {
checkbox.image = UIImage(systemName: "circle")
}
checkbox.tintColor = Asset.Colors.Label.secondary.color
}
}
extension ReportedStatusTableViewCell {