From c96a652543f0e7bcf2103dafba8f7987cce3a6ee Mon Sep 17 00:00:00 2001 From: Alexander Borsuk Date: Sat, 28 Aug 2021 09:55:37 +0200 Subject: [PATCH] [ios] Fixed minor issues Signed-off-by: Alexander Borsuk --- .../Cells/MWMMapDownloaderTableViewCell.m | 19 +++++++++++++++---- .../DownloadMapsViewController.swift | 12 +++++++----- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderTableViewCell.m b/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderTableViewCell.m index 96ec5d0dea..6bedb06657 100644 --- a/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderTableViewCell.m +++ b/iphone/Maps/UI/Downloader/Cells/MWMMapDownloaderTableViewCell.m @@ -89,11 +89,11 @@ self.downloadSize.hidden = (size == 0); } -- (void)configProgress:(MWMMapNodeAttributes *)nodeAttrs { +- (void)configProgress:(MWMMapNodeAttributes *)na { MWMCircularProgress *progress = self.progress; BOOL isModeDownloaded = self.mode == MWMMapDownloaderModeDownloaded; MWMButtonColoring coloring = isModeDownloaded ? MWMButtonColoringBlack : MWMButtonColoringBlue; - switch (nodeAttrs.nodeStatus) { + switch (na.nodeStatus) { case MWMMapNodeStatusNotDownloaded: case MWMMapNodeStatusPartly: { MWMCircularProgressStateVec affectedStates = @[@(MWMCircularProgressStateNormal), @(MWMCircularProgressStateSelected)]; @@ -102,9 +102,20 @@ progress.state = MWMCircularProgressStateNormal; break; } - case MWMMapNodeStatusDownloading: - progress.progress = kMaxProgress * nodeAttrs.downloadedSize / (isModeDownloaded ? nodeAttrs.totalUpdateSizeBytes : nodeAttrs.totalSize - nodeAttrs.downloadingSize); + case MWMMapNodeStatusDownloading: { + // Avoid NaN and +inf. + // TODO: Refactor downloader and do not allow these situations to happen. + float denominator; + if (isModeDownloaded) { + denominator = na.totalUpdateSizeBytes ? na.totalUpdateSizeBytes : na.totalSize; + } else { + uint64_t const diff = na.totalSize - na.downloadingSize; + denominator = diff > 0 ? diff : na.totalSize; + } + assert(denominator); + progress.progress = kMaxProgress * na.downloadedSize / denominator; break; + } case MWMMapNodeStatusApplying: case MWMMapNodeStatusInQueue: progress.state = MWMCircularProgressStateSpinner; diff --git a/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift b/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift index 87efc362bc..95c5051e8a 100644 --- a/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift +++ b/iphone/Maps/UI/Downloader/DownloadMapsViewController.swift @@ -406,11 +406,13 @@ extension DownloadMapsViewController: StorageObserver { configButtons() } - for cell in tableView.visibleCells { - guard let downloaderCell = cell as? MWMMapDownloaderTableViewCell else { continue } - if downloaderCell.nodeAttrs.countryId != countryId { continue } - guard let indexPath = tableView.indexPath(for: downloaderCell) else { return } - downloaderCell.config(dataSource.item(at: indexPath), searchQuery: searchBar.text) + for _ in tableView.visibleCells { + // Referencing tableView.visibleCells automatically initializes them, so the code below is not needed. + // See func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell +// guard let downloaderCell = cell as? MWMMapDownloaderTableViewCell else { continue } +// if downloaderCell.nodeAttrs.countryId != countryId { continue } +// guard let indexPath = tableView.indexPath(for: downloaderCell) else { return } +// downloaderCell.config(dataSource.item(at: indexPath), searchQuery: searchBar.text) } }