NCCreateFormUploadConflict.swift 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. //
  2. // NCCreateFormUploadConflict.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 29/03/2020.
  6. // Copyright © 2020 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. //
  23. import Foundation
  24. @objc class NCCreateFormUploadConflict: UIViewController {
  25. @IBOutlet weak var labelTitle: UILabel!
  26. @IBOutlet weak var labelSubTitle: UILabel!
  27. @IBOutlet weak var switchNewFiles: UISwitch!
  28. @IBOutlet weak var switchAlreadyExistingFiles: UISwitch!
  29. @IBOutlet weak var labelNewFiles: UILabel!
  30. @IBOutlet weak var labelAlreadyExistingFiles: UILabel!
  31. @IBOutlet weak var tableView: UITableView!
  32. @IBOutlet weak var buttonCancel: UIButton!
  33. @IBOutlet weak var buttonContinue: UIButton!
  34. private let appDelegate = UIApplication.shared.delegate as! AppDelegate
  35. @objc var metadatas: [tableMetadata]
  36. @objc var metadatasConflict: [tableMetadata]
  37. var metadatasConflictNewFiles = [String]()
  38. var metadatasConflictNewAlreadyExistingFiles = [String]()
  39. @objc required init?(coder aDecoder: NSCoder) {
  40. self.metadatas = [tableMetadata]()
  41. self.metadatasConflict = [tableMetadata]()
  42. super.init(coder: aDecoder)
  43. }
  44. override func viewDidLoad() {
  45. super.viewDidLoad()
  46. tableView.dataSource = self
  47. tableView.delegate = self
  48. tableView.tableFooterView = UIView()
  49. tableView.register(UINib.init(nibName: "NCCreateFormUploadConflictCell", bundle: nil), forCellReuseIdentifier: "Cell")
  50. labelTitle.text = String(metadatasConflict.count) + " " + NSLocalizedString("_file_conflict_num_", comment: "")
  51. labelSubTitle.text = NSLocalizedString("_file_conflict_desc_", comment: "")
  52. labelNewFiles.text = NSLocalizedString("_file_conflict_new_", comment: "")
  53. labelAlreadyExistingFiles.text = NSLocalizedString("_file_conflict_exists_", comment: "")
  54. switchNewFiles.isOn = false
  55. switchAlreadyExistingFiles.isOn = false
  56. buttonCancel.layer.cornerRadius = 20
  57. buttonCancel.layer.masksToBounds = true
  58. buttonCancel.setTitle(NSLocalizedString("_cancel_", comment: ""), for: .normal)
  59. buttonCancel.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.5).cgColor
  60. buttonContinue.layer.cornerRadius = 20
  61. buttonContinue.layer.masksToBounds = true
  62. buttonContinue.setTitle(NSLocalizedString("_continue_", comment: ""), for: .normal)
  63. buttonContinue.isEnabled = false
  64. buttonContinue.layer.backgroundColor = NCBrandColor.sharedInstance.graySoft.withAlphaComponent(0.5).cgColor
  65. }
  66. @IBAction func valueChangedSwitchNewFiles(_ sender: Any) {
  67. metadatasConflictNewFiles.removeAll()
  68. if switchNewFiles.isOn {
  69. for metadata in metadatasConflict {
  70. metadatasConflictNewFiles.append(metadata.fileId)
  71. }
  72. }
  73. tableView.reloadData()
  74. }
  75. @IBAction func valueChangedSwitchAlreadyExistingFiles(_ sender: Any) {
  76. metadatasConflictNewAlreadyExistingFiles.removeAll()
  77. if switchAlreadyExistingFiles.isOn {
  78. for metadata in metadatasConflict {
  79. metadatasConflictNewAlreadyExistingFiles.append(metadata.fileId)
  80. }
  81. }
  82. tableView.reloadData()
  83. }
  84. }
  85. // MARK: - UITableViewDelegate
  86. extension NCCreateFormUploadConflict: UITableViewDelegate {
  87. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  88. return 135
  89. }
  90. }
  91. // MARK: - UITableViewDataSource
  92. extension NCCreateFormUploadConflict: UITableViewDataSource {
  93. func numberOfSections(in tableView: UITableView) -> Int {
  94. return 1
  95. }
  96. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  97. return metadatasConflict.count
  98. }
  99. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  100. if let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? NCCreateFormUploadConflictCell {
  101. let metadata = metadatasConflict[indexPath.row]
  102. cell.fileId = metadata.fileId
  103. cell.delegate = self
  104. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName)) {
  105. NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
  106. cell.imageFile.image = image
  107. }
  108. } else {
  109. if metadata.iconName.count > 0 {
  110. cell.imageFile.image = UIImage.init(named: metadata.iconName)
  111. } else {
  112. cell.imageFile.image = UIImage.init(named: "file")
  113. }
  114. }
  115. cell.labelFileName.text = metadata.fileNameView
  116. cell.labelDetail.text = CCUtility.dateDiff(metadata.date as Date) + ", " + CCUtility.transformedSize(metadata.size)
  117. if metadatasConflictNewFiles.contains(metadata.fileId) {
  118. cell.switchNewFile.isOn = true
  119. } else {
  120. cell.switchNewFile.isOn = false
  121. }
  122. if metadatasConflictNewAlreadyExistingFiles.contains(metadata.fileId) {
  123. cell.switchAlreadyExistingFile.isOn = true
  124. } else {
  125. cell.switchAlreadyExistingFile.isOn = false
  126. }
  127. return cell
  128. }
  129. return UITableViewCell()
  130. }
  131. }
  132. // MARK: - NCCreateFormUploadConflictCellDelegate
  133. extension NCCreateFormUploadConflict: NCCreateFormUploadConflictCellDelegate {
  134. func valueChangedSwitchNewFile(with fileId: String, sender: Any) {
  135. }
  136. func valueChangedSwitchAlreadyExistingFile(with fileId: String, sender: Any) {
  137. }
  138. }