NCUtility.swift 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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 let activityIndicator = 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 isRichDocument(_ metadata: tableMetadata) -> Bool {
  156. guard let mimeType = CCUtility.getMimeType(metadata.fileNameView) else {
  157. return false
  158. }
  159. guard let richdocumentsMimetypes = NCManageDatabase.shared.getCapabilitiesServerArray(account: metadata.account, elements: NCElementsJSON.shared.capabilitiesRichdocumentsMimetypes) else {
  160. return false
  161. }
  162. if richdocumentsMimetypes.count > 0 && mimeType.components(separatedBy: ".").count > 2 {
  163. let mimeTypeArray = mimeType.components(separatedBy: ".")
  164. let mimeType = mimeTypeArray[mimeTypeArray.count - 2] + "." + mimeTypeArray[mimeTypeArray.count - 1]
  165. for richdocumentMimetype: String in richdocumentsMimetypes {
  166. if richdocumentMimetype.contains(mimeType) {
  167. return true
  168. }
  169. }
  170. }
  171. return false
  172. }
  173. @objc func isDirectEditing(account: String, contentType: String) -> String? {
  174. var editor: String?
  175. guard let results = NCManageDatabase.shared.getDirectEditingEditors(account: account) else {
  176. return editor
  177. }
  178. for result: tableDirectEditingEditors in results {
  179. for mimetype in result.mimetypes {
  180. if mimetype == contentType {
  181. editor = result.editor
  182. }
  183. // HARDCODE
  184. // https://github.com/nextcloud/text/issues/913
  185. if mimetype == "text/markdown" && contentType == "text/x-markdown" {
  186. editor = result.editor
  187. }
  188. }
  189. for mimetype in result.optionalMimetypes {
  190. if mimetype == contentType {
  191. editor = result.editor
  192. }
  193. }
  194. }
  195. // HARDCODE
  196. if editor == "" {
  197. editor = NCGlobal.shared.editorText
  198. }
  199. return editor
  200. }
  201. @objc func removeAllSettings() {
  202. URLCache.shared.memoryCapacity = 0
  203. URLCache.shared.diskCapacity = 0
  204. KTVHTTPCache.cacheDeleteAllCaches()
  205. NCManageDatabase.shared.clearDatabase(account: nil, removeAccount: true)
  206. CCUtility.removeGroupDirectoryProviderStorage()
  207. CCUtility.removeGroupLibraryDirectory()
  208. CCUtility.removeDocumentsDirectory()
  209. CCUtility.removeTemporaryDirectory()
  210. CCUtility.createDirectoryStandard()
  211. CCUtility.deleteAllChainStore()
  212. }
  213. @objc func permissionsContainsString(_ metadataPermissions: String, permissions: String) -> Bool {
  214. for char in permissions {
  215. if metadataPermissions.contains(char) == false {
  216. return false
  217. }
  218. }
  219. return true
  220. }
  221. @objc func getCustomUserAgentOnlyOffice() -> String {
  222. let appVersion = Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString")!
  223. if UIDevice.current.userInterfaceIdiom == .pad {
  224. return "Mozilla/5.0 (iPad) Nextcloud-iOS/\(appVersion)"
  225. }else{
  226. return "Mozilla/5.0 (iPhone) Mobile Nextcloud-iOS/\(appVersion)"
  227. }
  228. }
  229. @objc func pdfThumbnail(url: URL, width: CGFloat = 240) -> UIImage? {
  230. guard let data = try? Data(contentsOf: url), let page = PDFDocument(data: data)?.page(at: 0) else {
  231. return nil
  232. }
  233. let pageSize = page.bounds(for: .mediaBox)
  234. let pdfScale = width / pageSize.width
  235. // Apply if you're displaying the thumbnail on screen
  236. let scale = UIScreen.main.scale * pdfScale
  237. let screenSize = CGSize(width: pageSize.width * scale, height: pageSize.height * scale)
  238. return page.thumbnail(of: screenSize, for: .mediaBox)
  239. }
  240. @objc func isQuickLookDisplayable(metadata: tableMetadata) -> Bool {
  241. return true
  242. }
  243. @objc func ocIdToFileId(ocId: String?) -> String? {
  244. guard let ocId = ocId else { return nil }
  245. let items = ocId.components(separatedBy: "oc")
  246. if items.count < 2 { return nil }
  247. guard let intFileId = Int(items[0]) else { return nil }
  248. return String(intFileId)
  249. }
  250. func getUserStatus(userIcon: String?, userStatus: String?, userMessage: String?) -> (onlineStatus: UIImage?, statusMessage: String) {
  251. var onlineStatus: UIImage?
  252. var statusMessage: String = ""
  253. var messageUserDefined: String = ""
  254. if userStatus?.lowercased() == "online" {
  255. 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)
  256. messageUserDefined = NSLocalizedString("_online_", comment: "")
  257. }
  258. if userStatus?.lowercased() == "away" {
  259. 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)
  260. messageUserDefined = NSLocalizedString("_away_", comment: "")
  261. }
  262. if userStatus?.lowercased() == "dnd" {
  263. onlineStatus = UIImage.init(named: "userStatusDnd")?.resizeImage(size: CGSize(width: 100, height: 100), isAspectRation: false)
  264. messageUserDefined = NSLocalizedString("_dnd_", comment: "")
  265. }
  266. if userStatus?.lowercased() == "offline" || userStatus?.lowercased() == "invisible" {
  267. onlineStatus = UIImage.init(named: "userStatusOffline")!.image(color: .black, size: 50)
  268. messageUserDefined = NSLocalizedString("_invisible_", comment: "")
  269. }
  270. if let userIcon = userIcon {
  271. statusMessage = userIcon + " "
  272. }
  273. if let userMessage = userMessage {
  274. statusMessage = statusMessage + userMessage
  275. }
  276. statusMessage = statusMessage.trimmingCharacters(in: .whitespaces)
  277. if statusMessage == "" {
  278. statusMessage = messageUserDefined
  279. }
  280. return(onlineStatus, statusMessage)
  281. }
  282. func imageFromVideo(url: URL, at time: TimeInterval) -> UIImage? {
  283. let asset = AVURLAsset(url: url)
  284. let assetIG = AVAssetImageGenerator(asset: asset)
  285. assetIG.appliesPreferredTrackTransform = true
  286. assetIG.apertureMode = AVAssetImageGenerator.ApertureMode.encodedPixels
  287. let cmTime = CMTime(seconds: time, preferredTimescale: 60)
  288. let thumbnailImageRef: CGImage
  289. do {
  290. thumbnailImageRef = try assetIG.copyCGImage(at: cmTime, actualTime: nil)
  291. } catch let error {
  292. print("Error: \(error)")
  293. return nil
  294. }
  295. return UIImage(cgImage: thumbnailImageRef)
  296. }
  297. func createImageFrom(fileName: String, ocId: String, etag: String, typeFile: String) {
  298. var originalImage, scaleImagePreview, scaleImageIcon: UIImage?
  299. let fileNamePath = CCUtility.getDirectoryProviderStorageOcId(ocId, fileNameView: fileName)!
  300. let fileNamePathPreview = CCUtility.getDirectoryProviderStoragePreviewOcId(ocId, etag: etag)!
  301. let fileNamePathIcon = CCUtility.getDirectoryProviderStorageIconOcId(ocId, etag: etag)!
  302. if FileManager().fileExists(atPath: fileNamePathPreview) && FileManager().fileExists(atPath: fileNamePathIcon) { return }
  303. if !CCUtility.fileProviderStorageExists(ocId, fileNameView: fileName) { return }
  304. if typeFile != NCGlobal.shared.metadataTypeFileImage && typeFile != NCGlobal.shared.metadataTypeFileVideo { return }
  305. if typeFile == NCGlobal.shared.metadataTypeFileImage {
  306. originalImage = UIImage.init(contentsOfFile: fileNamePath)
  307. scaleImagePreview = originalImage?.resizeImage(size: CGSize(width: NCGlobal.shared.sizePreview, height: NCGlobal.shared.sizePreview), isAspectRation: false)
  308. scaleImageIcon = originalImage?.resizeImage(size: CGSize(width: NCGlobal.shared.sizeIcon, height: NCGlobal.shared.sizeIcon), isAspectRation: false)
  309. try? scaleImagePreview?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathPreview))
  310. try? scaleImageIcon?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathIcon))
  311. } else if typeFile == NCGlobal.shared.metadataTypeFileVideo {
  312. let videoPath = NSTemporaryDirectory()+"tempvideo.mp4"
  313. NCUtilityFileSystem.shared.linkItem(atPath: fileNamePath, toPath: videoPath)
  314. originalImage = imageFromVideo(url: URL(fileURLWithPath: videoPath), at: 0)
  315. try? originalImage?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathPreview))
  316. try? originalImage?.jpegData(compressionQuality: 0.7)?.write(to: URL(fileURLWithPath: fileNamePathIcon))
  317. }
  318. }
  319. @objc func getVersionApp() -> String {
  320. if let dictionary = Bundle.main.infoDictionary {
  321. if let version = dictionary["CFBundleShortVersionString"], let build = dictionary["CFBundleVersion"] {
  322. return "\(version).\(build)"
  323. }
  324. }
  325. return ""
  326. }
  327. func loadImage(named: String, color: UIColor = NCBrandColor.shared.icon, size: CGFloat = 50, symbolConfiguration: Any? = nil) -> UIImage {
  328. var image: UIImage?
  329. if #available(iOS 13.0, *) {
  330. if let symbolConfiguration = symbolConfiguration {
  331. image = UIImage(systemName: named, withConfiguration: symbolConfiguration as? UIImage.Configuration)?.imageColor(color)
  332. } else {
  333. image = UIImage(systemName: named)?.imageColor(color)
  334. }
  335. if image == nil {
  336. image = UIImage(named: named)?.image(color: color, size: size)
  337. }
  338. } else {
  339. image = UIImage(named: named)?.image(color: color, size: size)
  340. }
  341. if image != nil {
  342. return image!
  343. }
  344. return UIImage(named: "file")!.image(color: color, size: size)
  345. }
  346. @objc func createAvatar(image: UIImage, size: CGFloat) -> UIImage {
  347. var avatarImage = image
  348. let rect = CGRect(x: 0, y: 0, width: size, height: size)
  349. UIGraphicsBeginImageContextWithOptions(rect.size, false, 3.0)
  350. UIBezierPath.init(roundedRect: rect, cornerRadius: rect.size.height).addClip()
  351. avatarImage.draw(in: rect)
  352. avatarImage = UIGraphicsGetImageFromCurrentImageContext() ?? image
  353. UIGraphicsEndImageContext()
  354. return avatarImage
  355. }
  356. // MARK: -
  357. @objc func startActivityIndicator(backgroundView: UIView?, blurEffect: Bool, bottom: CGFloat = 0) {
  358. DispatchQueue.main.async {
  359. if self.viewBackgroundActivityIndicator != nil { return }
  360. self.activityIndicator.color = NCBrandColor.shared.textView
  361. self.activityIndicator.hidesWhenStopped = true
  362. self.activityIndicator.translatesAutoresizingMaskIntoConstraints = false
  363. let sizeActivityIndicator = self.activityIndicator.frame.height + 50
  364. self.viewActivityIndicator = UIView.init(frame: CGRect(x: 0, y: 0, width: sizeActivityIndicator, height: sizeActivityIndicator))
  365. self.viewActivityIndicator?.translatesAutoresizingMaskIntoConstraints = false
  366. self.viewActivityIndicator?.layer.cornerRadius = 10
  367. self.viewActivityIndicator?.layer.masksToBounds = true
  368. self.viewActivityIndicator?.backgroundColor = .clear
  369. if backgroundView == nil {
  370. if let window = UIApplication.shared.keyWindow {
  371. self.viewBackgroundActivityIndicator?.removeFromSuperview()
  372. self.viewBackgroundActivityIndicator = NCViewActivityIndicator(frame: window.bounds)
  373. window.addSubview(self.viewBackgroundActivityIndicator!)
  374. self.viewBackgroundActivityIndicator?.autoresizingMask = [.flexibleWidth, .flexibleHeight]
  375. self.viewBackgroundActivityIndicator?.backgroundColor = .clear
  376. }
  377. } else {
  378. self.viewBackgroundActivityIndicator = backgroundView
  379. }
  380. // VIEW ACTIVITY INDICATOR
  381. guard let viewActivityIndicator = self.viewActivityIndicator else { return }
  382. viewActivityIndicator.addSubview(self.activityIndicator)
  383. if blurEffect {
  384. let blurEffect = UIBlurEffect(style: .regular)
  385. let blurEffectView = UIVisualEffectView(effect: blurEffect)
  386. blurEffectView.frame = viewActivityIndicator.frame
  387. viewActivityIndicator.insertSubview(blurEffectView, at: 0)
  388. }
  389. NSLayoutConstraint.activate([
  390. viewActivityIndicator.widthAnchor.constraint(equalToConstant: sizeActivityIndicator),
  391. viewActivityIndicator.heightAnchor.constraint(equalToConstant: sizeActivityIndicator),
  392. self.activityIndicator.centerXAnchor.constraint(equalTo: viewActivityIndicator.centerXAnchor),
  393. self.activityIndicator.centerYAnchor.constraint(equalTo: viewActivityIndicator.centerYAnchor)
  394. ])
  395. // BACKGROUD VIEW ACTIVITY INDICATOR
  396. guard let viewBackgroundActivityIndicator = self.viewBackgroundActivityIndicator else { return }
  397. viewBackgroundActivityIndicator.addSubview(viewActivityIndicator)
  398. var verticalConstant: CGFloat = 0
  399. if bottom > 0 {
  400. verticalConstant = (viewBackgroundActivityIndicator.frame.size.height / 2) - bottom
  401. }
  402. NSLayoutConstraint.activate([
  403. viewActivityIndicator.centerXAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerXAnchor),
  404. viewActivityIndicator.centerYAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerYAnchor, constant: verticalConstant)
  405. ])
  406. self.activityIndicator.startAnimating()
  407. }
  408. }
  409. @objc func stopActivityIndicator() {
  410. DispatchQueue.main.async {
  411. self.activityIndicator.stopAnimating()
  412. self.activityIndicator.removeFromSuperview()
  413. self.viewActivityIndicator?.removeFromSuperview()
  414. self.viewActivityIndicator = nil
  415. if self.viewBackgroundActivityIndicator is NCViewActivityIndicator {
  416. self.viewBackgroundActivityIndicator?.removeFromSuperview()
  417. }
  418. self.viewBackgroundActivityIndicator = nil
  419. }
  420. }
  421. }
  422. // MARK: -
  423. class NCViewActivityIndicator: UIView {
  424. override init(frame: CGRect) {
  425. super.init(frame: frame)
  426. }
  427. required init?(coder: NSCoder) {
  428. fatalError("init(coder:) has not been implemented")
  429. }
  430. }