NCUtility.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587
  1. //
  2. // NCUtility.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 25/06/18.
  6. // Copyright © 2018 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 SVGKit
  25. import KTVHTTPCache
  26. import NCCommunication
  27. import PDFKit
  28. import Accelerate
  29. class NCUtility: NSObject {
  30. @objc static let shared: NCUtility = {
  31. let instance = NCUtility()
  32. return instance
  33. }()
  34. private var activityIndicator: UIActivityIndicatorView? // = UIActivityIndicatorView(style: .whiteLarge)
  35. private var viewActivityIndicator: UIView?
  36. private var viewBackgroundActivityIndicator: UIView?
  37. func setLayoutForView(key: String, serverUrl: String, layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButton: String, itemForLine: Int) {
  38. let string = layout + "|" + sort + "|" + "\(ascending)" + "|" + groupBy + "|" + "\(directoryOnTop)" + "|" + titleButton + "|" + "\(itemForLine)"
  39. var keyStore = key
  40. if serverUrl != "" {
  41. keyStore = serverUrl
  42. }
  43. UICKeyChainStore.setString(string, forKey: keyStore, service: NCGlobal.shared.serviceShareKeyChain)
  44. }
  45. func setLayoutForView(key: String, serverUrl: String, layout: String) {
  46. var sort: String
  47. var ascending: Bool
  48. var groupBy: String
  49. var directoryOnTop: Bool
  50. var titleButton: String
  51. var itemForLine: Int
  52. (_, sort, ascending, groupBy, directoryOnTop, titleButton, itemForLine) = NCUtility.shared.getLayoutForView(key: NCGlobal.shared.layoutViewFavorite, serverUrl: serverUrl)
  53. setLayoutForView(key: key, serverUrl: serverUrl, layout: layout, sort: sort, ascending: ascending, groupBy: groupBy, directoryOnTop: directoryOnTop, titleButton: titleButton, itemForLine: itemForLine)
  54. }
  55. @objc func getLayoutForView(key: String, serverUrl: String) -> (String) {
  56. var layout: String
  57. (layout, _, _, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
  58. return layout
  59. }
  60. @objc func getSortedForView(key: String, serverUrl: String) -> (String) {
  61. var sort: String
  62. (_, sort, _, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
  63. return sort
  64. }
  65. @objc func getAscendingForView(key: String, serverUrl: String) -> (Bool) {
  66. var ascending: Bool
  67. (_, _, ascending, _, _, _, _) = NCUtility.shared.getLayoutForView(key: key, serverUrl: serverUrl)
  68. return ascending
  69. }
  70. func getLayoutForView(key: String, serverUrl: String) -> (layout: String, sort: String, ascending: Bool, groupBy: String, directoryOnTop: Bool, titleButton: String, itemForLine: Int) {
  71. var keyStore = key
  72. if serverUrl != "" {
  73. keyStore = serverUrl
  74. }
  75. guard let string = UICKeyChainStore.string(forKey: keyStore, service: NCGlobal.shared.serviceShareKeyChain) else {
  76. setLayoutForView(key: key, serverUrl: serverUrl, layout: NCGlobal.shared.layoutList, sort: "fileName", ascending: true, groupBy: "none", directoryOnTop: true, titleButton: "_sorted_by_name_a_z_", itemForLine: 3)
  77. return (NCGlobal.shared.layoutList, "fileName", true, "none", true, "_sorted_by_name_a_z_", 3)
  78. }
  79. let array = string.components(separatedBy: "|")
  80. if array.count == 7 {
  81. let sort = NSString(string: array[2])
  82. let directoryOnTop = NSString(string: array[4])
  83. let itemForLine = NSString(string: array[6])
  84. return (array[0], array[1], sort.boolValue, array[3], directoryOnTop.boolValue, array[5], Int(itemForLine.intValue))
  85. }
  86. setLayoutForView(key: key, serverUrl: serverUrl, layout: NCGlobal.shared.layoutList, sort: "fileName", ascending: true, groupBy: "none", directoryOnTop: true, titleButton: "_sorted_by_name_a_z_", itemForLine: 3)
  87. return (NCGlobal.shared.layoutList, "fileName", true, "none", true, "_sorted_by_name_a_z_", 3)
  88. }
  89. func convertSVGtoPNGWriteToUserData(svgUrlString: String, fileName: String?, width: CGFloat?, rewrite: Bool, account: String, closure: @escaping (String?) -> ()) {
  90. var fileNamePNG = ""
  91. guard let svgUrlString = svgUrlString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) else {
  92. return closure(nil)
  93. }
  94. guard let iconURL = URL(string: svgUrlString) else {
  95. return closure(nil)
  96. }
  97. if fileName == nil {
  98. fileNamePNG = iconURL.deletingPathExtension().lastPathComponent + ".png"
  99. } else {
  100. fileNamePNG = fileName!
  101. }
  102. let imageNamePath = CCUtility.getDirectoryUserData() + "/" + fileNamePNG
  103. if !FileManager.default.fileExists(atPath: imageNamePath) || rewrite == true {
  104. NCCommunication.shared.downloadContent(serverUrl: iconURL.absoluteString) { (account, data, errorCode, errorMessage) in
  105. if errorCode == 0 && data != nil {
  106. if let image = UIImage.init(data: data!) {
  107. var newImage: UIImage = image
  108. if width != nil {
  109. let ratio = image.size.height / image.size.width
  110. let newSize = CGSize(width: width!, height: width! * ratio)
  111. let renderFormat = UIGraphicsImageRendererFormat.default()
  112. renderFormat.opaque = false
  113. let renderer = UIGraphicsImageRenderer(size: CGSize(width: newSize.width, height: newSize.height), format: renderFormat)
  114. newImage = renderer.image {
  115. (context) in
  116. image.draw(in: CGRect(x: 0, y: 0, width: newSize.width, height: newSize.height))
  117. }
  118. }
  119. guard let pngImageData = newImage.pngData() else {
  120. return closure(nil)
  121. }
  122. try? pngImageData.write(to: URL(fileURLWithPath:imageNamePath))
  123. return closure(imageNamePath)
  124. } else {
  125. guard let svgImage: SVGKImage = SVGKImage(data: data) else {
  126. return closure(nil)
  127. }
  128. if width != nil {
  129. let scale = svgImage.size.height / svgImage.size.width
  130. svgImage.size = CGSize(width: width!, height: width! * scale)
  131. }
  132. guard let image: UIImage = svgImage.uiImage else {
  133. return closure(nil)
  134. }
  135. guard let pngImageData = image.pngData() else {
  136. return closure(nil)
  137. }
  138. try? pngImageData.write(to: URL(fileURLWithPath:imageNamePath))
  139. return closure(imageNamePath)
  140. }
  141. } else {
  142. return closure(nil)
  143. }
  144. }
  145. } else {
  146. return closure(imageNamePath)
  147. }
  148. }
  149. @objc func isSimulatorOrTestFlight() -> Bool {
  150. guard let path = Bundle.main.appStoreReceiptURL?.path else {
  151. return false
  152. }
  153. return path.contains("CoreSimulator") || path.contains("sandboxReceipt")
  154. }
  155. @objc func isSimulator() -> Bool {
  156. guard let path = Bundle.main.appStoreReceiptURL?.path else {
  157. return false
  158. }
  159. return path.contains("CoreSimulator")
  160. }
  161. @objc func isRichDocument(_ metadata: tableMetadata) -> Bool {
  162. guard let mimeType = CCUtility.getMimeType(metadata.fileNameView) else {
  163. return false
  164. }
  165. guard let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) else {
  166. return false
  167. }
  168. if richdocumentsMimetypes.count > 0 && mimeType.components(separatedBy: ".").count > 2 {
  169. let mimeTypeArray = mimeType.components(separatedBy: ".")
  170. let mimeType = mimeTypeArray[mimeTypeArray.count - 2] + "." + mimeTypeArray[mimeTypeArray.count - 1]
  171. for richdocumentMimetype: String in richdocumentsMimetypes {
  172. if richdocumentMimetype.contains(mimeType) {
  173. return true
  174. }
  175. }
  176. }
  177. return false
  178. }
  179. @objc func isDirectEditing(account: String, contentType: String) -> String? {
  180. var editor: String?
  181. guard let results = NCManageDatabase.shared.getDirectEditingEditors(account: account) else {
  182. return editor
  183. }
  184. for result: tableDirectEditingEditors in results {
  185. for mimetype in result.mimetypes {
  186. if mimetype == contentType {
  187. editor = result.editor
  188. }
  189. // HARDCODE
  190. // https://github.com/nextcloud/text/issues/913
  191. if mimetype == "text/markdown" && contentType == "text/x-markdown" {
  192. editor = result.editor
  193. }
  194. }
  195. for mimetype in result.optionalMimetypes {
  196. if mimetype == contentType {
  197. editor = result.editor
  198. }
  199. }
  200. }
  201. // HARDCODE
  202. if editor == "" {
  203. editor = NCGlobal.shared.editorText
  204. }
  205. return editor
  206. }
  207. @objc func removeAllSettings() {
  208. URLCache.shared.memoryCapacity = 0
  209. URLCache.shared.diskCapacity = 0
  210. KTVHTTPCache.cacheDeleteAllCaches()
  211. NCManageDatabase.shared.clearDatabase(account: nil, removeAccount: true)
  212. CCUtility.removeGroupDirectoryProviderStorage()
  213. CCUtility.removeGroupLibraryDirectory()
  214. CCUtility.removeDocumentsDirectory()
  215. CCUtility.removeTemporaryDirectory()
  216. CCUtility.createDirectoryStandard()
  217. CCUtility.deleteAllChainStore()
  218. }
  219. @objc func permissionsContainsString(_ metadataPermissions: String, permissions: String) -> Bool {
  220. for char in permissions {
  221. if metadataPermissions.contains(char) == false {
  222. return false
  223. }
  224. }
  225. return true
  226. }
  227. @objc func getCustomUserAgentOnlyOffice() -> String {
  228. let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")!
  229. if UIDevice.current.userInterfaceIdiom == .pad {
  230. return "Mozilla/5.0 (iPad) Nextcloud-iOS/\(appVersion)"
  231. }else{
  232. return "Mozilla/5.0 (iPhone) Mobile Nextcloud-iOS/\(appVersion)"
  233. }
  234. }
  235. @objc func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? {
  236. guard let data = try? Data(contentsOf: url), let page = PDFDocument(data: data)?.page(at: 0) else {
  237. return nil
  238. }
  239. let pageSize = page.bounds(for: .mediaBox)
  240. let pdfScale = width / pageSize.width
  241. // Apply if you're displaying the thumbnail on screen
  242. let scale = UIScreen.main.scale * pdfScale
  243. let screenSize = CGSize(width: pageSize.width * scale, height: pageSize.height * scale)
  244. return page.thumbnail(of: screenSize, for: .mediaBox)
  245. }
  246. @objc func isQuickLookDisplayable(metadata: tableMetadata) -> Bool {
  247. return true
  248. }
  249. @objc func ocIdToFileId(ocId: String?) -> String? {
  250. guard let ocId = ocId else { return nil }
  251. let items = ocId.components(separatedBy: "oc")
  252. if items.count < 2 { return nil }
  253. guard let intFileId = Int(items[0]) else { return nil }
  254. return String(intFileId)
  255. }
  256. func getUserStatus(userIcon: String?, userStatus: String?, userMessage: String?) -> (onlineStatus: UIImage?, statusMessage: String) {
  257. var onlineStatus: UIImage?
  258. var statusMessage: String = ""
  259. var messageUserDefined: String = ""
  260. if userStatus?.lowercased() == "online" {
  261. onlineStatus = UIImage.init(named: "userStatusOnline")!.image(color: UIColor(red: 103.0/255.0, green: 176.0/255.0, blue: 134.0/255.0, alpha: 1.0), size: 50)
  262. messageUserDefined = NSLocalizedString("_online_", comment: "")
  263. }
  264. if userStatus?.lowercased() == "away" {
  265. onlineStatus = UIImage.init(named: "userStatusAway")!.image(color: UIColor(red: 233.0/255.0, green: 166.0/255.0, blue: 75.0/255.0, alpha: 1.0), size: 50)
  266. messageUserDefined = NSLocalizedString("_away_", comment: "")
  267. }
  268. if userStatus?.lowercased() == "dnd" {
  269. onlineStatus = UIImage.init(named: "userStatusDnd")?.resizeImage(size: CGSize(width: 100, height: 100), isAspectRation: false)
  270. messageUserDefined = NSLocalizedString("_dnd_", comment: "")
  271. }
  272. if userStatus?.lowercased() == "offline" || userStatus?.lowercased() == "invisible" {
  273. onlineStatus = UIImage.init(named: "userStatusOffline")!.image(color: .black, size: 50)
  274. messageUserDefined = NSLocalizedString("_invisible_", comment: "")
  275. }
  276. if let userIcon = userIcon {
  277. statusMessage = userIcon + " "
  278. }
  279. if let userMessage = userMessage {
  280. statusMessage = statusMessage + userMessage
  281. }
  282. statusMessage = statusMessage.trimmingCharacters(in: .whitespaces)
  283. if statusMessage == "" {
  284. statusMessage = messageUserDefined
  285. }
  286. return(onlineStatus, statusMessage)
  287. }
  288. func imageFromVideo(url: URL, at time: TimeInterval) -> UIImage? {
  289. let asset = AVURLAsset(url: url)
  290. let assetIG = AVAssetImageGenerator(asset: asset)
  291. assetIG.appliesPreferredTrackTransform = true
  292. assetIG.apertureMode = AVAssetImageGenerator.ApertureMode.encodedPixels
  293. let cmTime = CMTime(seconds: time, preferredTimescale: 60)
  294. let thumbnailImageRef: CGImage
  295. do {
  296. thumbnailImageRef = try assetIG.copyCGImage(at: cmTime, actualTime: nil)
  297. } catch let error {
  298. print("Error: \(error)")
  299. return nil
  300. }
  301. return UIImage(cgImage: thumbnailImageRef)
  302. }
  303. func createImageFrom(fileName: String, ocId: String, etag: String, typeFile: String) {
  304. var originalImage, scaleImagePreview, scaleImageIcon: UIImage?
  305. let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
  306. let fileNamePathPreview = CCUtility.getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)!
  307. let fileNamePathIcon = CCUtility.getDirectoryProviderStorageIconOcId(ocId, etag: etag)!
  308. if FileManager().fileExists(atPath: fileNamePathPreview) && FileManager().fileExists(atPath: fileNamePathIcon) { return }
  309. if !CCUtility.fileProviderStorageExists(ocId, fileNameView: fileName) { return }
  310. if typeFile != NCGlobal.shared.metadataTypeFileImage && typeFile != NCGlobal.shared.metadataTypeFileVideo { return }
  311. if typeFile == NCGlobal.shared.metadataTypeFileImage {
  312. originalImage = UIImage.init(contentsOfFile: fileNamePath)
  313. scaleImagePreview = originalImage?.resizeImage(size: CGSize(width: NCGlobal.shared.sizePreview, height: NCGlobal.shared.sizePreview), isAspectRation: false)
  314. scaleImageIcon = originalImage?.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: false)
  315. try? scaleImagePreview?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathPreview))
  316. try? scaleImageIcon?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathIcon))
  317. } else if typeFile == NCGlobal.shared.metadataTypeFileVideo {
  318. let videoPath = NSTemporaryDirectory()+"tempvideo.mp4"
  319. NCUtilityFileSystem.shared.linkItem(atPath: fileNamePath, toPath: videoPath)
  320. originalImage = imageFromVideo(url: URL(fileURLWithPath: videoPath), at: 0)
  321. try? originalImage?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathPreview))
  322. try? originalImage?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathIcon))
  323. }
  324. }
  325. @objc func getVersionApp() -> String {
  326. if let dictionary = Bundle.main.infoDictionary {
  327. if let version = dictionary["CFBundleShortVersionString"], let build = dictionary["CFBundleVersion"] {
  328. return "\(version).\(build)"
  329. }
  330. }
  331. return ""
  332. }
  333. func loadImage(named: String, color: UIColor = NCBrandColor.shared.gray, size: CGFloat = 50, symbolConfiguration: Any? = nil) -> UIImage {
  334. var image: UIImage?
  335. if #available(iOS 13.0, *) {
  336. if let symbolConfiguration = symbolConfiguration {
  337. image = UIImage(systemName: named, withConfiguration: symbolConfiguration as? UIImage.Configuration)?.imageColor(color)
  338. } else {
  339. image = UIImage(systemName: named)?.imageColor(color)
  340. }
  341. if image == nil {
  342. image = UIImage(named: named)?.image(color: color, size: size)
  343. }
  344. } else {
  345. image = UIImage(named: named)?.image(color: color, size: size)
  346. }
  347. if image != nil {
  348. return image!
  349. }
  350. return UIImage(named: "file")!.image(color: color, size: size)
  351. }
  352. @objc func createAvatar(image: UIImage, size: CGFloat) -> UIImage {
  353. var avatarImage = image
  354. let rect = CGRect(x: 0, y: 0, width: size, height: size)
  355. UIGraphicsBeginImageContextWithOptions(rect.size, false, 3.0)
  356. UIBezierPath.init(roundedRect: rect, cornerRadius: rect.size.height).addClip()
  357. avatarImage.draw(in: rect)
  358. avatarImage = UIGraphicsGetImageFromCurrentImageContext() ?? image
  359. UIGraphicsEndImageContext()
  360. return avatarImage
  361. }
  362. // MARK: -
  363. @objc func startActivityIndicator(backgroundView: UIView?, blurEffect: Bool, bottom: CGFloat = 0, style: UIActivityIndicatorView.Style = .whiteLarge) {
  364. if self.activityIndicator != nil {
  365. stopActivityIndicator()
  366. }
  367. self.activityIndicator = UIActivityIndicatorView(style: style)
  368. guard let activityIndicator = self.activityIndicator else { return }
  369. DispatchQueue.main.async {
  370. if self.viewBackgroundActivityIndicator != nil { return }
  371. activityIndicator.color = NCBrandColor.shared.label
  372. activityIndicator.hidesWhenStopped = true
  373. activityIndicator.translatesAutoresizingMaskIntoConstraints = false
  374. let sizeActivityIndicator = activityIndicator.frame.height + 50
  375. self.viewActivityIndicator = UIView.init(frame: CGRect(x: 0, y: 0, width: sizeActivityIndicator, height: sizeActivityIndicator))
  376. self.viewActivityIndicator?.translatesAutoresizingMaskIntoConstraints = false
  377. self.viewActivityIndicator?.layer.cornerRadius = 10
  378. self.viewActivityIndicator?.layer.masksToBounds = true
  379. self.viewActivityIndicator?.backgroundColor = .clear
  380. if backgroundView == nil {
  381. if let window = UIApplication.shared.keyWindow {
  382. self.viewBackgroundActivityIndicator?.removeFromSuperview()
  383. self.viewBackgroundActivityIndicator = NCViewActivityIndicator(frame: window.bounds)
  384. window.addSubview(self.viewBackgroundActivityIndicator!)
  385. self.viewBackgroundActivityIndicator?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  386. self.viewBackgroundActivityIndicator?.backgroundColor = .clear
  387. }
  388. } else {
  389. self.viewBackgroundActivityIndicator = backgroundView
  390. }
  391. // VIEW ACTIVITY INDICATOR
  392. guard let viewActivityIndicator = self.viewActivityIndicator else { return }
  393. viewActivityIndicator.addSubview(activityIndicator)
  394. if blurEffect {
  395. let blurEffect = UIBlurEffect(style: .regular)
  396. let blurEffectView = UIVisualEffectView(effect: blurEffect)
  397. blurEffectView.frame = viewActivityIndicator.frame
  398. viewActivityIndicator.insertSubview(blurEffectView, at: 0)
  399. }
  400. NSLayoutConstraint.activate([
  401. viewActivityIndicator.widthAnchor.constraint(equalToConstant: sizeActivityIndicator),
  402. viewActivityIndicator.heightAnchor.constraint(equalToConstant: sizeActivityIndicator),
  403. activityIndicator.centerXAnchor.constraint(equalTo: viewActivityIndicator.centerXAnchor),
  404. activityIndicator.centerYAnchor.constraint(equalTo: viewActivityIndicator.centerYAnchor)
  405. ])
  406. // BACKGROUD VIEW ACTIVITY INDICATOR
  407. guard let viewBackgroundActivityIndicator = self.viewBackgroundActivityIndicator else { return }
  408. viewBackgroundActivityIndicator.addSubview(viewActivityIndicator)
  409. var verticalConstant: CGFloat = 0
  410. if bottom > 0 {
  411. verticalConstant = (viewBackgroundActivityIndicator.frame.size.height / 2) - bottom
  412. }
  413. NSLayoutConstraint.activate([
  414. viewActivityIndicator.centerXAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerXAnchor),
  415. viewActivityIndicator.centerYAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerYAnchor, constant: verticalConstant)
  416. ])
  417. activityIndicator.startAnimating()
  418. }
  419. }
  420. @objc func stopActivityIndicator() {
  421. DispatchQueue.main.async {
  422. self.activityIndicator?.stopAnimating()
  423. self.activityIndicator?.removeFromSuperview()
  424. self.activityIndicator = nil
  425. self.viewActivityIndicator?.removeFromSuperview()
  426. self.viewActivityIndicator = nil
  427. if self.viewBackgroundActivityIndicator is NCViewActivityIndicator {
  428. self.viewBackgroundActivityIndicator?.removeFromSuperview()
  429. }
  430. self.viewBackgroundActivityIndicator = nil
  431. }
  432. }
  433. }
  434. // MARK: -
  435. class NCViewActivityIndicator: UIView {
  436. override init(frame: CGRect) {
  437. super.init(frame: frame)
  438. }
  439. required init?(coder: NSCoder) {
  440. fatalError("init(coder:) has not been implemented")
  441. }
  442. }