| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465 |
- //
- // DetailInformasiSertifikasiVC.swift
- // Sirani
- //
- // Created by Anhar Solehudin on 31/03/19.
- // Copyright © 2019 Anhar Solehudin. All rights reserved.
- //
- import UIKit
- import WebKit
- import Alamofire
- class DetailInformasiSertifikasiVC: UIViewController {
-
- @IBOutlet weak var lblSubtitle: UILabel!
- @IBOutlet weak var progressLayout: UIView!
-
- @IBOutlet weak var title1: UIView!
- @IBOutlet weak var dropdown1: UIImageView!
- @IBOutlet weak var lineWV1: UIView!
- @IBOutlet weak var wv1: WKWebView!
- @IBOutlet weak var line1: UIView!
-
- @IBOutlet weak var title2: UIView!
- @IBOutlet weak var dropdown2: UIImageView!
- @IBOutlet weak var lineWV2: UIView!
- @IBOutlet weak var wv2: WKWebView!
- @IBOutlet weak var line2: UIView!
-
- @IBOutlet weak var title3: UIView!
- @IBOutlet weak var dropdown3: UIImageView!
- @IBOutlet weak var lineContent3: UIView!
- @IBOutlet weak var content3: UIView!
- @IBOutlet weak var line3: UIView!
-
- @IBOutlet weak var title4: UIView!
- @IBOutlet weak var dropdown4: UIImageView!
- @IBOutlet weak var lineContent4: UIView!
- @IBOutlet weak var content4: UIView!
- @IBOutlet weak var line4: UIView!
-
- @IBOutlet weak var title5: UIView!
- @IBOutlet weak var dropdown5: UIImageView!
- @IBOutlet weak var lineContent5: UIView!
- @IBOutlet weak var content5: UIView!
- @IBOutlet weak var line5: UIView!
-
- @IBOutlet weak var title7: UIView!
- @IBOutlet weak var dropdown7: UIImageView!
- @IBOutlet weak var lineContent7: UIView!
- @IBOutlet weak var content7: UIView!
- @IBOutlet weak var line7: UIView!
-
- @IBOutlet weak var title10: UIView!
- @IBOutlet weak var dropdown10: UIImageView!
- @IBOutlet weak var lineContent10: UIView!
- @IBOutlet weak var content10: UIView!
- @IBOutlet weak var line10: UIView!
-
- @IBOutlet weak var title11: UIView!
- @IBOutlet weak var dropdown11: UIImageView!
- @IBOutlet weak var lineContent11: UIView!
- @IBOutlet weak var content11: UIView!
- @IBOutlet weak var line11: UIView!
-
- @IBOutlet weak var title12: UIView!
- @IBOutlet weak var dropdown12: UIImageView!
- @IBOutlet weak var lineWV12: UIView!
- @IBOutlet weak var wv12: WKWebView!
- @IBOutlet weak var line12: UIView!
-
- @IBOutlet weak var title13: UIView!
- @IBOutlet weak var dropdown13: UIImageView!
- @IBOutlet weak var lineWV13: UIView!
- @IBOutlet weak var wv13: WKWebView!
- @IBOutlet weak var line13: UIView!
-
- var selectedInfo = 0
- var subtitleLabel = ""
- private var loading = false
- private var documentInteractorController: UIDocumentInteractionController!
-
- // View Lifecycles
- override var preferredStatusBarStyle: UIStatusBarStyle {
- return .lightContent
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- lblSubtitle.text = subtitleLabel
-
- switch selectedInfo {
- case 0:
- setInfo(uri: URI_PERSYARATAN_KEWAJIBAN)
- case 1:
- setInfo(uri: URI_PROSEDUR_SERTIFIKASI)
- case 2:
- setInfo(uri: URI_PROSEDUR_PERUBAHAN)
- case 3:
- setInfo(uri: URI_INFO_PEMBAYARAN)
- case 4:
- setInfo(uri: URI_PROSEDUR_PENERBITAN)
- case 5:
- setInfo(uri: URI_PROSEDUR_KELUHAN)
- default:
- print("nomenu")
- }
- }
-
- private func setInfo(uri : String) {
- wv1.navigationDelegate = self
- if let url = URL(string: uri) {
- let request = URLRequest(url: url)
- wv1.load(request)
- }
- self.wv1.show()
- }
-
- private func setInfo1() {
- wv1.navigationDelegate = self
- let content = WebViewContent.instance.syarat1()
- wv1.loadHTMLString(content, baseURL: nil)
- title1.show()
- line1.show()
- }
-
- private func setInfo2() {
- wv2.navigationDelegate = self
- let content = WebViewContent.instance.syarat2()
- wv2.loadHTMLString(content, baseURL: nil)
- title2.show()
- line2.show()
- }
-
- private func setInfo3() {
- title3.show()
- line3.show()
- }
-
- private func setInfo4() {
- title4.show()
- line4.show()
- }
-
- private func setInfo5() {
- title5.show()
- line5.show()
- }
-
- private func setInfo7() {
- title7.show()
- line7.show()
- }
-
- private func setInfo10() {
- title10.show()
- line10.show()
- }
-
- private func setInfo11() {
- title11.show()
- line11.show()
- }
-
- private func setInfo12() {
- wv12.navigationDelegate = self
- let content = WebViewContent.instance.syarat3()
- wv12.loadHTMLString(content, baseURL: nil)
- title12.show()
- line12.show()
- }
-
- private func setInfo13() {
- wv13.navigationDelegate = self
- let content = WebViewContent.instance.syarat4()
- wv13.loadHTMLString(content, baseURL: nil)
- title13.show()
- line13.show()
- }
-
- @IBAction func onBackTapped(_ sender: Any) {
- performSegue(withIdentifier: "unwindToInfoSertifikasiWithSegueId", sender: self)
- }
-
- @IBAction func onTapTitle1(_ sender: Any) {
- if self.wv1.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineWV1.show()
- self.lineWV1.layoutIfNeeded()
- self.wv1.show()
- self.wv1.layoutIfNeeded()
- self.dropdown1.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineWV1.hide()
- self.lineWV1.layoutIfNeeded()
- self.wv1.hide()
- self.wv1.layoutIfNeeded()
- self.dropdown1.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle2(_ sender: Any) {
- if self.wv2.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineWV2.show()
- self.lineWV2.layoutIfNeeded()
- self.wv2.show()
- self.wv2.layoutIfNeeded()
- self.dropdown2.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineWV2.hide()
- self.lineWV2.layoutIfNeeded()
- self.wv2.hide()
- self.wv2.layoutIfNeeded()
- self.dropdown2.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle3(_ sender: Any) {
- if self.content3.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineContent3.show()
- self.lineContent3.layoutIfNeeded()
- self.content3.show()
- self.content3.layoutIfNeeded()
- self.dropdown3.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineContent3.hide()
- self.lineContent3.layoutIfNeeded()
- self.content3.hide()
- self.content3.layoutIfNeeded()
- self.dropdown3.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle4(_ sender: Any) {
- if self.content4.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineContent4.show()
- self.lineContent4.layoutIfNeeded()
- self.content4.show()
- self.content4.layoutIfNeeded()
- self.dropdown4.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineContent4.hide()
- self.lineContent4.layoutIfNeeded()
- self.content4.hide()
- self.content4.layoutIfNeeded()
- self.dropdown4.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle5(_ sender: Any) {
- if self.content5.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineContent5.show()
- self.lineContent5.layoutIfNeeded()
- self.content5.show()
- self.content5.layoutIfNeeded()
- self.dropdown5.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineContent5.hide()
- self.lineContent5.layoutIfNeeded()
- self.content5.hide()
- self.content5.layoutIfNeeded()
- self.dropdown5.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle7(_ sender: Any) {
- if self.content7.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineContent7.show()
- self.lineContent7.layoutIfNeeded()
- self.content7.show()
- self.content7.layoutIfNeeded()
- self.dropdown7.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineContent7.hide()
- self.lineContent7.layoutIfNeeded()
- self.content7.hide()
- self.content7.layoutIfNeeded()
- self.dropdown7.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTItle10(_ sender: Any) {
- if self.content10.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineContent10.show()
- self.lineContent10.layoutIfNeeded()
- self.content10.show()
- self.content10.layoutIfNeeded()
- self.dropdown10.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineContent10.hide()
- self.lineContent10.layoutIfNeeded()
- self.content10.hide()
- self.content10.layoutIfNeeded()
- self.dropdown10.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle11(_ sender: Any) {
- if self.content11.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineContent11.show()
- self.lineContent11.layoutIfNeeded()
- self.content11.show()
- self.content11.layoutIfNeeded()
- self.dropdown11.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineContent11.hide()
- self.lineContent11.layoutIfNeeded()
- self.content11.hide()
- self.content11.layoutIfNeeded()
- self.dropdown11.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle12(_ sender: Any) {
- if self.wv12.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineWV12.show()
- self.lineWV12.layoutIfNeeded()
- self.wv12.show()
- self.wv12.layoutIfNeeded()
- self.dropdown12.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineWV12.hide()
- self.lineWV12.layoutIfNeeded()
- self.wv12.hide()
- self.wv12.layoutIfNeeded()
- self.dropdown12.rotate(0.0)
- })
- }
- }
-
- @IBAction func onTapTitle13(_ sender: Any) {
- if self.wv13.isHidden {
- UIView.animate(withDuration: 0.25, delay: 0, options: .curveEaseOut, animations: {
- self.lineWV13.show()
- self.lineWV13.layoutIfNeeded()
- self.wv13.show()
- self.wv13.layoutIfNeeded()
- self.dropdown13.rotate(-.pi)
- })
- } else {
- UIView.animate(withDuration: 0, delay: 0, options: .curveEaseIn, animations: {
- self.lineWV13.hide()
- self.lineWV13.layoutIfNeeded()
- self.wv13.hide()
- self.wv13.layoutIfNeeded()
- self.dropdown13.rotate(0.0)
- })
- }
- }
-
- private func downloadFile(urlRequest: String, filename: String) {
- if !loading {
- if ConnectionHelper.isConnectedToNetwork() {
- self.progressLayout.show()
- self.loading = true
-
- let destination: DownloadRequest.Destination = { _, _ in
- let documentsURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
- let fileURL = documentsURL.appendingPathComponent(filename)
- return (fileURL, [.removePreviousFile, .createIntermediateDirectories])
- }
-
- AF.download(urlRequest, to: destination).validate().responseData { response in
- if let url = response.fileURL {
- self.documentInteractorController = UIDocumentInteractionController()
- self.documentInteractorController.delegate = self
- self.documentInteractorController.url = url
- self.documentInteractorController.presentPreview(animated: true)
- }
-
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.6) {
- self.progressLayout.hide()
- self.loading = false
- }
- }
- }
- }
- }
-
- @IBAction func onTapDownload4(_ sender: Any) {
- // downloadFile(urlRequest: METHOD_DOWNLOAD_USER_MANUAL, filename: "user_manual.pdf")
- }
-
- @IBAction func onTapDownload10(_ sender: Any) {
- downloadFile(urlRequest: METHOD_DOWNLOAD_H2H_MANDIRI, filename: "h2h_mandiri.pdf")
- }
-
- @IBAction func onTapDownload11(_ sender: Any) {
- downloadFile(urlRequest: METHOD_DOWNLOAD_H2H_BNI, filename: "h2h_bni.pdf")
- }
-
- }
- extension DetailInformasiSertifikasiVC: WKNavigationDelegate {
- func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
- if navigationAction.navigationType == .linkActivated {
- guard let url = navigationAction.request.url else {
- decisionHandler(.allow)
- return
- }
-
- let components = URLComponents(url: url, resolvingAgainstBaseURL: false)
- if components?.scheme == "http" || components?.scheme == "https" || components?.scheme == "mailto"
- {
- if UIApplication.shared.canOpenURL(url) {
- if #available(iOS 10.0, *) {
- UIApplication.shared.open(url)
- } else {
- UIApplication.shared.openURL(url)
- }
- decisionHandler(.cancel)
- } else {
- decisionHandler(.allow)
- }
- } else {
- decisionHandler(.allow)
- }
- } else {
- decisionHandler(.allow)
- }
- }
- }
- extension DetailInformasiSertifikasiVC: UIDocumentInteractionControllerDelegate {
- func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
- guard let navVC = self.navigationController else {
- return self
- }
- return navVC
- }
- }
|