|
@@ -103,7 +103,7 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
|
|
|
|
|
|
(typeLayout, datasourceSorted, datasourceAscending, datasourceGroupBy, datasourceDirectoryOnTop) = NCUtility.sharedInstance.getLayoutForView(key: k_layout_view_offline)
|
|
|
|
|
|
- if typeLayout == "list" {
|
|
|
+ if typeLayout == k_layout_list {
|
|
|
collectionView.collectionViewLayout = listLayout
|
|
|
} else {
|
|
|
collectionView.collectionViewLayout = gridLayout
|
|
@@ -154,7 +154,7 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
|
|
|
self.collectionView.setContentOffset(CGPoint(x:0,y:0), animated: false)
|
|
|
})
|
|
|
})
|
|
|
- typeLayout = "list"
|
|
|
+ typeLayout = k_layout_list
|
|
|
NCUtility.sharedInstance.setLayoutForView(key: k_layout_view_offline, layout: typeLayout, sort: datasourceSorted, ascending: datasourceAscending, groupBy: datasourceGroupBy, directoryOnTop: datasourceDirectoryOnTop)
|
|
|
} else {
|
|
|
// grid layout
|
|
@@ -165,7 +165,7 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
|
|
|
self.collectionView.setContentOffset(CGPoint(x:0,y:0), animated: false)
|
|
|
})
|
|
|
})
|
|
|
- typeLayout = "grid"
|
|
|
+ typeLayout = k_layout_grid
|
|
|
NCUtility.sharedInstance.setLayoutForView(key: k_layout_view_offline, layout: typeLayout, sort: datasourceSorted, ascending: datasourceAscending, groupBy: datasourceGroupBy, directoryOnTop: datasourceDirectoryOnTop)
|
|
|
}
|
|
|
}
|
|
@@ -368,17 +368,6 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
|
|
|
|
|
|
// MARK: NC API
|
|
|
|
|
|
- func downloadThumbnail(with tableMetadata: tableMetadata, indexPath: IndexPath) {
|
|
|
-
|
|
|
- let ocNetworking = OCnetworking.init(delegate: self, metadataNet: nil, withUser: appDelegate.activeUser, withUserID: appDelegate.activeUserID, withPassword: appDelegate.activePassword, withUrl: appDelegate.activeUrl)
|
|
|
-
|
|
|
- ocNetworking?.downloadPreviewTrash(withFileID: tableMetadata.fileID, fileName: tableMetadata.fileName, completion: { (message, errorCode) in
|
|
|
- if errorCode == 0 && CCUtility.fileProviderStorageIconExists(tableMetadata.fileID, fileNameView: tableMetadata.fileName) {
|
|
|
- self.collectionView.reloadItems(at: [indexPath])
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
-
|
|
|
func deleteItem(with metadata: tableMetadata, sender: Any) {
|
|
|
|
|
|
var items = [ActionSheetItem]()
|
|
@@ -543,9 +532,6 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
|
|
- var image: UIImage?
|
|
|
- var imagePreview = false
|
|
|
-
|
|
|
guard let metadata = NCMainCommon.sharedInstance.getMetadataFromSectionDataSourceIndexPath(indexPath, sectionDataSource: sectionDatasource) else {
|
|
|
return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
|
|
|
}
|
|
@@ -553,153 +539,9 @@ class NCOffline: UIViewController ,UICollectionViewDataSource, UICollectionViewD
|
|
|
return collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
|
|
|
}
|
|
|
|
|
|
- if metadata.iconName.count > 0 {
|
|
|
- image = UIImage.init(named: metadata.iconName)
|
|
|
- } else {
|
|
|
- image = UIImage.init(named: "file")
|
|
|
- }
|
|
|
-
|
|
|
- if FileManager().fileExists(atPath: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileName)) {
|
|
|
- image = UIImage.init(contentsOfFile: CCUtility.getDirectoryProviderStorageIconFileID(metadata.fileID, fileNameView: metadata.fileName))
|
|
|
- imagePreview = true
|
|
|
- } else {
|
|
|
- if metadata.hasPreview == 1 && !CCUtility.fileProviderStorageIconExists(metadata.fileID, fileNameView: metadata.fileName) {
|
|
|
- downloadThumbnail(with: metadata, indexPath: indexPath)
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if collectionView.collectionViewLayout == listLayout {
|
|
|
-
|
|
|
- // LIST
|
|
|
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "listCell", for: indexPath) as! NCListCell
|
|
|
- cell.delegate = self
|
|
|
-
|
|
|
- cell.fileID = metadata.fileID
|
|
|
- cell.indexPath = indexPath
|
|
|
- cell.labelTitle.text = metadata.fileNameView
|
|
|
- cell.imageStatus.image = nil
|
|
|
- cell.imageLocal.image = nil
|
|
|
- cell.imageFavorite.image = nil
|
|
|
-
|
|
|
- if metadata.directory {
|
|
|
- cell.imageItem.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "folder"), multiplier: 3, color: NCBrandColor.sharedInstance.brandElement)
|
|
|
- cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date)
|
|
|
-
|
|
|
- let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
|
|
|
- let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
|
|
|
- // Status image: passcode
|
|
|
- if tableDirectory != nil && tableDirectory!.lock && CCUtility.getBlockCode() != nil {
|
|
|
- cell.imageStatus.image = UIImage.init(named: "passcode")
|
|
|
- }
|
|
|
- // Local image: offline
|
|
|
- if tableDirectory != nil && tableDirectory!.offline {
|
|
|
- cell.imageLocal.image = UIImage.init(named: "offlineFlag")
|
|
|
- }
|
|
|
-
|
|
|
- } else {
|
|
|
- cell.imageItem.image = image
|
|
|
- cell.labelInfo.text = CCUtility.dateDiff(metadata.date as Date) + " " + CCUtility.transformedSize(metadata.size)
|
|
|
-
|
|
|
- // image Local
|
|
|
- let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "fileID == %@", metadata.fileID))
|
|
|
- if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.fileID, fileNameView: metadata.fileNameView) {
|
|
|
- if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
|
|
|
- else { cell.imageLocal.image = UIImage.init(named: "local") }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // image Favorite
|
|
|
- if metadata.favorite {
|
|
|
- cell.imageFavorite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), multiplier: 2, color: NCBrandColor.sharedInstance.yellowFavorite)
|
|
|
- }
|
|
|
-
|
|
|
- if isEditMode {
|
|
|
- cell.imageItemLeftConstraint.constant = 45
|
|
|
- cell.imageSelect.isHidden = false
|
|
|
-
|
|
|
- if selectFileID.contains(metadata.fileID) {
|
|
|
- cell.imageSelect.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedYes"), multiplier: 2, color: NCBrandColor.sharedInstance.brand)
|
|
|
- cell.backgroundView = cellBlurEffect(with: cell.bounds)
|
|
|
- } else {
|
|
|
- cell.imageSelect.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedNo"), multiplier: 2, color: NCBrandColor.sharedInstance.optionItem)
|
|
|
- cell.backgroundView = nil
|
|
|
- }
|
|
|
- } else {
|
|
|
- cell.imageItemLeftConstraint.constant = 10
|
|
|
- cell.imageSelect.isHidden = true
|
|
|
- cell.backgroundView = nil
|
|
|
- }
|
|
|
-
|
|
|
- // Remove last separator
|
|
|
- if collectionView.numberOfItems(inSection: indexPath.section) == indexPath.row + 1 {
|
|
|
- cell.separator.isHidden = true
|
|
|
- } else {
|
|
|
- cell.separator.isHidden = false
|
|
|
- }
|
|
|
-
|
|
|
- return cell
|
|
|
+ let cell = NCMainCommon.sharedInstance.collectionViewCellForItemAt(indexPath, collectionView: collectionView, typeLayout: typeLayout, metadata: metadata, serverUrl: serverUrl, isEditMode: isEditMode, selectFileID: selectFileID, hideButtonMore: false, source: self)
|
|
|
|
|
|
- } else {
|
|
|
-
|
|
|
- // GRID
|
|
|
- let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "gridCell", for: indexPath) as! NCGridCell
|
|
|
- cell.delegate = self
|
|
|
-
|
|
|
- cell.fileID = metadata.fileID
|
|
|
- cell.indexPath = indexPath
|
|
|
- cell.labelTitle.text = metadata.fileNameView
|
|
|
-
|
|
|
- if metadata.directory {
|
|
|
- image = UIImage.init(named: "folder")
|
|
|
- cell.imageItem.image = CCGraphics.changeThemingColorImage(image, width: image!.size.width*6, height: image!.size.height*6, scale: 3.0, color: NCBrandColor.sharedInstance.brandElement)
|
|
|
- cell.imageItem.contentMode = .center
|
|
|
-
|
|
|
- let lockServerUrl = CCUtility.stringAppendServerUrl(serverUrl, addFileName: metadata.fileName)!
|
|
|
- let tableDirectory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.activeAccount, lockServerUrl))
|
|
|
- // Status image: passcode
|
|
|
- if tableDirectory != nil && tableDirectory!.lock && CCUtility.getBlockCode() != nil {
|
|
|
- cell.imageStatus.image = UIImage.init(named: "passcode")
|
|
|
- }
|
|
|
- // Local image: offline
|
|
|
- if tableDirectory != nil && tableDirectory!.offline {
|
|
|
- cell.imageLocal.image = UIImage.init(named: "offlineFlag")
|
|
|
- }
|
|
|
- } else {
|
|
|
- cell.imageItem.image = image
|
|
|
- if imagePreview == false {
|
|
|
- let width = cell.imageItem.image!.size.width * 2
|
|
|
- //let scale = UIScreen.main.scale
|
|
|
- cell.imageItem.image = NCUtility.sharedInstance.resizeImage(image: image!, newWidth: width)
|
|
|
- cell.imageItem.contentMode = .center
|
|
|
- }
|
|
|
- // image Local
|
|
|
- let tableLocalFile = NCManageDatabase.sharedInstance.getTableLocalFile(predicate: NSPredicate(format: "fileID == %@", metadata.fileID))
|
|
|
- if tableLocalFile != nil && CCUtility.fileProviderStorageExists(metadata.fileID, fileNameView: metadata.fileNameView) {
|
|
|
- if tableLocalFile!.offline { cell.imageLocal.image = UIImage.init(named: "offlineFlag") }
|
|
|
- else { cell.imageLocal.image = UIImage.init(named: "local") }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- // image Favorite
|
|
|
- if metadata.favorite {
|
|
|
- cell.imageFavorite.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "favorite"), multiplier: 2, color: NCBrandColor.sharedInstance.yellowFavorite)
|
|
|
- }
|
|
|
-
|
|
|
- if isEditMode {
|
|
|
- cell.imageSelect.isHidden = false
|
|
|
- if selectFileID.contains(metadata.fileID) {
|
|
|
- cell.imageSelect.image = CCGraphics.changeThemingColorImage(UIImage.init(named: "checkedYes"), multiplier: 2, color: UIColor.white)
|
|
|
- cell.backgroundView = cellBlurEffect(with: cell.bounds)
|
|
|
- } else {
|
|
|
- cell.imageSelect.isHidden = true
|
|
|
- cell.backgroundView = nil
|
|
|
- }
|
|
|
- } else {
|
|
|
- cell.imageSelect.isHidden = true
|
|
|
- cell.backgroundView = nil
|
|
|
- }
|
|
|
- return cell
|
|
|
- }
|
|
|
+ return cell
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|