1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import Foundation
- import NCCommunication
- class NCShares: NCCollectionViewCommon {
-
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
-
- titleCurrentFolder = NSLocalizedString("_list_shares_", comment: "")
- layoutKey = NCGlobal.shared.layoutViewShares
- enableSearchBar = false
- emptyImage = UIImage.init(named: "share")?.image(color: .gray, size: UIScreen.main.bounds.width)
- emptyTitle = "_list_shares_no_files_"
- emptyDescription = "_tutorial_list_shares_view_"
- }
-
-
-
- override func reloadDataSource() {
- super.reloadDataSource()
-
- DispatchQueue.global().async {
- self.metadatasSource.removeAll()
- let sharess = NCManageDatabase.shared.getTableShares(account: self.appDelegate.account)
- for share in sharess {
- if let metadata = NCManageDatabase.shared.getMetadata(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@ AND fileName == %@", self.appDelegate.account, share.serverUrl, share.fileName)) {
- self.metadatasSource.append(metadata)
- }
- }
-
- self.dataSource = NCDataSource.init(metadatasSource: self.metadatasSource, sort:self.sort, ascending: self.ascending, directoryOnTop: self.directoryOnTop, favoriteOnTop: true, filterLivePhoto: true)
-
- DispatchQueue.main.async {
- self.refreshControl.endRefreshing()
- self.collectionView.reloadData()
- }
- }
- }
-
- override func reloadDataSourceNetwork(forced: Bool = false) {
- super.reloadDataSourceNetwork(forced: forced)
-
- if isSearching {
- networkSearch()
- return
- }
-
- isReloadDataSourceNetworkInProgress = true
- collectionView?.reloadData()
-
-
- NCCommunication.shared.readShares { (account, shares, errorCode, ErrorDescription) in
-
- self.refreshControl.endRefreshing()
- self.isReloadDataSourceNetworkInProgress = false
-
- if errorCode == 0 {
-
- NCManageDatabase.shared.deleteTableShare(account: account)
- if shares != nil {
- NCManageDatabase.shared.addShare(urlBase: self.appDelegate.urlBase, account: account, shares: shares!)
- }
- self.appDelegate.shares = NCManageDatabase.shared.getTableShares(account: account)
-
- self.reloadDataSource()
-
- } else {
-
- self.collectionView?.reloadData()
- NCContentPresenter.shared.messageNotification("_share_", description: ErrorDescription, delay: NCGlobal.shared.dismissAfterSecond, type: NCContentPresenter.messageType.error, errorCode: errorCode)
- }
- }
- }
- }
|