1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
//
// NCShareExtension.swift
// Share
//
// Created by Marino Faggiana on 04.01.2022.
// Copyright © 2022 Henrik Storch. All rights reserved.
//
// Author Henrik Storch <henrik.storch@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 NCCommunication
import UIKit
extension NCShareExtension: NCEmptyDataSetDelegate, NCAccountRequestDelegate {
// MARK: - Empty
func emptyDataSetView(_ view: NCEmptyView) {
if networkInProgress {
view.emptyImage.image = UIImage(named: "networkInProgress")?.image(color: .gray, size: UIScreen.main.bounds.width)
view.emptyTitle.text = NSLocalizedString("_request_in_progress_", comment: "")
view.emptyDescription.text = ""
} else {
view.emptyImage.image = UIImage(named: "folder")?.image(color: NCBrandColor.shared.brandElement, size: UIScreen.main.bounds.width)
view.emptyTitle.text = NSLocalizedString("_files_no_folders_", comment: "")
view.emptyDescription.text = ""
}
}
// MARK: - Account
func showAccountPicker() {
let accounts = NCManageDatabase.shared.getAllAccountOrderAlias()
guard accounts.count > 1,
let vcAccountRequest = UIStoryboard(name: "NCAccountRequest", bundle: nil).instantiateInitialViewController() as? NCAccountRequest else { return }
// Only here change the active account
for account in accounts {
account.active = account.account == self.activeAccount.account
}
vcAccountRequest.activeAccount = self.activeAccount
vcAccountRequest.accounts = accounts.sorted { sorg, dest -> Bool in
return sorg.active && !dest.active
}
vcAccountRequest.enableTimerProgress = false
vcAccountRequest.enableAddAccount = false
vcAccountRequest.delegate = self
vcAccountRequest.dismissDidEnterBackground = true
let screenHeighMax = UIScreen.main.bounds.height - (UIScreen.main.bounds.height / 5)
let height = min(CGFloat(accounts.count * Int(vcAccountRequest.heightCell) + 45), screenHeighMax)
let popup = NCPopupViewController(contentController: vcAccountRequest, popupWidth: 300, popupHeight: height + 20)
self.present(popup, animated: true)
}
func accountRequestChangeAccount(account: String) {
guard let activeAccount = NCManageDatabase.shared.getAccount(predicate: NSPredicate(format: "account == %@", account)) else {
cancel(with: NCShareExtensionError.noAccount)
return
}
self.activeAccount = activeAccount
// COLORS
NCBrandColor.shared.settingThemingColor(account: activeAccount.account)
NCBrandColor.shared.createUserColors()
// NETWORKING
NCCommunicationCommon.shared.setup(
account: activeAccount.account,
user: activeAccount.user,
userId: activeAccount.userId,
password: CCUtility.getPassword(activeAccount.account),
urlBase: activeAccount.urlBase,
userAgent: CCUtility.getUserAgent(),
webDav: NCUtilityFileSystem.shared.getWebDAV(account: activeAccount.account),
nextcloudVersion: 0,
delegate: NCNetworking.shared)
// get auto upload folder
autoUploadFileName = NCManageDatabase.shared.getAccountAutoUploadFileName()
autoUploadDirectory = NCManageDatabase.shared.getAccountAutoUploadDirectory(urlBase: activeAccount.urlBase, account: activeAccount.account)
serverUrl = NCUtilityFileSystem.shared.getHomeServer(account: activeAccount.account)
layoutForView = NCUtility.shared.getLayoutForView(key: keyLayout, serverUrl: serverUrl)
reloadDatasource(withLoadFolder: true)
setNavigationBar(navigationTitle: NCBrandOptions.shared.brand)
}
}
extension NCShareExtension: NCShareCellDelegate, NCRenameFileDelegate, NCListCellDelegate {
func removeFile(named fileName: String) {
guard let index = self.filesName.firstIndex(of: fileName) else {
return showAlert(title: "_file_not_found_", description: fileName)
}
self.filesName.remove(at: index)
if self.filesName.isEmpty {
cancel(with: NCShareExtensionError.noFiles)
} else {
self.setCommandView()
}
}
func renameFile(named fileName: String) {
guard let vcRename = UIStoryboard(name: "NCRenameFile", bundle: nil).instantiateInitialViewController() as? NCRenameFile else { return }
let resultInternalType = NCCommunicationCommon.shared.getInternalType(fileName: fileName, mimeType: "", directory: false)
vcRename.delegate = self
vcRename.fileName = fileName
if let previewImage = UIImage.downsample(imageAt: URL(fileURLWithPath: NSTemporaryDirectory() + fileName), to: CGSize(width: 140, height: 140)) {
vcRename.imagePreview = previewImage
} else {
vcRename.imagePreview = UIImage(named: resultInternalType.iconName) ?? NCBrandColor.cacheImages.file
}
let popup = NCPopupViewController(contentController: vcRename, popupWidth: vcRename.width, popupHeight: vcRename.height)
self.present(popup, animated: true)
}
func rename(fileName: String, fileNameNew: String) {
guard fileName != fileNameNew else { return }
guard let fileIx = self.filesName.firstIndex(of: fileName),
!self.filesName.contains(fileNameNew),
NCUtilityFileSystem.shared.moveFile(atPath: (NSTemporaryDirectory() + fileName), toPath: (NSTemporaryDirectory() + fileNameNew)) else {
return showAlert(title: "_single_file_conflict_title_", description: "'\(fileName)' -> '\(fileNameNew)'")
}
filesName[fileIx] = fileNameNew
tableView.reloadData()
}
}
extension NCShareExtension: NCCreateFormUploadConflictDelegate {
func dismissCreateFormUploadConflict(metadatas: [tableMetadata]?) {
guard let metadatas = metadatas else {
uploadStarted = false
uploadMetadata.removeAll()
return
}
self.uploadMetadata.append(contentsOf: metadatas)
self.upload()
}
}
|