123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- import UIKit
- class MasterDndDaysViewController: ThemedTableViewController {
-
- var days:[String] = Calendar.current.weekdaySymbols
- var selectedIndexPaths:NSMutableOrderedSet = NSMutableOrderedSet()
- override func viewDidLoad() {
- super.viewDidLoad()
-
- self.title = BundleUtil.localizedString(forKey: "settings_notifications_masterDnd_workingDays")
- }
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
-
- selectedIndexPaths = NSMutableOrderedSet.init(orderedSet: UserSettings.shared().masterDndWorkingDays)
-
- tableView.reloadData()
- }
-
- override func viewWillDisappear(_ animated: Bool) {
- super.viewWillDisappear(animated)
-
- UserSettings.shared().masterDndWorkingDays = selectedIndexPaths
- }
- // MARK: - Table view data source
- override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return days.count
- }
-
- override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let cell = tableView.dequeueReusableCell(withIdentifier: "MasterDndDaysCell", for: indexPath)
-
- var row = indexPath.row + Calendar.current.firstWeekday
- if row > days.count {
- row = row - days.count
- }
- cell.textLabel?.text = days[row - 1]
- if selectedIndexPaths.contains(row) {
- cell.accessoryType = .checkmark
- } else {
- cell.accessoryType = .none
- }
- return cell
- }
- override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let cell = tableView.cellForRow(at: indexPath)
- var row = indexPath.row + Calendar.current.firstWeekday
- if row > days.count {
- row = row - days.count
- }
- if selectedIndexPaths.contains(row) {
- selectedIndexPaths.remove(row)
- cell?.accessoryType = .none
- } else {
- selectedIndexPaths.add(row)
- cell?.accessoryType = .checkmark
- }
- tableView.deselectRow(at: indexPath, animated: true)
- }
- }
|