NCUtility.swift 25 KB

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