Skip to content

Commit

Permalink
Add archive actions if there are archived habits (iSoron#1345)
Browse files Browse the repository at this point in the history
  • Loading branch information
kursadsaka authored Apr 12, 2022
1 parent 4469f86 commit b79f785
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions uhabits-ios/Application/Frontend/MainScreenController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
}

0 comments on commit b79f785

Please sign in to comment.