CCNotification.swift 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // CCNotification.swift
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 27/01/17.
  6. // Copyright (c) 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. class CCNotification: UITableViewController, UISearchResultsUpdating {
  25. var resultSearchController = UISearchController()
  26. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  27. override func viewDidLoad() {
  28. super.viewDidLoad()
  29. self.navigationController?.navigationBar.topItem?.title = NSLocalizedString("_notification_", comment: "")
  30. self.navigationItem.setRightBarButton(UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(close)), animated: true)
  31. self.resultSearchController = ({
  32. let controller = UISearchController(searchResultsController: nil)
  33. controller.searchBar.sizeToFit()
  34. controller.searchResultsUpdater = self
  35. controller.dimsBackgroundDuringPresentation = false
  36. controller.searchBar.scopeButtonTitles = ["A", "B", "C", "D"]
  37. self.tableView.tableHeaderView = controller.searchBar
  38. self.tableView.tableFooterView = UIView()
  39. return controller
  40. })()
  41. self.tableView.reloadData()
  42. }
  43. override func didReceiveMemoryWarning() {
  44. super.didReceiveMemoryWarning()
  45. }
  46. func close() {
  47. self.dismiss(animated: true) {
  48. }
  49. }
  50. override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  51. return true
  52. }
  53. override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
  54. let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
  55. print("favorite button tapped")
  56. }
  57. favorite.backgroundColor = .red
  58. let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
  59. print("share button tapped")
  60. }
  61. share.backgroundColor = .green
  62. return [share, favorite]
  63. }
  64. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  65. return 120
  66. }
  67. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  68. if self.resultSearchController.isActive {
  69. return 0
  70. } else {
  71. let numRecord = appDelegate.listOfNotifications.count
  72. return numRecord
  73. }
  74. }
  75. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  76. let cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCNotificationCell
  77. if self.resultSearchController.isActive {
  78. } else {
  79. let idsNotification: [String] = appDelegate.listOfNotifications.allKeys as! [String]
  80. let idNotification : String! = idsNotification[indexPath.row]
  81. let notification = appDelegate.listOfNotifications[idNotification] as! OCNotifications
  82. cell.date.text = DateFormatter.localizedString(from: notification.date, dateStyle: .medium, timeStyle: .medium)
  83. cell.subject.text = "let notification = appDelegate.listOfNotifications[idNotification] as! OCNotificationslet notification = appDelegate.listOfNotifications[idNotification] as! OCNotifications"//notification.subject
  84. cell.message.text = "let notification = appDelegate.listOfNotifications[idNotification] as! OCNotificationslet notification = appDelegate.listOfNotifications[idNotification] as! OCNotifications"//notification.message
  85. }
  86. return cell
  87. }
  88. func updateSearchResults(for searchController: UISearchController) {
  89. }
  90. }
  91. // MARK: - Class UITableViewCell
  92. class CCNotificationCell: UITableViewCell {
  93. @IBOutlet weak var icon : UIImageView!
  94. @IBOutlet weak var date: UILabel!
  95. @IBOutlet weak var subject: UILabel!
  96. @IBOutlet weak var message: UILabel!
  97. }