Add archive actions if there are archived habits (#1345)

pull/1349/head
Kürşad Bumin Giray Saka 4 years ago committed by GitHub
parent 4469f86e46
commit b79f7850ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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
}
}

Loading…
Cancel
Save