NCCreateFormUploadConflict.swift 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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. @objc required init?(coder aDecoder: NSCoder) {
  38. self.metadatas = [tableMetadata]()
  39. self.metadatasConflict = [tableMetadata]()
  40. super.init(coder: aDecoder)
  41. }
  42. override func viewDidLoad() {
  43. super.viewDidLoad()
  44. tableView.dataSource = self
  45. tableView.delegate = self
  46. tableView.register(UINib.init(nibName: "NCCreateFormUploadConflictCell", bundle: nil), forCellReuseIdentifier: "Cell")
  47. labelTitle.text = String(metadatasConflict.count) + " " + NSLocalizedString("_file_conflict_num_", comment: "")
  48. labelSubTitle.text = NSLocalizedString("_file_conflict_desc_", comment: "")
  49. labelNewFiles.text = NSLocalizedString("_file_conflict_new_", comment: "")
  50. labelAlreadyExistingFiles.text = NSLocalizedString("_file_conflict_exists_", comment: "")
  51. buttonCancel.layer.cornerRadius = 15
  52. buttonCancel.layer.masksToBounds = true
  53. buttonCancel.setTitle(NSLocalizedString("_cancel_", comment: ""), for: .normal)
  54. buttonContinue.layer.cornerRadius = 15
  55. buttonContinue.layer.masksToBounds = true
  56. buttonContinue.setTitle(NSLocalizedString("_continue_", comment: ""), for: .normal)
  57. buttonContinue.isEnabled = false
  58. }
  59. }
  60. // MARK: - UITableViewDelegate
  61. extension NCCreateFormUploadConflict: UITableViewDelegate {
  62. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  63. return 120
  64. }
  65. }
  66. // MARK: - UITableViewDataSource
  67. extension NCCreateFormUploadConflict: UITableViewDataSource {
  68. func numberOfSections(in tableView: UITableView) -> Int {
  69. return 1
  70. }
  71. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  72. return metadatasConflict.count
  73. }
  74. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  75. if let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as? NCCreateFormUploadConflictCell {
  76. let metadata = metadatasConflict[indexPath.row]
  77. if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconOcId(metadata.ocId, fileNameView: metadata.fileName)) {
  78. NCUtility.sharedInstance.loadImage(ocId: metadata.ocId, fileNameView: metadata.fileNameView) { (image) in
  79. cell.imageFile.image = image
  80. }
  81. } else {
  82. if metadata.iconName.count > 0 {
  83. cell.imageFile.image = UIImage.init(named: metadata.iconName)
  84. } else {
  85. cell.imageFile.image = UIImage.init(named: "file")
  86. }
  87. }
  88. cell.labelFileName.text = metadata.fileNameView
  89. return cell
  90. }
  91. return UITableViewCell()
  92. }
  93. }