From b79f7850ed3213efd0f4c66911e3c3c04c2a0653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=BCr=C5=9Fad=20Bumin=20Giray=20Saka?= Date: Tue, 12 Apr 2022 04:50:44 +0300 Subject: [PATCH] Add archive actions if there are archived habits (#1345) --- .../Frontend/MainScreenController.swift | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/uhabits-ios/Application/Frontend/MainScreenController.swift b/uhabits-ios/Application/Frontend/MainScreenController.swift index e50974aaf..7c4d9136d 100644 --- a/uhabits-ios/Application/Frontend/MainScreenController.swift +++ b/uhabits-ios/Application/Frontend/MainScreenController.swift @@ -190,18 +190,20 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener @objc func onMoreActionsClicked() { let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet) - if preferences.showArchived { - alert.addAction(UIAlertAction(title: strings.hide_archived, style: .default) { - (action: UIAlertAction) -> Void in - self.preferences.showArchived = false - self.dataSource.requestData() - }) - } else { - alert.addAction(UIAlertAction(title: strings.show_archived, style: .default) { - (action: UIAlertAction) -> Void in - self.preferences.showArchived = true - self.dataSource.requestData() - }) + if isThereAnyArchivedHabit() { + if preferences.showArchived { + alert.addAction(UIAlertAction(title: strings.hide_archived, style: .default) { + (action: UIAlertAction) -> Void in + self.preferences.showArchived = false + self.dataSource.requestData() + }) + } else { + alert.addAction(UIAlertAction(title: strings.show_archived, style: .default) { + (action: UIAlertAction) -> Void in + self.preferences.showArchived = true + self.dataSource.requestData() + }) + } } if preferences.showCompleted { @@ -262,4 +264,8 @@ class MainScreenController: UITableViewController, MainScreenDataSourceListener let sections = NSIndexSet(indexesIn: NSMakeRange(0, self.tableView.numberOfSections)) tableView.reloadSections(sections as IndexSet, with: .automatic) } + + func isThereAnyArchivedHabit() -> Bool { + return data!.habits.filter({ $0.isArchived }).count > 0 + } }