NCRecent.swift 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. guard let href = NCCommunicationCommon.shared.encodeString("/files/" + appDelegate.userID) else {
  54. return
  55. }
  56. let requestBodyRecent =
  57. """
  58. <?xml version=\"1.0\"?>
  59. <d:searchrequest xmlns:d=\"DAV:\" xmlns:oc=\"http://owncloud.org/ns\" xmlns:nc=\"http://nextcloud.org/ns\">
  60. <d:basicsearch>
  61. <d:select>
  62. <d:prop>
  63. <d:displayname/>
  64. <d:getcontenttype/>
  65. <d:resourcetype/>
  66. <d:getcontentlength/>
  67. <d:getlastmodified/>
  68. <d:getetag/>
  69. <d:quota-used-bytes/>
  70. <d:quota-available-bytes/>
  71. <permissions xmlns=\"http://owncloud.org/ns\"/>
  72. <id xmlns=\"http://owncloud.org/ns\"/>
  73. <fileid xmlns=\"http://owncloud.org/ns\"/>
  74. <size xmlns=\"http://owncloud.org/ns\"/>
  75. <favorite xmlns=\"http://owncloud.org/ns\"/>
  76. <creation_time xmlns=\"http://nextcloud.org/ns\"/>
  77. <upload_time xmlns=\"http://nextcloud.org/ns\"/>
  78. <is-encrypted xmlns=\"http://nextcloud.org/ns\"/>
  79. <mount-type xmlns=\"http://nextcloud.org/ns\"/>
  80. <owner-id xmlns=\"http://owncloud.org/ns\"/>
  81. <owner-display-name xmlns=\"http://owncloud.org/ns\"/>
  82. <comments-unread xmlns=\"http://owncloud.org/ns\"/>
  83. <has-preview xmlns=\"http://nextcloud.org/ns\"/>
  84. <trashbin-filename xmlns=\"http://nextcloud.org/ns\"/>
  85. <trashbin-original-location xmlns=\"http://nextcloud.org/ns\"/>
  86. <trashbin-deletion-time xmlns=\"http://nextcloud.org/ns\"/>
  87. </d:prop>
  88. </d:select>
  89. <d:from>
  90. <d:scope>
  91. <d:href>%@</d:href>
  92. <d:depth>infinity</d:depth>
  93. </d:scope>
  94. </d:from>
  95. <d:orderby>
  96. <d:order>
  97. <d:prop>
  98. <d:getlastmodified/>
  99. </d:prop>
  100. <d:descending/>
  101. </d:order>
  102. </d:orderby>
  103. <d:limit>
  104. <d:nresults>100</d:nresults>
  105. </d:limit>
  106. </d:basicsearch>
  107. </d:searchrequest>
  108. """
  109. let requestBody = String(format: requestBodyRecent, href)
  110. isReloadDataSourceNetworkInProgress = true
  111. collectionView?.reloadData()
  112. NCCommunication.shared.searchBodyRequest(serverUrl: appDelegate.urlBase, requestBody: requestBody, showHiddenFiles: CCUtility.getShowHiddenFiles()) { (account, files, errorCode, errorDescription) in
  113. self.refreshControl.endRefreshing()
  114. self.isReloadDataSourceNetworkInProgress = false
  115. self.reloadDataSource()
  116. }
  117. }
  118. }