123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- //
- // NCTransfers.swift
- // Nextcloud
- //
- // Created by Marino Faggiana on 17/09/2020.
- // Copyright © 2018 Marino Faggiana. All rights reserved.
- //
- // Author Marino Faggiana <marino.faggiana@nextcloud.com>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- //
- import Foundation
- import NCCommunication
- class NCTransfers: NCCollectionViewCommon {
-
- required init?(coder aDecoder: NSCoder) {
- super.init(coder: aDecoder)
-
- appDelegate.activeTransfers = self
- titleCurrentFolder = NSLocalizedString("_transfers_", comment: "")
- layoutKey = k_layout_view_transfers
- enableSearchBar = false
- DZNimage = CCGraphics.changeThemingColorImage(UIImage.init(named: "load"), width: 300, height: 300, color: NCBrandColor.sharedInstance.brandElement)
- DZNtitle = "_no_transfer_"
- DZNdescription = "_no_transfer_sub_"
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- }
-
- // MARK: - Collection View
-
- override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
-
- guard let metadata = dataSource?.cellForItemAt(indexPath: indexPath) else { return }
- metadataPush = metadata
-
- if isEditMode {
- if let index = selectOcId.firstIndex(of: metadata.ocId) {
- selectOcId.remove(at: index)
- } else {
- selectOcId.append(metadata.ocId)
- }
- collectionView.reloadItems(at: [indexPath])
- return
- }
-
- if metadata.directory {
-
- guard let serverUrlPush = CCUtility.stringAppendServerUrl(metadataPush!.serverUrl, addFileName: metadataPush!.fileName) else { return }
- let ncOffline:NCOffline = UIStoryboard(name: "NCOffline", bundle: nil).instantiateInitialViewController() as! NCOffline
-
- ncOffline.serverUrl = serverUrlPush
- ncOffline.titleCurrentFolder = metadataPush!.fileNameView
-
- self.navigationController?.pushViewController(ncOffline, animated: true)
-
- } else {
-
- if CCUtility.fileProviderStorageExists(metadataPush?.ocId, fileNameView: metadataPush?.fileNameView) {
- performSegue(withIdentifier: "segueDetail", sender: self)
- } else {
- NCNetworking.shared.download(metadata: metadataPush!, selector: "") { (errorCode) in
- if errorCode == 0 {
- self.performSegue(withIdentifier: "segueDetail", sender: self)
- }
- }
- }
- }
- }
-
- // MARK: - NC API & Algorithm
- override func reloadDataSource() {
- super.reloadDataSource()
-
- var sort: String
- var ascending: Bool
- var directoryOnTop: Bool
-
- (layout, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: layoutKey)
-
- metadatasSource = NCManageDatabase.sharedInstance.getMetadatas(predicate: NSPredicate(format: "(session CONTAINS 'upload') OR (session CONTAINS 'download')"), page: 1, limit: 100, sorted: "sessionTaskIdentifier", ascending: false)
- self.dataSource = NCDataSource.init(metadatasSource: metadatasSource, sort: sort, ascending: ascending, directoryOnTop: directoryOnTop, filterLivePhoto: true)
-
- refreshControl.endRefreshing()
- collectionView.reloadData()
- }
-
- override func reloadDataSourceNetwork() {
- super.reloadDataSourceNetwork()
-
- reloadDataSource()
- }
- }
|