DetailInformasiSertifikasiVC.swift 16 KB

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