NCShareUserMenuView.swift 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. //
  2. // NCShareUserMenuView.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/07/2019.
  6. // Copyright © 2019 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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. import Foundation
  23. import FSCalendar
  24. class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkingDelegate, FSCalendarDelegate, FSCalendarDelegateAppearance {
  25. @IBOutlet weak var switchCanReshare: UISwitch!
  26. @IBOutlet weak var labelCanReshare: UILabel!
  27. @IBOutlet weak var switchSetExpirationDate: UISwitch!
  28. @IBOutlet weak var labelSetExpirationDate: UILabel!
  29. @IBOutlet weak var fieldSetExpirationDate: UITextField!
  30. @IBOutlet weak var imageNoteToRecipient: UIImageView!
  31. @IBOutlet weak var labelNoteToRecipient: UILabel!
  32. @IBOutlet weak var fieldNoteToRecipient: UITextField!
  33. @IBOutlet weak var buttonUnshare: UIButton!
  34. @IBOutlet weak var labelUnshare: UILabel!
  35. @IBOutlet weak var imageUnshare: UIImageView!
  36. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  37. public let width: CGFloat = 250
  38. public let height: CGFloat = 340
  39. private var tableShare: tableShare?
  40. public var metadata: tableMetadata?
  41. public var viewWindow: UIView?
  42. public var viewWindowCalendar: UIView?
  43. override func awakeFromNib() {
  44. self.frame.size.width = width
  45. self.frame.size.height = height
  46. layer.borderColor = UIColor.lightGray.cgColor
  47. layer.borderWidth = 0.5
  48. layer.cornerRadius = 5
  49. layer.masksToBounds = false
  50. layer.shadowOffset = CGSize(width: 2, height: 2)
  51. layer.shadowOpacity = 0.2
  52. switchCanReshare.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
  53. switchCanReshare.onTintColor = NCBrandColor.sharedInstance.brand
  54. switchSetExpirationDate.transform = CGAffineTransform(scaleX: 0.75, y: 0.75)
  55. switchSetExpirationDate.onTintColor = NCBrandColor.sharedInstance.brand
  56. fieldSetExpirationDate.inputView = UIView()
  57. imageNoteToRecipient.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "file_txt"), width: 100, height: 100, color: UIColor(red: 76/255, green: 76/255, blue: 76/255, alpha: 1))
  58. imageUnshare.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "trash"), width: 100, height: 100, color: UIColor(red: 76/255, green: 76/255, blue: 76/255, alpha: 1))
  59. }
  60. func unLoad() {
  61. viewWindowCalendar?.removeFromSuperview()
  62. viewWindow?.removeFromSuperview()
  63. viewWindowCalendar = nil
  64. viewWindow = nil
  65. }
  66. func reloadData(idRemoteShared: Int) {
  67. tableShare = NCManageDatabase.sharedInstance.getTableShare(account: metadata!.account, idRemoteShared: idRemoteShared)
  68. // Can reshare
  69. if tableShare != nil && tableShare!.permissions > Int(k_read_share_permission) {
  70. //switchAllowEditing.setOn(true, animated: false)
  71. } else {
  72. //switchAllowEditing.setOn(false, animated: false)
  73. }
  74. // Set expiration date
  75. if tableShare != nil && tableShare!.expirationDate != nil {
  76. switchSetExpirationDate.setOn(true, animated: false)
  77. fieldSetExpirationDate.isEnabled = true
  78. let dateFormatter = DateFormatter()
  79. dateFormatter.formatterBehavior = .behavior10_4
  80. dateFormatter.dateStyle = .medium
  81. fieldSetExpirationDate.text = dateFormatter.string(from: tableShare!.expirationDate! as Date)
  82. } else {
  83. switchSetExpirationDate.setOn(false, animated: false)
  84. fieldSetExpirationDate.isEnabled = false
  85. fieldSetExpirationDate.text = ""
  86. }
  87. // Note to recipient
  88. if tableShare != nil {
  89. fieldNoteToRecipient.text = tableShare!.note
  90. } else {
  91. fieldNoteToRecipient.text = ""
  92. }
  93. }
  94. // delegate networking
  95. func readShareCompleted(errorCode: Int) {
  96. reloadData(idRemoteShared: tableShare?.idRemoteShared ?? 0)
  97. }
  98. func shareCompleted(errorCode: Int) {
  99. unLoad()
  100. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadDataNCShare"), object: nil, userInfo: nil)
  101. }
  102. func unShareCompleted() {
  103. unLoad()
  104. NotificationCenter.default.post(name: NSNotification.Name(rawValue: "reloadDataNCShare"), object: nil, userInfo: nil)
  105. }
  106. func updateShareWithError(idRemoteShared: Int) {
  107. reloadData(idRemoteShared: idRemoteShared)
  108. }
  109. }