NCTransfers.swift 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. //
  2. // NCTransfers.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 17/09/2020.
  6. // Copyright © 2018 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. import NCCommunication
  25. class NCTransfers: NCCollectionViewCommon {
  26. required init?(coder aDecoder: NSCoder) {
  27. super.init(coder: aDecoder)
  28. appDelegate.activeTransfers = self
  29. titleCurrentFolder = NSLocalizedString("_transfers_", comment: "")
  30. layoutKey = k_layout_view_transfers
  31. enableSearchBar = false
  32. DZNimage = CCGraphics.changeThemingColorImage(UIImage.init(named: "load"), width: 300, height: 300, color: NCBrandColor.sharedInstance.brandElement)
  33. DZNtitle = "_no_transfer_"
  34. DZNdescription = "_no_transfer_sub_"
  35. }
  36. override func viewWillAppear(_ animated: Bool) {
  37. super.viewWillAppear(animated)
  38. }
  39. // MARK: - Collection View
  40. override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  41. guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return }
  42. metadataPush = metadata
  43. if isEditMode {
  44. if let index = selectOcId.firstIndex(of: metadata.ocId) {
  45. selectOcId.remove(at: index)
  46. } else {
  47. selectOcId.append(metadata.ocId)
  48. }
  49. collectionView.reloadItems(at: [indexPath])
  50. return
  51. }
  52. if metadata.directory {
  53. guard let serverUrlPush = CCUtility.stringAppendServerUrl(metadataPush!.serverUrl, addFileName: metadataPush!.fileName) else { return }
  54. let ncOffline:NCOffline = UIStoryboard(name: "NCOffline", bundle: nil).instantiateInitialViewController() as! NCOffline
  55. ncOffline.serverUrl = serverUrlPush
  56. ncOffline.titleCurrentFolder = metadataPush!.fileNameView
  57. self.navigationController?.pushViewController(ncOffline, animated: true)
  58. } else {
  59. if CCUtility.fileProviderStorageExists(metadataPush?.ocId, fileNameView: metadataPush?.fileNameView) {
  60. performSegue(withIdentifier: "segueDetail", sender: self)
  61. } else {
  62. NCNetworking.shared.download(metadata: metadataPush!, selector: "") { (errorCode) in
  63. if errorCode == 0 {
  64. self.performSegue(withIdentifier: "segueDetail", sender: self)
  65. }
  66. }
  67. }
  68. }
  69. }
  70. // MARK: - NC API & Algorithm
  71. override func reloadDataSource() {
  72. super.reloadDataSource()
  73. var sort: String
  74. var ascending: Bool
  75. var directoryOnTop: Bool
  76. (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey)
  77. metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "(session CONTAINS 'upload') OR (session CONTAINS 'download')"), page: 1, limit: 100, sorted: "sessionTaskIdentifier", ascending: false)
  78. self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
  79. refreshControl.endRefreshing()
  80. collectionView.reloadData()
  81. }
  82. override func reloadDataSourceNetwork() {
  83. super.reloadDataSourceNetwork()
  84. reloadDataSource()
  85. }
  86. }