CCNotification.swift 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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.resultSearchController = ({
  30. let controller = UISearchController(searchResultsController: nil)
  31. controller.searchBar.sizeToFit()
  32. controller.searchResultsUpdater = self
  33. controller.dimsBackgroundDuringPresentation = false
  34. controller.searchBar.scopeButtonTitles = ["A", "B", "C", "D"]
  35. self.tableView.tableHeaderView = controller.searchBar
  36. self.tableView.tableFooterView = UIView()
  37. return controller
  38. })()
  39. self.tableView.reloadData()
  40. }
  41. override func didReceiveMemoryWarning() {
  42. super.didReceiveMemoryWarning()
  43. }
  44. override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
  45. return true
  46. }
  47. override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
  48. let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
  49. print("favorite button tapped")
  50. }
  51. favorite.backgroundColor = .red
  52. let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
  53. print("share button tapped")
  54. }
  55. share.backgroundColor = .green
  56. return [share, favorite]
  57. }
  58. override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  59. return 90
  60. }
  61. override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  62. if self.resultSearchController.isActive {
  63. return 0
  64. } else {
  65. let numRecord = appDelegate.listOfNotifications.count
  66. return numRecord
  67. }
  68. }
  69. override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  70. let cell = self.tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCNotificationCell
  71. if self.resultSearchController.isActive {
  72. } else {
  73. let idsNotification: [String] = appDelegate.listOfNotifications.allKeys as! [String]
  74. let idNotification : String! = idsNotification[indexPath.row]
  75. let notification = appDelegate.listOfNotifications[idNotification] as! OCNotifications
  76. cell.subject.text = notification.subject
  77. cell.message.text = notification.message
  78. }
  79. return cell
  80. }
  81. func updateSearchResults(for searchController: UISearchController) {
  82. }
  83. }
  84. // MARK: - Class UITableViewCell
  85. class CCNotificationCell: UITableViewCell {
  86. @IBOutlet weak var icon : UIImageView!
  87. @IBOutlet weak var subject: UILabel!
  88. @IBOutlet weak var message: UILabel!
  89. }