NCRecent.swift 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // NCRecent.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 29/09/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. import NCCommunication
  25. class NCRecent: NCCollectionViewCommon {
  26. required init?(coder aDecoder: NSCoder) {
  27. super.init(coder: aDecoder)
  28. appDelegate.activeRecent = self
  29. titleCurrentFolder = NSLocalizedString("_recent_", comment: "")
  30. layoutKey = k_layout_view_recent
  31. enableSearchBar = true
  32. DZNimage = CCGraphics.changeThemingColorImage(UIImage.init(named: "recent"), width: 300, height: 300, color: NCBrandColor.sharedInstance.brandElement)
  33. DZNtitle = "_files_no_files_"
  34. DZNdescription = ""
  35. }
  36. override func viewWillAppear(_ animated: Bool) {
  37. super.viewWillAppear(animated)
  38. }
  39. // MARK: - DataSource + NC Endpoint
  40. override func reloadDataSource() {
  41. super.reloadDataSource()
  42. var sort: String
  43. var ascending: Bool
  44. var directoryOnTop: Bool
  45. (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey, serverUrl: "")
  46. metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "account == %@", appDelegate.account), limit: 100, sorted: "date", ascending: true)
  47. self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
  48. refreshControl.endRefreshing()
  49. collectionView.reloadData()
  50. }
  51. override func reloadDataSourceNetwork(forced: Bool = false) {
  52. super.reloadDataSourceNetwork(forced: forced)
  53. let requestBodyRecent =
  54. """
  55. <?xml version=\"1.0\"?>
  56. <d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">
  57. <d:basicsearch>
  58. <d:select>
  59. <d:prop>
  60. <d:displayname/>
  61. <d:getcontenttype/>
  62. <d:resourcetype/>
  63. <d:getcontentlength/>
  64. <d:getlastmodified/>
  65. <d:getetag/>
  66. <d:quota-used-bytes/>
  67. <d:quota-available-bytes/>
  68. <permissions xmlns=\"http://owncloud.org/ns\"/>
  69. <id xmlns=\"http://owncloud.org/ns\"/>
  70. <fileid xmlns=\"http://owncloud.org/ns\"/>
  71. <size xmlns=\"http://owncloud.org/ns\"/>
  72. <favorite xmlns=\"http://owncloud.org/ns\"/>
  73. <creation_time xmlns=\"http://nextcloud.org/ns\"/>
  74. <upload_time xmlns=\"http://nextcloud.org/ns\"/>
  75. <is-encrypted xmlns=\"http://nextcloud.org/ns\"/>
  76. <mount-type xmlns=\"http://nextcloud.org/ns\"/>
  77. <owner-id xmlns=\"http://owncloud.org/ns\"/>
  78. <owner-display-name xmlns=\"http://owncloud.org/ns\"/>
  79. <comments-unread xmlns=\"http://owncloud.org/ns\"/>
  80. <has-preview xmlns=\"http://nextcloud.org/ns\"/>
  81. <trashbin-filename xmlns=\"http://nextcloud.org/ns\"/>
  82. <trashbin-original-location xmlns=\"http://nextcloud.org/ns\"/>
  83. <trashbin-deletion-time xmlns=\"http://nextcloud.org/ns\"/>
  84. </d:prop>
  85. </d:select>
  86. <d:from>
  87. <d:scope>
  88. <d:href>%@</d:href>
  89. <d:depth>infinity</d:depth>
  90. </d:scope>
  91. </d:from>
  92. <d:orderby>
  93. <d:order>
  94. <d:prop>
  95. <d:getlastmodified/>
  96. </d:prop>
  97. <d:descending/>
  98. </d:order>
  99. </d:orderby>
  100. <d:limit>
  101. <d:nresults>100</d:nresults>
  102. </d:limit>
  103. </d:basicsearch>
  104. </d:searchrequest>
  105. """
  106. let requestBody = String(format: requestBodyRecent, "/files/"+appDelegate.userID)
  107. isReloadDataSourceNetworkInProgress = true
  108. collectionView?.reloadData()
  109. NCCommunication.shared.searchBodyRequest(serverUrl: appDelegate.urlBase, requestBody: requestBody, showHiddenFiles: CCUtility.getShowHiddenFiles()) { (account, files, errorCode, errorDescription) in
  110. self.refreshControl.endRefreshing()
  111. self.isReloadDataSourceNetworkInProgress = false
  112. self.reloadDataSource()
  113. }
  114. }
  115. }