DetailInformasiSertifikasiVC.swift 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460
  1. //
  2. // DetailInformasiSertifikasiVC.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 31/03/19.
  6. // Copyright © 2019 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. import WebKit
  10. import Alamofire
  11. class DetailInformasiSertifikasiVC: UIViewController {
  12. @IBOutlet weak var lblSubtitle: UILabel!
  13. @IBOutlet weak var progressLayout: UIView!
  14. @IBOutlet weak var title1: UIView!
  15. @IBOutlet weak var dropdown1: UIImageView!
  16. @IBOutlet weak var lineWV1: UIView!
  17. @IBOutlet weak var wv1: WKWebView!
  18. @IBOutlet weak var line1: UIView!
  19. @IBOutlet weak var title2: UIView!
  20. @IBOutlet weak var dropdown2: UIImageView!
  21. @IBOutlet weak var lineWV2: UIView!
  22. @IBOutlet weak var wv2: WKWebView!
  23. @IBOutlet weak var line2: UIView!
  24. @IBOutlet weak var title3: UIView!
  25. @IBOutlet weak var dropdown3: UIImageView!
  26. @IBOutlet weak var lineContent3: UIView!
  27. @IBOutlet weak var content3: UIView!
  28. @IBOutlet weak var line3: UIView!
  29. @IBOutlet weak var title4: UIView!
  30. @IBOutlet weak var dropdown4: UIImageView!
  31. @IBOutlet weak var lineContent4: UIView!
  32. @IBOutlet weak var content4: UIView!
  33. @IBOutlet weak var line4: UIView!
  34. @IBOutlet weak var title5: UIView!
  35. @IBOutlet weak var dropdown5: UIImageView!
  36. @IBOutlet weak var lineContent5: UIView!
  37. @IBOutlet weak var content5: UIView!
  38. @IBOutlet weak var line5: UIView!
  39. @IBOutlet weak var title7: UIView!
  40. @IBOutlet weak var dropdown7: UIImageView!
  41. @IBOutlet weak var lineContent7: UIView!
  42. @IBOutlet weak var content7: UIView!
  43. @IBOutlet weak var line7: UIView!
  44. @IBOutlet weak var title10: UIView!
  45. @IBOutlet weak var dropdown10: UIImageView!
  46. @IBOutlet weak var lineContent10: UIView!
  47. @IBOutlet weak var content10: UIView!
  48. @IBOutlet weak var line10: UIView!
  49. @IBOutlet weak var title11: UIView!
  50. @IBOutlet weak var dropdown11: UIImageView!
  51. @IBOutlet weak var lineContent11: UIView!
  52. @IBOutlet weak var content11: UIView!
  53. @IBOutlet weak var line11: UIView!
  54. @IBOutlet weak var title12: UIView!
  55. @IBOutlet weak var dropdown12: UIImageView!
  56. @IBOutlet weak var lineWV12: UIView!
  57. @IBOutlet weak var wv12: WKWebView!
  58. @IBOutlet weak var line12: UIView!
  59. @IBOutlet weak var title13: UIView!
  60. @IBOutlet weak var dropdown13: UIImageView!
  61. @IBOutlet weak var lineWV13: UIView!
  62. @IBOutlet weak var wv13: WKWebView!
  63. @IBOutlet weak var line13: UIView!
  64. var selectedInfo = 0
  65. var subtitleLabel = ""
  66. private var loading = false
  67. private var documentInteractorController: UIDocumentInteractionController!
  68. // View Lifecycles
  69. override var preferredStatusBarStyle: UIStatusBarStyle {
  70. return .lightContent
  71. }
  72. override func viewDidLoad() {
  73. super.viewDidLoad()
  74. lblSubtitle.text = subtitleLabel
  75. switch selectedInfo {
  76. case 0:
  77. setInfo1()
  78. setInfo2()
  79. case 1:
  80. setInfo3()
  81. setInfo4()
  82. case 2:
  83. setInfo5()
  84. case 3:
  85. setInfo7()
  86. case 4:
  87. setInfo10()
  88. setInfo11()
  89. case 5:
  90. setInfo12()
  91. setInfo13()
  92. default:
  93. print("nomenu")
  94. }
  95. }
  96. private func setInfo1() {
  97. wv1.navigationDelegate = self
  98. let content = WebViewContent.instance.syarat1()
  99. wv1.loadHTMLString(content, baseURL: nil)
  100. title1.show()
  101. line1.show()
  102. }
  103. private func setInfo2() {
  104. wv2.navigationDelegate = self
  105. let content = WebViewContent.instance.syarat2()
  106. wv2.loadHTMLString(content, baseURL: nil)
  107. title2.show()
  108. line2.show()
  109. }
  110. private func setInfo3() {
  111. title3.show()
  112. line3.show()
  113. }
  114. private func setInfo4() {
  115. title4.show()
  116. line4.show()
  117. }
  118. private func setInfo5() {
  119. title5.show()
  120. line5.show()
  121. }
  122. private func setInfo7() {
  123. title7.show()
  124. line7.show()
  125. }
  126. private func setInfo10() {
  127. title10.show()
  128. line10.show()
  129. }
  130. private func setInfo11() {
  131. title11.show()
  132. line11.show()
  133. }
  134. private func setInfo12() {
  135. wv12.navigationDelegate = self
  136. let content = WebViewContent.instance.syarat3()
  137. wv12.loadHTMLString(content, baseURL: nil)
  138. title12.show()
  139. line12.show()
  140. }
  141. private func setInfo13() {
  142. wv13.navigationDelegate = self
  143. let content = WebViewContent.instance.syarat4()
  144. wv13.loadHTMLString(content, baseURL: nil)
  145. title13.show()
  146. line13.show()
  147. }
  148. @IBAction func onBackTapped(_ sender: Any) {
  149. performSegue(withIdentifier: "unwindToInfoSertifikasiWithSegueId", sender: self)
  150. }
  151. @IBAction func onTapTitle1(_ sender: Any) {
  152. if self.wv1.isHidden {
  153. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  154. self.lineWV1.show()
  155. self.lineWV1.layoutIfNeeded()
  156. self.wv1.show()
  157. self.wv1.layoutIfNeeded()
  158. self.dropdown1.rotate(-.pi)
  159. })
  160. } else {
  161. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  162. self.lineWV1.hide()
  163. self.lineWV1.layoutIfNeeded()
  164. self.wv1.hide()
  165. self.wv1.layoutIfNeeded()
  166. self.dropdown1.rotate(0.0)
  167. })
  168. }
  169. }
  170. @IBAction func onTapTitle2(_ sender: Any) {
  171. if self.wv2.isHidden {
  172. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  173. self.lineWV2.show()
  174. self.lineWV2.layoutIfNeeded()
  175. self.wv2.show()
  176. self.wv2.layoutIfNeeded()
  177. self.dropdown2.rotate(-.pi)
  178. })
  179. } else {
  180. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  181. self.lineWV2.hide()
  182. self.lineWV2.layoutIfNeeded()
  183. self.wv2.hide()
  184. self.wv2.layoutIfNeeded()
  185. self.dropdown2.rotate(0.0)
  186. })
  187. }
  188. }
  189. @IBAction func onTapTitle3(_ sender: Any) {
  190. if self.content3.isHidden {
  191. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  192. self.lineContent3.show()
  193. self.lineContent3.layoutIfNeeded()
  194. self.content3.show()
  195. self.content3.layoutIfNeeded()
  196. self.dropdown3.rotate(-.pi)
  197. })
  198. } else {
  199. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  200. self.lineContent3.hide()
  201. self.lineContent3.layoutIfNeeded()
  202. self.content3.hide()
  203. self.content3.layoutIfNeeded()
  204. self.dropdown3.rotate(0.0)
  205. })
  206. }
  207. }
  208. @IBAction func onTapTitle4(_ sender: Any) {
  209. if self.content4.isHidden {
  210. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  211. self.lineContent4.show()
  212. self.lineContent4.layoutIfNeeded()
  213. self.content4.show()
  214. self.content4.layoutIfNeeded()
  215. self.dropdown4.rotate(-.pi)
  216. })
  217. } else {
  218. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  219. self.lineContent4.hide()
  220. self.lineContent4.layoutIfNeeded()
  221. self.content4.hide()
  222. self.content4.layoutIfNeeded()
  223. self.dropdown4.rotate(0.0)
  224. })
  225. }
  226. }
  227. @IBAction func onTapTitle5(_ sender: Any) {
  228. if self.content5.isHidden {
  229. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  230. self.lineContent5.show()
  231. self.lineContent5.layoutIfNeeded()
  232. self.content5.show()
  233. self.content5.layoutIfNeeded()
  234. self.dropdown5.rotate(-.pi)
  235. })
  236. } else {
  237. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  238. self.lineContent5.hide()
  239. self.lineContent5.layoutIfNeeded()
  240. self.content5.hide()
  241. self.content5.layoutIfNeeded()
  242. self.dropdown5.rotate(0.0)
  243. })
  244. }
  245. }
  246. @IBAction func onTapTitle7(_ sender: Any) {
  247. if self.content7.isHidden {
  248. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  249. self.lineContent7.show()
  250. self.lineContent7.layoutIfNeeded()
  251. self.content7.show()
  252. self.content7.layoutIfNeeded()
  253. self.dropdown7.rotate(-.pi)
  254. })
  255. } else {
  256. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  257. self.lineContent7.hide()
  258. self.lineContent7.layoutIfNeeded()
  259. self.content7.hide()
  260. self.content7.layoutIfNeeded()
  261. self.dropdown7.rotate(0.0)
  262. })
  263. }
  264. }
  265. @IBAction func onTapTItle10(_ sender: Any) {
  266. if self.content10.isHidden {
  267. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  268. self.lineContent10.show()
  269. self.lineContent10.layoutIfNeeded()
  270. self.content10.show()
  271. self.content10.layoutIfNeeded()
  272. self.dropdown10.rotate(-.pi)
  273. })
  274. } else {
  275. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  276. self.lineContent10.hide()
  277. self.lineContent10.layoutIfNeeded()
  278. self.content10.hide()
  279. self.content10.layoutIfNeeded()
  280. self.dropdown10.rotate(0.0)
  281. })
  282. }
  283. }
  284. @IBAction func onTapTitle11(_ sender: Any) {
  285. if self.content11.isHidden {
  286. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  287. self.lineContent11.show()
  288. self.lineContent11.layoutIfNeeded()
  289. self.content11.show()
  290. self.content11.layoutIfNeeded()
  291. self.dropdown11.rotate(-.pi)
  292. })
  293. } else {
  294. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  295. self.lineContent11.hide()
  296. self.lineContent11.layoutIfNeeded()
  297. self.content11.hide()
  298. self.content11.layoutIfNeeded()
  299. self.dropdown11.rotate(0.0)
  300. })
  301. }
  302. }
  303. @IBAction func onTapTitle12(_ sender: Any) {
  304. if self.wv12.isHidden {
  305. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  306. self.lineWV12.show()
  307. self.lineWV12.layoutIfNeeded()
  308. self.wv12.show()
  309. self.wv12.layoutIfNeeded()
  310. self.dropdown12.rotate(-.pi)
  311. })
  312. } else {
  313. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  314. self.lineWV12.hide()
  315. self.lineWV12.layoutIfNeeded()
  316. self.wv12.hide()
  317. self.wv12.layoutIfNeeded()
  318. self.dropdown12.rotate(0.0)
  319. })
  320. }
  321. }
  322. @IBAction func onTapTitle13(_ sender: Any) {
  323. if self.wv13.isHidden {
  324. UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
  325. self.lineWV13.show()
  326. self.lineWV13.layoutIfNeeded()
  327. self.wv13.show()
  328. self.wv13.layoutIfNeeded()
  329. self.dropdown13.rotate(-.pi)
  330. })
  331. } else {
  332. UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
  333. self.lineWV13.hide()
  334. self.lineWV13.layoutIfNeeded()
  335. self.wv13.hide()
  336. self.wv13.layoutIfNeeded()
  337. self.dropdown13.rotate(0.0)
  338. })
  339. }
  340. }
  341. private func downloadFile(urlRequest: String, filename: String) {
  342. if !loading {
  343. if ConnectionHelper.isConnectedToNetwork() {
  344. self.progressLayout.show()
  345. self.loading = true
  346. let destination: DownloadRequest.Destination = { _, _ in
  347. let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
  348. let fileURL = documentsURL.appendingPathComponent(filename)
  349. return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
  350. }
  351. AF.download(urlRequest, to: destination).validate().responseData { response in
  352. if let url = response.fileURL {
  353. self.documentInteractorController = UIDocumentInteractionController()
  354. self.documentInteractorController.delegate = self
  355. self.documentInteractorController.url = url
  356. self.documentInteractorController.presentPreview(animated: true)
  357. }
  358. DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
  359. self.progressLayout.hide()
  360. self.loading = false
  361. }
  362. }
  363. }
  364. }
  365. }
  366. @IBAction func onTapDownload4(_ sender: Any) {
  367. // downloadFile(urlRequest: METHOD_DOWNLOAD_USER_MANUAL, filename: "user_manual.pdf")
  368. }
  369. @IBAction func onTapDownload10(_ sender: Any) {
  370. downloadFile(urlRequest: METHOD_DOWNLOAD_H2H_MANDIRI, filename: "h2h_mandiri.pdf")
  371. }
  372. @IBAction func onTapDownload11(_ sender: Any) {
  373. downloadFile(urlRequest: METHOD_DOWNLOAD_H2H_BNI, filename: "h2h_bni.pdf")
  374. }
  375. }
  376. extension DetailInformasiSertifikasiVC: WKNavigationDelegate {
  377. func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
  378. if navigationAction.navigationType == .linkActivated {
  379. guard let url = navigationAction.request.url else {
  380. decisionHandler(.allow)
  381. return
  382. }
  383. let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
  384. if components?.scheme == "http" || components?.scheme == "https" || components?.scheme == "mailto"
  385. {
  386. if UIApplication.shared.canOpenURL(url) {
  387. if #available(iOS 10.0, *) {
  388. UIApplication.shared.open(url)
  389. } else {
  390. UIApplication.shared.openURL(url)
  391. }
  392. decisionHandler(.cancel)
  393. } else {
  394. decisionHandler(.allow)
  395. }
  396. } else {
  397. decisionHandler(.allow)
  398. }
  399. } else {
  400. decisionHandler(.allow)
  401. }
  402. }
  403. }
  404. extension DetailInformasiSertifikasiVC: UIDocumentInteractionControllerDelegate {
  405. func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
  406. guard let navVC = self.navigationController else {
  407. return self
  408. }
  409. return navVC
  410. }
  411. }