HomeVC.swift 54 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344
  1. //
  2. // HomeVC.swift
  3. // Sirani
  4. //
  5. // Created by Anhar Solehudin on 24/03/19.
  6. // Copyright © 2019 Anhar Solehudin. All rights reserved.
  7. //
  8. import UIKit
  9. import ImageSlideshow
  10. class HomeVC: UIViewController {
  11. // Outlets
  12. @IBOutlet weak var notifContainer: UIView!
  13. @IBOutlet weak var notifBg: CircleView!
  14. @IBOutlet weak var lblNotif: UILabel!
  15. @IBOutlet weak var progressLayout: UIView!
  16. @IBOutlet weak var progress: UIActivityIndicatorView!
  17. @IBOutlet weak var slideshow: ImageSlideshow!
  18. @IBOutlet weak var container: UIView!
  19. @IBOutlet weak var moreMenuLayout: UIView!
  20. @IBOutlet weak var headerLayout: UIView!
  21. @IBOutlet weak var moreMenuContainer: UIView!
  22. @IBOutlet weak var mainMenuCV: UICollectionView!
  23. @IBOutlet weak var btnMoreMenu: UIButton!
  24. @IBOutlet weak var btnMoreNews: UIButton!
  25. @IBOutlet weak var homeNewsTV: UITableView!
  26. @IBOutlet weak var moreMenuUtamaCV: UICollectionView!
  27. @IBOutlet weak var moreMenuNewTitleLayout: UIView!
  28. @IBOutlet weak var moreMenuNewNotif: UIView!
  29. @IBOutlet weak var lblMoreMenuUtamaNewNotif: UILabel!
  30. @IBOutlet weak var moreMenuUtamaNewCV: UICollectionView!
  31. @IBOutlet weak var marginMoreMenuUtamaNew: UIView!
  32. @IBOutlet weak var moreMenuAplikasiODSTitleLayout: UIView!
  33. @IBOutlet weak var moreMenuOdsNotif: UIView!
  34. @IBOutlet weak var lblMoreMenuAplikasiODSNotif: UILabel!
  35. @IBOutlet weak var moreMenuAplikasiODSCV: UICollectionView!
  36. @IBOutlet weak var marginMoreMenuAplikasiODS: UIView!
  37. @IBOutlet weak var moreMenuFotoLabelTitleLayout: UIView!
  38. @IBOutlet weak var moreMenuFotoLabelNotif: UIView!
  39. @IBOutlet weak var lblMoreMenuFotoLabelNotif: UILabel!
  40. @IBOutlet weak var moreMenuFotoLabelCV: UICollectionView!
  41. @IBOutlet weak var marginMoreMenuFotoLabel: UIView!
  42. @IBOutlet weak var moreMenuAplikasiTitleLayout: UIView!
  43. @IBOutlet weak var moreMenuAplikasiNotif: UIView!
  44. @IBOutlet weak var lblMoreMenuAplikasiNotif: UILabel!
  45. @IBOutlet weak var moreMenuAplikasiCV: UICollectionView!
  46. @IBOutlet weak var marginMoreMenuAplikasi: UIView!
  47. @IBOutlet weak var moreMenuSP2SertifikatTitleLayout: UIView!
  48. @IBOutlet weak var moreMenuSP2SertifikatNotif: UIView!
  49. @IBOutlet weak var lblMoreMenuSP2SertifikatNotif: UILabel!
  50. @IBOutlet weak var moreMenuSP2SertifikatCV: UICollectionView!
  51. @IBOutlet weak var marginMoreMenuSP2Sertifikat: UIView!
  52. @IBOutlet weak var moreMenuSP2TambahanTItleLayout: UIView!
  53. @IBOutlet weak var moreMenuSP2TambahanNotif: UIView!
  54. @IBOutlet weak var lblMoreMenuSP2TambahanNotif: UILabel!
  55. @IBOutlet weak var moreMenuSP2TambahanCV: UICollectionView!
  56. @IBOutlet weak var marginMoreMenuSP2Tambahan: UIView!
  57. @IBOutlet weak var moreMenuDaftarRHUTitleLayout: UIView!
  58. @IBOutlet weak var moreMenuDaftarRhuNotif: UIView!
  59. @IBOutlet weak var lblMoreMenuDaftarRHUNotif: UILabel!
  60. @IBOutlet weak var moreMenuDaftarRHUCV: UICollectionView!
  61. @IBOutlet weak var marginMoreMenuDaftarRHU: UIView!
  62. @IBOutlet weak var moreMenuSertifikatTitleLayout: UIView!
  63. @IBOutlet weak var moreMenuSertifikatNotif: UIView!
  64. @IBOutlet weak var lblMoreMenuSertifikatNotif: UILabel!
  65. @IBOutlet weak var moreMenuSertifikatCV: UICollectionView!
  66. @IBOutlet weak var marginMoreMenuSertifikat: UIView!
  67. @IBOutlet weak var moreMenuSurveyTitleLayout: UIView!
  68. @IBOutlet weak var moreMenuSurveyNotif: UIView!
  69. @IBOutlet weak var lblMoreMenuNotif: UILabel!
  70. @IBOutlet weak var moreMenuSurveyCV: UICollectionView!
  71. @IBOutlet weak var marginMoreMenuSurvey: UIView!
  72. // id
  73. private let homeNewsCellId = "HomeNewsCellId"
  74. // initialize
  75. private let presenter = HomePresenter(siraniApiServices: SiraniApiServices())
  76. // data list
  77. private var listNews = [News]()
  78. private let listMenuUtama = MenuListData.instance.getMenuUtamaData()
  79. private var listMenuUtamaNew = [MenuItem]()
  80. private var listMenuAplikasiODS = [MenuItem]()
  81. private var listMenuFotoLabel = [MenuItem]()
  82. private var listMenuAplikasi = [MenuItem]()
  83. private var listMenuSP2Sertifikat = [MenuItem]()
  84. private var listMenuSP2Tambahan = [MenuItem]()
  85. private var listMenuDaftarRHU = [MenuItem]()
  86. private var listMenuSertifikat = [MenuItem]()
  87. private var listMenuSurvey = [MenuItem]()
  88. // Constants
  89. private let menuItemSize = 85.75
  90. private let CUSTOMER_ROLE_ID = Constants.instance.CUSTOMER_ROLE_ID
  91. private let OPERATOR_ROLE_ID = Constants.instance.OPERATOR_ROLE_ID
  92. private let KEPALA_SEKSI_ROLE_ID = Constants.instance.KEPALA_SEKSI_ROLE_ID
  93. private let KEPALA_SUB_DIREKTORAT_ROLE_ID = Constants.instance.KEPALA_SUB_DIREKTORAT_ROLE_ID
  94. private let DIREKTUR_ROLE_ID = Constants.instance.DIREKTUR_ROLE_ID
  95. // Variables (notes : let is constants)
  96. private var moreMenuFrame: CGRect?
  97. private var loading = false
  98. private var selectedNewsId = 0
  99. private var date = ""
  100. private var judul = ""
  101. private var urlThumb = ""
  102. private var moreMenuShown = false
  103. private var showMoreMenuDuration = 0.2
  104. private var userRoleId = ""
  105. public var openNotif = false
  106. // Modern Header UI (Matching Mockup)
  107. private let modernHeaderView: UIView = {
  108. let v = UIView()
  109. v.backgroundColor = .clear
  110. return v
  111. }()
  112. private let logoImageView: UIImageView = {
  113. let iv = UIImageView()
  114. iv.image = UIImage(named: "logo-header")
  115. iv.contentMode = .scaleAspectFit
  116. iv.clipsToBounds = true
  117. return iv
  118. }()
  119. private let lblGreeting: UILabel = {
  120. let lbl = UILabel()
  121. lbl.font = UIFont.systemFont(ofSize: 13, weight: .regular)
  122. lbl.textColor = UIColor.siraniTextSecondary
  123. return lbl
  124. }()
  125. private let lblUserName: UILabel = {
  126. let lbl = UILabel()
  127. lbl.font = UIFont.systemFont(ofSize: 22, weight: .bold)
  128. lbl.textColor = UIColor.siraniTextPrimary
  129. lbl.numberOfLines = 1
  130. lbl.adjustsFontSizeToFitWidth = true
  131. return lbl
  132. }()
  133. private let btnHeaderNotif: UIButton = {
  134. let btn = UIButton(type: .system)
  135. if #available(iOS 13.0, *) {
  136. let config = UIImage.SymbolConfiguration(pointSize: 16, weight: .medium)
  137. btn.setImage(UIImage(systemName: "bell.fill", withConfiguration: config), for: .normal)
  138. } else {
  139. btn.setImage(UIImage(named: "ic-notif"), for: .normal)
  140. }
  141. btn.tintColor = UIColor.siraniPrimaryBlue
  142. btn.backgroundColor = UIColor.siraniSoftBlue
  143. btn.layer.cornerRadius = 20
  144. btn.layer.masksToBounds = true
  145. return btn
  146. }()
  147. private let headerNotifBadge: UIView = {
  148. let v = UIView()
  149. v.backgroundColor = UIColor(red: 220/255, green: 38/255, blue: 38/255, alpha: 1.0)
  150. v.layer.cornerRadius = 7
  151. v.layer.masksToBounds = true
  152. v.isHidden = true
  153. return v
  154. }()
  155. private let headerNotifBadgeLabel: UILabel = {
  156. let lbl = UILabel()
  157. lbl.font = UIFont.systemFont(ofSize: 9, weight: .bold)
  158. lbl.textColor = .white
  159. lbl.textAlignment = .center
  160. return lbl
  161. }()
  162. private let btnHeaderProfile: UIButton = {
  163. let btn = UIButton(type: .system)
  164. if #available(iOS 13.0, *) {
  165. let config = UIImage.SymbolConfiguration(pointSize: 16, weight: .medium)
  166. btn.setImage(UIImage(systemName: "person.fill", withConfiguration: config), for: .normal)
  167. } else {
  168. btn.setImage(UIImage(named: "nav-account"), for: .normal)
  169. }
  170. btn.tintColor = UIColor.siraniPrimaryBlue
  171. btn.backgroundColor = UIColor.siraniSoftBlue
  172. btn.layer.cornerRadius = 20
  173. btn.layer.masksToBounds = true
  174. return btn
  175. }()
  176. // View Lifecycles
  177. override var preferredStatusBarStyle: UIStatusBarStyle {
  178. if #available(iOS 13.0, *) {
  179. return .darkContent
  180. } else {
  181. return .default
  182. }
  183. }
  184. override func viewWillAppear(_ animated: Bool) {
  185. AppUtility.lockOrientation(.portrait)
  186. checkUserState()
  187. updateGreetingText()
  188. setupModernTabBar()
  189. btnMoreMenu.setTitle("Lihat semua", for: .normal)
  190. btnMoreMenu.setTitleColor(UIColor.siraniPrimaryBlue, for: .normal)
  191. btnMoreMenu.backgroundColor = .clear
  192. btnMoreMenu.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .semibold)
  193. btnMoreNews.setTitle("Lihat semua", for: .normal)
  194. btnMoreNews.setTitleColor(UIColor.siraniPrimaryBlue, for: .normal)
  195. btnMoreNews.backgroundColor = .clear
  196. btnMoreNews.titleLabel?.font = UIFont.systemFont(ofSize: 13, weight: .semibold)
  197. moreMenuFrame = moreMenuLayout.frame
  198. moreMenuLayout.frame = .init(
  199. x: 0,
  200. y: view.frame.height,
  201. width: moreMenuFrame!.size.width,
  202. height: moreMenuFrame!.size.height
  203. )
  204. let gesture = UITapGestureRecognizer(target: self, action: #selector(self.openNotifList))
  205. notifContainer.addGestureRecognizer(gesture)
  206. userRoleId = UserState.instance.getRoleId()
  207. let userId = UserState.instance.getUserId()
  208. let custId = UserState.instance.getCustId()
  209. if !userRoleId.isEmpty {
  210. showNotif()
  211. } else {
  212. hideNotif()
  213. }
  214. setSlideImageView()
  215. setNewsView()
  216. }
  217. override func viewDidLoad() {
  218. super.viewDidLoad()
  219. presenter.attachView(view: self)
  220. setupPremiumHeader()
  221. setupModernTabBar()
  222. if openNotif {
  223. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  224. }
  225. setMainMenu()
  226. userRoleId = UserState.instance.getRoleId()
  227. if !userRoleId.isEmpty {
  228. setMoreMenuUtamaNew(userRoleId: userRoleId)
  229. showNotif()
  230. } else {
  231. hideNotif()
  232. }
  233. }
  234. override func viewDidAppear(_ animated: Bool) {
  235. presenter.attachView(view: self)
  236. setupModernTabBar()
  237. if openNotif {
  238. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  239. }
  240. if moreMenuShown {
  241. showMoreMenu()
  242. }
  243. if !userRoleId.isEmpty {
  244. clearMoreMenu()
  245. setMoreMenuUtamaNew(userRoleId: userRoleId)
  246. clearMoreMenuNotifData()
  247. if ConnectionHelper.isConnectedToNetwork() {
  248. self.presenter.loadMenuNotifications()
  249. } else {
  250. CommonHelper.showNoConnection(in: self)
  251. }
  252. showNotif()
  253. } else {
  254. clearMoreMenu()
  255. clearMoreMenuNotifData()
  256. hideNotif()
  257. }
  258. }
  259. override func viewWillDisappear(_ animated: Bool) {
  260. AppUtility.lockOrientation(.all)
  261. }
  262. override func viewDidDisappear(_ animated: Bool) {
  263. presenter.detachView()
  264. }
  265. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  266. if let destVC = segue.destination as? NewsDetailVC {
  267. destVC.newsId = self.selectedNewsId
  268. destVC.date = self.date
  269. destVC.judul = self.judul
  270. destVC.urlThumb = self.urlThumb.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
  271. destVC.segueId = destVC.SEGUE_HOME_ID
  272. }
  273. }
  274. private func setupModernTabBar() {
  275. guard let tabBar = self.tabBarController?.tabBar else { return }
  276. tabBar.backgroundColor = .white
  277. tabBar.barTintColor = .white
  278. tabBar.tintColor = UIColor.siraniPrimaryBlue
  279. tabBar.unselectedItemTintColor = UIColor.siraniUnselectedGray
  280. if let items = tabBar.items, items.count >= 5 {
  281. if #available(iOS 13.0, *) {
  282. let symbols = ["house.fill", "qrcode.viewfinder", "questionmark.circle.fill", "bubble.left.and.bubble.right.fill", "person.fill"]
  283. for i in 0..<min(items.count, symbols.count) {
  284. if let img = UIImage(systemName: symbols[i]) {
  285. items[i].image = img
  286. items[i].selectedImage = img
  287. }
  288. }
  289. }
  290. }
  291. }
  292. @objc func openProfile() {
  293. if let tabBar = self.tabBarController {
  294. tabBar.selectedIndex = (tabBar.viewControllers?.count ?? 1) - 1
  295. }
  296. }
  297. private func updateGreetingText() {
  298. let hour = Calendar.current.component(.hour, from: Date())
  299. var greeting = "Selamat Pagi"
  300. if hour >= 11 && hour < 15 {
  301. greeting = "Selamat Siang"
  302. } else if hour >= 15 && hour < 18 {
  303. greeting = "Selamat Sore"
  304. } else if hour >= 18 || hour < 4 {
  305. greeting = "Selamat Malam"
  306. }
  307. lblGreeting.text = greeting
  308. let fullname = UserState.instance.getFullname()
  309. let username = UserState.instance.getUsername()
  310. if !fullname.isEmpty {
  311. lblUserName.text = fullname
  312. } else if !username.isEmpty {
  313. lblUserName.text = username
  314. } else {
  315. lblUserName.text = "SIRANI Komdigi"
  316. }
  317. }
  318. // private functions
  319. private func checkUserState() {
  320. let isLoggedIn = UserState.instance.isLoggedIn()
  321. if isLoggedIn {
  322. btnMoreMenu.show()
  323. } else {
  324. btnMoreMenu.hide()
  325. }
  326. }
  327. private func setupPremiumHeader() {
  328. // 1. Canvas background
  329. self.view.backgroundColor = UIColor.siraniCanvasBackground
  330. container.backgroundColor = UIColor.siraniCanvasBackground
  331. // 2. Hide legacy header views and setup modern greeting header
  332. for subview in headerLayout.subviews {
  333. subview.isHidden = true
  334. }
  335. headerLayout.backgroundColor = UIColor.siraniCanvasBackground
  336. modernHeaderView.subviews.forEach { $0.removeFromSuperview() }
  337. modernHeaderView.removeFromSuperview()
  338. headerLayout.addSubview(modernHeaderView)
  339. modernHeaderView.translatesAutoresizingMaskIntoConstraints = false
  340. NSLayoutConstraint.activate([
  341. modernHeaderView.topAnchor.constraint(equalTo: headerLayout.safeAreaLayoutGuide.topAnchor),
  342. modernHeaderView.leadingAnchor.constraint(equalTo: headerLayout.leadingAnchor, constant: 16),
  343. modernHeaderView.trailingAnchor.constraint(equalTo: headerLayout.trailingAnchor, constant: -16),
  344. modernHeaderView.bottomAnchor.constraint(equalTo: headerLayout.bottomAnchor, constant: -4)
  345. ])
  346. modernHeaderView.addSubview(logoImageView)
  347. modernHeaderView.addSubview(lblGreeting)
  348. modernHeaderView.addSubview(lblUserName)
  349. modernHeaderView.addSubview(btnHeaderProfile)
  350. modernHeaderView.addSubview(btnHeaderNotif)
  351. btnHeaderNotif.addSubview(headerNotifBadge)
  352. headerNotifBadge.addSubview(headerNotifBadgeLabel)
  353. logoImageView.translatesAutoresizingMaskIntoConstraints = false
  354. lblGreeting.translatesAutoresizingMaskIntoConstraints = false
  355. lblUserName.translatesAutoresizingMaskIntoConstraints = false
  356. btnHeaderProfile.translatesAutoresizingMaskIntoConstraints = false
  357. btnHeaderNotif.translatesAutoresizingMaskIntoConstraints = false
  358. headerNotifBadge.translatesAutoresizingMaskIntoConstraints = false
  359. headerNotifBadgeLabel.translatesAutoresizingMaskIntoConstraints = false
  360. NSLayoutConstraint.activate([
  361. logoImageView.centerYAnchor.constraint(equalTo: modernHeaderView.centerYAnchor),
  362. logoImageView.leadingAnchor.constraint(equalTo: modernHeaderView.leadingAnchor),
  363. logoImageView.widthAnchor.constraint(equalToConstant: 42),
  364. logoImageView.heightAnchor.constraint(equalToConstant: 42),
  365. lblGreeting.topAnchor.constraint(equalTo: modernHeaderView.topAnchor, constant: 4),
  366. lblGreeting.leadingAnchor.constraint(equalTo: logoImageView.trailingAnchor, constant: 10),
  367. lblGreeting.trailingAnchor.constraint(lessThanOrEqualTo: btnHeaderNotif.leadingAnchor, constant: -8),
  368. lblUserName.topAnchor.constraint(equalTo: lblGreeting.bottomAnchor, constant: 2),
  369. lblUserName.leadingAnchor.constraint(equalTo: logoImageView.trailingAnchor, constant: 10),
  370. lblUserName.trailingAnchor.constraint(lessThanOrEqualTo: btnHeaderNotif.leadingAnchor, constant: -8),
  371. lblUserName.bottomAnchor.constraint(lessThanOrEqualTo: modernHeaderView.bottomAnchor, constant: -4),
  372. btnHeaderProfile.centerYAnchor.constraint(equalTo: modernHeaderView.centerYAnchor),
  373. btnHeaderProfile.trailingAnchor.constraint(equalTo: modernHeaderView.trailingAnchor),
  374. btnHeaderProfile.widthAnchor.constraint(equalToConstant: 40),
  375. btnHeaderProfile.heightAnchor.constraint(equalToConstant: 40),
  376. btnHeaderNotif.centerYAnchor.constraint(equalTo: modernHeaderView.centerYAnchor),
  377. btnHeaderNotif.trailingAnchor.constraint(equalTo: btnHeaderProfile.leadingAnchor, constant: -10),
  378. btnHeaderNotif.widthAnchor.constraint(equalToConstant: 40),
  379. btnHeaderNotif.heightAnchor.constraint(equalToConstant: 40),
  380. headerNotifBadge.topAnchor.constraint(equalTo: btnHeaderNotif.topAnchor, constant: -2),
  381. headerNotifBadge.trailingAnchor.constraint(equalTo: btnHeaderNotif.trailingAnchor, constant: 2),
  382. headerNotifBadge.heightAnchor.constraint(equalToConstant: 16),
  383. headerNotifBadge.widthAnchor.constraint(greaterThanOrEqualToConstant: 16),
  384. headerNotifBadgeLabel.centerXAnchor.constraint(equalTo: headerNotifBadge.centerXAnchor),
  385. headerNotifBadgeLabel.centerYAnchor.constraint(equalTo: headerNotifBadge.centerYAnchor),
  386. headerNotifBadgeLabel.leadingAnchor.constraint(greaterThanOrEqualTo: headerNotifBadge.leadingAnchor, constant: 3),
  387. headerNotifBadgeLabel.trailingAnchor.constraint(lessThanOrEqualTo: headerNotifBadge.trailingAnchor, constant: -3)
  388. ])
  389. btnHeaderNotif.addTarget(self, action: #selector(openNotifList), for: .touchUpInside)
  390. btnHeaderProfile.addTarget(self, action: #selector(openProfile), for: .touchUpInside)
  391. updateGreetingText()
  392. // 3. Slideshow styling as floating card
  393. slideshow.layer.cornerRadius = 14
  394. slideshow.layer.masksToBounds = true
  395. slideshow.clipsToBounds = true
  396. slideshow.contentScaleMode = .scaleAspectFill
  397. // 4. Collection view and table styling
  398. mainMenuCV.backgroundColor = .clear
  399. homeNewsTV.backgroundColor = .clear
  400. homeNewsTV.separatorStyle = .none
  401. }
  402. private func showNotif() {
  403. notifContainer.show()
  404. if ConnectionHelper.isConnectedToNetwork() {
  405. self.presenter.loadTotalUnreadNotif()
  406. } else {
  407. CommonHelper.showNoConnection(in: self)
  408. }
  409. }
  410. private func hideNotif() {
  411. notifContainer.hide()
  412. notifBg.hide()
  413. lblNotif.text = ""
  414. }
  415. private func setMainMenu() {
  416. let flowLayout = UICollectionViewFlowLayout()
  417. flowLayout.sectionInset = .init(top: 0, left: 16, bottom: 0, right: 16)
  418. let itemW = (UIScreen.main.bounds.width - 32) / 4.0
  419. flowLayout.itemSize = CGSize(width: itemW, height: 86.0)
  420. flowLayout.minimumInteritemSpacing = 0
  421. flowLayout.minimumLineSpacing = 0
  422. mainMenuCV.collectionViewLayout = flowLayout
  423. mainMenuCV.delegate = self
  424. mainMenuCV.dataSource = self
  425. mainMenuCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuUtamaCellId)
  426. }
  427. private func setNewsView() {
  428. homeNewsTV.delegate = self
  429. homeNewsTV.dataSource = self
  430. let footer = UIView()
  431. footer.backgroundColor = #colorLiteral(red: 0.9814968705, green: 0.9760531783, blue: 1, alpha: 1)
  432. homeNewsTV.tableFooterView = footer
  433. if ConnectionHelper.isConnectedToNetwork() {
  434. self.presenter.loadNews(cursor: 5, prev: 1, jenis: "", columns: "")
  435. } else {
  436. CommonHelper.showNoConnection(in: self)
  437. }
  438. }
  439. private func setSlideImageView() {
  440. if ConnectionHelper.isConnectedToNetwork() {
  441. self.presenter.loadSlideshowImages()
  442. } else {
  443. CommonHelper.showNoConnection(in: self)
  444. }
  445. }
  446. private func showMoreMenu() {
  447. if !loading {
  448. UIView.animate(withDuration: showMoreMenuDuration, delay: 0, options: [.curveEaseOut], animations: {
  449. self.moreMenuShown = true
  450. self.moreMenuLayout.show()
  451. self.moreMenuFrame = self.moreMenuLayout.frame
  452. self.moreMenuLayout.frame = .init(x: 0, y: self.headerLayout.frame.height, width: self.moreMenuFrame!.size.width, height: self.moreMenuFrame!.size.height)
  453. })
  454. }
  455. }
  456. private func hideMoreMenu() {
  457. self.moreMenuShown = false
  458. self.moreMenuLayout.hide()
  459. self.moreMenuFrame = self.moreMenuLayout.frame
  460. self.moreMenuLayout.frame = .init(x: 0, y: view.frame.height, width: self.moreMenuFrame!.size.width, height: self.moreMenuFrame!.size.height)
  461. }
  462. private func clearMoreMenu() {
  463. moreMenuAplikasiODSTitleLayout.hide()
  464. moreMenuOdsNotif.hide()
  465. moreMenuAplikasiODSCV.hide()
  466. marginMoreMenuAplikasiODS.hide()
  467. moreMenuFotoLabelTitleLayout.hide()
  468. moreMenuFotoLabelNotif.hide()
  469. moreMenuFotoLabelCV.hide()
  470. marginMoreMenuFotoLabel.hide()
  471. moreMenuAplikasiTitleLayout.hide()
  472. moreMenuAplikasiNotif.hide()
  473. moreMenuAplikasiCV.hide()
  474. marginMoreMenuAplikasi.hide()
  475. moreMenuSP2SertifikatTitleLayout.hide()
  476. moreMenuSP2SertifikatNotif.hide()
  477. moreMenuSP2SertifikatCV.hide()
  478. marginMoreMenuSP2Sertifikat.hide()
  479. moreMenuSP2TambahanTItleLayout.hide()
  480. moreMenuSP2TambahanNotif.hide()
  481. moreMenuSP2TambahanCV.hide()
  482. marginMoreMenuSP2Tambahan.hide()
  483. moreMenuDaftarRHUTitleLayout.hide()
  484. moreMenuDaftarRhuNotif.hide()
  485. moreMenuDaftarRHUCV.hide()
  486. marginMoreMenuDaftarRHU.hide()
  487. moreMenuSertifikatTitleLayout.hide()
  488. moreMenuSertifikatNotif.hide()
  489. moreMenuSertifikatCV.hide()
  490. marginMoreMenuSertifikat.hide()
  491. moreMenuSurveyTitleLayout.hide()
  492. moreMenuSurveyNotif.hide()
  493. moreMenuSurveyCV.hide()
  494. marginMoreMenuSurvey.hide()
  495. }
  496. private func clearMoreMenuNotifData() {
  497. moreMenuOdsNotif.hide()
  498. moreMenuFotoLabelNotif.hide()
  499. moreMenuAplikasiNotif.hide()
  500. moreMenuSP2SertifikatNotif.hide()
  501. moreMenuSP2TambahanNotif.hide()
  502. moreMenuDaftarRhuNotif.hide()
  503. moreMenuSertifikatNotif.hide()
  504. moreMenuSurveyNotif.hide()
  505. for i in 0..<listMenuAplikasiODS.count {
  506. listMenuAplikasiODS[i].totalNotif = 0
  507. }
  508. for i in 0..<listMenuFotoLabel.count {
  509. listMenuFotoLabel[i].totalNotif = 0
  510. }
  511. for i in 0..<listMenuAplikasi.count {
  512. listMenuAplikasi[i].totalNotif = 0
  513. }
  514. for i in 0..<listMenuSP2Sertifikat.count {
  515. listMenuSP2Sertifikat[i].totalNotif = 0
  516. }
  517. for i in 0..<listMenuSP2Tambahan.count {
  518. listMenuSP2Tambahan[i].totalNotif = 0
  519. }
  520. for i in 0..<listMenuDaftarRHU.count {
  521. listMenuDaftarRHU[i].totalNotif = 0
  522. }
  523. for i in 0..<listMenuSertifikat.count {
  524. listMenuSertifikat[i].totalNotif = 0
  525. }
  526. for i in 0..<listMenuSurvey.count {
  527. listMenuSurvey[i].totalNotif = 0
  528. }
  529. moreMenuAplikasiODSCV.reloadData()
  530. moreMenuFotoLabelCV.reloadData()
  531. moreMenuAplikasiCV.reloadData()
  532. moreMenuSP2SertifikatCV.reloadData()
  533. moreMenuSP2TambahanCV.reloadData()
  534. moreMenuDaftarRHUCV.reloadData()
  535. moreMenuSertifikatCV.reloadData()
  536. moreMenuSurveyCV.reloadData()
  537. }
  538. private func setMoreMainMenu() {
  539. let flowLayout = UICollectionViewFlowLayout()
  540. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  541. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  542. flowLayout.minimumInteritemSpacing = 0
  543. flowLayout.minimumLineSpacing = 0
  544. moreMenuUtamaCV.collectionViewLayout = flowLayout
  545. moreMenuUtamaCV.delegate = self
  546. moreMenuUtamaCV.dataSource = self
  547. moreMenuUtamaCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId)
  548. }
  549. private func setMoreMenuAplikasiODS(userRoleId: String) {
  550. // notif
  551. moreMenuOdsNotif.layer.cornerRadius = 5
  552. // menus
  553. let flowLayout = UICollectionViewFlowLayout()
  554. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  555. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  556. flowLayout.minimumInteritemSpacing = 0
  557. flowLayout.minimumLineSpacing = 0
  558. moreMenuAplikasiODSCV.collectionViewLayout = flowLayout
  559. moreMenuAplikasiODSCV.delegate = self
  560. moreMenuAplikasiODSCV.dataSource = self
  561. moreMenuAplikasiODSCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId)
  562. listMenuAplikasiODS = MenuListData.instance.getMenuAplikasiOdsData(userRoleId: userRoleId)
  563. if listMenuAplikasiODS.count > 0 {
  564. moreMenuAplikasiODSCV.reloadData()
  565. moreMenuAplikasiODSTitleLayout.show()
  566. moreMenuAplikasiODSCV.show()
  567. marginMoreMenuAplikasiODS.show()
  568. }
  569. }
  570. private func setMoreMenuFotoLabel(userRoleId: String) {
  571. // notif
  572. moreMenuFotoLabelNotif.layer.cornerRadius = 5
  573. // menus
  574. let flowLayout = UICollectionViewFlowLayout()
  575. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  576. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  577. flowLayout.minimumInteritemSpacing = 0
  578. flowLayout.minimumLineSpacing = 0
  579. moreMenuFotoLabelCV.collectionViewLayout = flowLayout
  580. moreMenuFotoLabelCV.delegate = self
  581. moreMenuFotoLabelCV.dataSource = self
  582. moreMenuFotoLabelCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuFotoLabelCellId)
  583. listMenuFotoLabel = MenuListData.instance.getMenuFotoLabelData(userRoleId: userRoleId)
  584. if listMenuFotoLabel.count > 0 {
  585. moreMenuFotoLabelCV.reloadData()
  586. moreMenuFotoLabelTitleLayout.show()
  587. moreMenuFotoLabelCV.show()
  588. marginMoreMenuFotoLabel.show()
  589. }
  590. }
  591. private func setMoreMenuAplikasi(userRoleId: String) {
  592. // notif
  593. moreMenuAplikasiNotif.layer.cornerRadius = 5
  594. // menus
  595. let flowLayout = UICollectionViewFlowLayout()
  596. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  597. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  598. flowLayout.minimumInteritemSpacing = 0
  599. flowLayout.minimumLineSpacing = 0
  600. moreMenuAplikasiCV.collectionViewLayout = flowLayout
  601. moreMenuAplikasiCV.delegate = self
  602. moreMenuAplikasiCV.dataSource = self
  603. moreMenuAplikasiCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuAplikasiCellId)
  604. listMenuAplikasi = MenuListData.instance.getMenuAplikasiData(userRoleId: userRoleId)
  605. if listMenuAplikasi.count > 0 {
  606. moreMenuAplikasiCV.reloadData()
  607. moreMenuAplikasiTitleLayout.show()
  608. moreMenuAplikasiCV.show()
  609. marginMoreMenuAplikasi.show()
  610. }
  611. }
  612. private func setMoreMenuSP2Sertifikat(userRoleId: String) {
  613. // notif
  614. moreMenuSP2SertifikatNotif.layer.cornerRadius = 5
  615. // menus
  616. let flowLayout = UICollectionViewFlowLayout()
  617. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  618. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  619. flowLayout.minimumInteritemSpacing = 0
  620. flowLayout.minimumLineSpacing = 0
  621. moreMenuSP2SertifikatCV.collectionViewLayout = flowLayout
  622. moreMenuSP2SertifikatCV.delegate = self
  623. moreMenuSP2SertifikatCV.dataSource = self
  624. moreMenuSP2SertifikatCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId)
  625. listMenuSP2Sertifikat = MenuListData.instance.getMenuSP2SertifikatData(userRoleId: userRoleId)
  626. if listMenuSP2Sertifikat.count > 0 {
  627. moreMenuSP2SertifikatCV.reloadData()
  628. moreMenuSP2SertifikatTitleLayout.show()
  629. moreMenuSP2SertifikatCV.show()
  630. marginMoreMenuSP2Sertifikat.show()
  631. }
  632. }
  633. private func setMoreMenuSP2Tambahan(userRoleId: String) {
  634. // notif
  635. moreMenuSP2TambahanNotif.layer.cornerRadius = 5
  636. // menus
  637. let flowLayout = UICollectionViewFlowLayout()
  638. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  639. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  640. flowLayout.minimumInteritemSpacing = 0
  641. flowLayout.minimumLineSpacing = 0
  642. moreMenuSP2TambahanCV.collectionViewLayout = flowLayout
  643. moreMenuSP2TambahanCV.delegate = self
  644. moreMenuSP2TambahanCV.dataSource = self
  645. moreMenuSP2TambahanCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId)
  646. listMenuSP2Tambahan = MenuListData.instance.getMenuSP2TambahanData(userRoleId: userRoleId)
  647. if listMenuSP2Tambahan.count > 0 {
  648. moreMenuSP2TambahanCV.reloadData()
  649. moreMenuSP2TambahanTItleLayout.show()
  650. moreMenuSP2TambahanCV.show()
  651. marginMoreMenuSP2Tambahan.show()
  652. }
  653. }
  654. private func setMoreMenuDaftarRHU(userRoleId: String) {
  655. // notif
  656. moreMenuDaftarRhuNotif.layer.cornerRadius = 5
  657. // menus
  658. let flowLayout = UICollectionViewFlowLayout()
  659. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  660. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  661. flowLayout.minimumInteritemSpacing = 0
  662. flowLayout.minimumLineSpacing = 0
  663. moreMenuDaftarRHUCV.collectionViewLayout = flowLayout
  664. moreMenuDaftarRHUCV.delegate = self
  665. moreMenuDaftarRHUCV.dataSource = self
  666. moreMenuDaftarRHUCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId)
  667. listMenuDaftarRHU = MenuListData.instance.getMenuDaftarRhuData(userRoleId: userRoleId)
  668. if listMenuDaftarRHU.count > 0 {
  669. moreMenuDaftarRHUCV.reloadData()
  670. moreMenuDaftarRHUTitleLayout.show()
  671. moreMenuDaftarRHUCV.show()
  672. marginMoreMenuDaftarRHU.show()
  673. }
  674. }
  675. private func setMoreMenuSertifikat(userRoleId: String) {
  676. // notif
  677. moreMenuSertifikatNotif.layer.cornerRadius = 5
  678. // menus
  679. let flowLayout = UICollectionViewFlowLayout()
  680. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  681. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  682. flowLayout.minimumInteritemSpacing = 0
  683. flowLayout.minimumLineSpacing = 0
  684. moreMenuSertifikatCV.collectionViewLayout = flowLayout
  685. moreMenuSertifikatCV.delegate = self
  686. moreMenuSertifikatCV.dataSource = self
  687. moreMenuSertifikatCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSertifikatCellId)
  688. listMenuSertifikat = MenuListData.instance.getMenuSertifikatData(userRoleId: userRoleId)
  689. if listMenuSertifikat.count > 0 {
  690. moreMenuSertifikatCV.reloadData()
  691. moreMenuSertifikatTitleLayout.show()
  692. moreMenuSertifikatCV.show()
  693. marginMoreMenuSertifikat.show()
  694. }
  695. }
  696. private func setMoreMenuSurvey(userRoleId: String) {
  697. // notif
  698. moreMenuSurveyNotif.layer.cornerRadius = 5
  699. // menus
  700. let flowLayout = UICollectionViewFlowLayout()
  701. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  702. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  703. flowLayout.minimumInteritemSpacing = 0
  704. flowLayout.minimumLineSpacing = 0
  705. moreMenuSurveyCV.collectionViewLayout = flowLayout
  706. moreMenuSurveyCV.delegate = self
  707. moreMenuSurveyCV.dataSource = self
  708. moreMenuSurveyCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSurveyCellId)
  709. listMenuSurvey = MenuListData.instance.getMenuSurveyData(userRoleId: userRoleId)
  710. if listMenuSurvey.count > 0 {
  711. moreMenuSurveyCV.reloadData()
  712. moreMenuSurveyTitleLayout.show()
  713. moreMenuSurveyCV.show()
  714. marginMoreMenuSurvey.show()
  715. }
  716. }
  717. private func setMoreMenuUtamaNew(userRoleId: String) {
  718. // notif
  719. moreMenuNewNotif.layer.cornerRadius = 5
  720. // menus
  721. let flowLayout = UICollectionViewFlowLayout()
  722. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  723. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  724. flowLayout.minimumInteritemSpacing = 0
  725. flowLayout.minimumLineSpacing = 0
  726. moreMenuUtamaNewCV.collectionViewLayout = flowLayout
  727. moreMenuUtamaNewCV.delegate = self
  728. moreMenuUtamaNewCV.dataSource = self
  729. moreMenuUtamaNewCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuUtamaCellNewId)
  730. listMenuUtamaNew = MenuListData.instance.getMenuUtamaNewData(userRoleId: userRoleId)
  731. if listMenuUtamaNew.count > 0 {
  732. moreMenuUtamaNewCV.reloadData()
  733. moreMenuNewTitleLayout.show()
  734. moreMenuUtamaNewCV.show()
  735. marginMoreMenuUtamaNew.show()
  736. }
  737. }
  738. // IB Actions
  739. @IBAction func unwindToHome(segue: UIStoryboardSegue) {}
  740. @IBAction func onBtnMoreMenuTapped(_ sender: Any) {
  741. self.showMoreMenu()
  742. if !loading {
  743. let userRoleId = UserState.instance.getRoleId()
  744. if !userRoleId.isEmpty {
  745. clearMoreMenuNotifData()
  746. if ConnectionHelper.isConnectedToNetwork() {
  747. self.presenter.loadMenuNotifications()
  748. } else {
  749. CommonHelper.showNoConnection(in: self)
  750. }
  751. }
  752. }
  753. }
  754. @IBAction func dismissMoreMenuLayout(_ sender: Any) {
  755. self.hideMoreMenu()
  756. }
  757. @IBAction func onBtnMoreNewsTap(_ sender: Any) {
  758. if !loading {
  759. performSegue(withIdentifier: "NewsSegueId", sender: self)
  760. }
  761. }
  762. @objc func openNotifList(sender : UITapGestureRecognizer) {
  763. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  764. }
  765. public func openNotifListPage() {
  766. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  767. }
  768. }
  769. // HomeViewDelegate
  770. extension HomeVC: HomeViewDelegate {
  771. func showLoading() {
  772. loading = true
  773. progress.startAnimating()
  774. progressLayout.show()
  775. }
  776. func hideLoading() {
  777. loading = false
  778. progress.stopAnimating()
  779. progressLayout.hide()
  780. }
  781. func setTotalUnreadNotif(totalUnreadNotif: Int) {
  782. if totalUnreadNotif > 0 {
  783. lblNotif.text = String(totalUnreadNotif)
  784. notifBg.show()
  785. headerNotifBadge.isHidden = false
  786. headerNotifBadgeLabel.text = String(totalUnreadNotif)
  787. } else {
  788. lblNotif.text = ""
  789. notifBg.hide()
  790. headerNotifBadge.isHidden = true
  791. headerNotifBadgeLabel.text = ""
  792. }
  793. }
  794. func setSlideshowImages(images: [String]) {
  795. if !images.isEmpty {
  796. var sources = [SDWebImageSource]()
  797. for url in images {
  798. if let encodedURLString = url.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed),
  799. let webpSource = SDWebImageSource(urlString: encodedURLString) {
  800. sources.append(webpSource)
  801. }
  802. }
  803. self.slideshow.slideshowInterval = 2.0
  804. self.slideshow.pageIndicatorPosition = .init(horizontal: .center, vertical: .under)
  805. self.slideshow.contentScaleMode = UIView.ContentMode.scaleAspectFill
  806. let pageControl = UIPageControl()
  807. pageControl.currentPageIndicatorTintColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
  808. pageControl.pageIndicatorTintColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
  809. self.slideshow.pageIndicator = pageControl
  810. self.slideshow.setImageInputs(sources)
  811. }
  812. }
  813. func setNews(listNews: [News]) {
  814. if listNews.count > 0 {
  815. homeNewsTV.beginUpdates()
  816. for news in listNews {
  817. self.listNews.append(news)
  818. homeNewsTV.insertRows(
  819. at: [IndexPath(row: self.listNews.count-1, section: 0)],
  820. with: .automatic
  821. )
  822. }
  823. homeNewsTV.endUpdates()
  824. homeNewsTV.reloadData()
  825. }
  826. }
  827. func setMenuNotifications(menuNotification: MenuNotification) {
  828. let userRoleId = UserState.instance.getRoleId()
  829. if userRoleId == CUSTOMER_ROLE_ID {
  830. if listMenuSP2Sertifikat.count > 0 {
  831. // total notif
  832. let totalNotif = menuNotification.tot_sp2_sertifikat
  833. if (totalNotif > 0) {
  834. lblMoreMenuSP2SertifikatNotif.text = "\(totalNotif)"
  835. moreMenuSP2SertifikatNotif.show()
  836. } else {
  837. moreMenuSP2SertifikatNotif.hide()
  838. }
  839. // sp2 sertifikat
  840. listMenuSP2Sertifikat[0].totalNotif = menuNotification.tot_sp2_sertifikat
  841. moreMenuSP2SertifikatCV.reloadData()
  842. }
  843. if listMenuSP2Tambahan.count > 0 {
  844. // total notif
  845. let tot_ods = menuNotification.tot_sp2_tambahan
  846. if (tot_ods > 0) {
  847. lblMoreMenuSP2TambahanNotif.text = "\(tot_ods)"
  848. moreMenuSP2TambahanNotif.show()
  849. } else {
  850. moreMenuSP2TambahanNotif.hide()
  851. }
  852. // sp2 tambahan
  853. listMenuSP2Tambahan[0].totalNotif = menuNotification.tot_sp2_tambahan
  854. moreMenuSP2TambahanCV.reloadData()
  855. }
  856. if listMenuSertifikat.count > 0 {
  857. // total
  858. let tot_ods = menuNotification.tot_sertifikat
  859. if (tot_ods > 0) {
  860. lblMoreMenuSertifikatNotif.text = "\(tot_ods)"
  861. moreMenuSertifikatNotif.show()
  862. } else {
  863. moreMenuSertifikatNotif.hide()
  864. }
  865. // sert sementara
  866. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  867. // sert berlaku
  868. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  869. moreMenuSertifikatCV.reloadData()
  870. }
  871. } else if userRoleId == OPERATOR_ROLE_ID {
  872. if listMenuAplikasiODS.count > 0 {
  873. // total notif
  874. let totalNotif = menuNotification.tot_ods
  875. if (totalNotif > 0) {
  876. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  877. moreMenuOdsNotif.show()
  878. } else {
  879. moreMenuOdsNotif.hide()
  880. }
  881. // ods sp2 baru
  882. listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2baru
  883. // ods sp2 otirisasi
  884. listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  885. moreMenuAplikasiODSCV.reloadData()
  886. }
  887. if listMenuSertifikat.count > 0 {
  888. // total notif
  889. let totalNotif = menuNotification.tot_sertifikat
  890. if (totalNotif > 0) {
  891. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  892. moreMenuSertifikatNotif.show()
  893. } else {
  894. moreMenuSertifikatNotif.hide()
  895. }
  896. // sert sementara
  897. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  898. // sert berlaku
  899. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  900. moreMenuSertifikatCV.reloadData()
  901. }
  902. } else if userRoleId == KEPALA_SEKSI_ROLE_ID {
  903. if listMenuAplikasiODS.count > 0 {
  904. // total notif
  905. let totalNotif = menuNotification.tot_ods
  906. if (totalNotif > 0) {
  907. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  908. moreMenuOdsNotif.show()
  909. } else {
  910. moreMenuOdsNotif.hide()
  911. }
  912. // ods sp2 otorisasi
  913. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  914. //sp2 before
  915. listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2before
  916. //sp2 after
  917. listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2after
  918. moreMenuAplikasiODSCV.reloadData()
  919. }
  920. if listMenuSertifikat.count > 0 {
  921. // total notif
  922. let totalNotif = menuNotification.tot_sertifikat
  923. if (totalNotif > 0) {
  924. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  925. moreMenuSertifikatNotif.show()
  926. } else {
  927. moreMenuSertifikatNotif.hide()
  928. }
  929. // sert sementara
  930. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  931. // sert berlaku
  932. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  933. moreMenuSertifikatCV.reloadData()
  934. }
  935. } else if userRoleId == KEPALA_SUB_DIREKTORAT_ROLE_ID {
  936. if listMenuAplikasiODS.count > 0 {
  937. // total notif
  938. let totalNotif = menuNotification.tot_ods
  939. if (totalNotif > 0) {
  940. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  941. moreMenuOdsNotif.show()
  942. } else {
  943. moreMenuOdsNotif.hide()
  944. }
  945. // ods sp2 otorisasi
  946. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  947. moreMenuAplikasiODSCV.reloadData()
  948. }
  949. if listMenuSertifikat.count > 0 {
  950. // total notif
  951. let totalNotif = menuNotification.tot_sertifikat
  952. if (totalNotif > 0) {
  953. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  954. moreMenuSertifikatNotif.show()
  955. } else {
  956. moreMenuSertifikatNotif.hide()
  957. }
  958. // sert sementara
  959. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  960. // sert berlaku
  961. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  962. moreMenuSertifikatCV.reloadData()
  963. }
  964. } else if userRoleId == DIREKTUR_ROLE_ID {
  965. if listMenuAplikasiODS.count > 0 {
  966. // total notif
  967. let totalNotif = menuNotification.tot_ods
  968. if (totalNotif > 0) {
  969. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  970. moreMenuOdsNotif.show()
  971. } else {
  972. moreMenuOdsNotif.hide()
  973. }
  974. // ods sp2 otorisasi
  975. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  976. moreMenuAplikasiODSCV.reloadData()
  977. }
  978. if listMenuSertifikat.count > 0 {
  979. // total notif
  980. let totalNotif = menuNotification.tot_sertifikat
  981. if (totalNotif > 0) {
  982. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  983. moreMenuSertifikatNotif.show()
  984. } else {
  985. moreMenuSertifikatNotif.hide()
  986. }
  987. // sert sementara
  988. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  989. // sert berlaku
  990. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  991. moreMenuSertifikatCV.reloadData()
  992. }
  993. }
  994. }
  995. }
  996. // CollectionView functions
  997. extension HomeVC : UICollectionViewDelegate, UICollectionViewDataSource {
  998. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  999. if collectionView == self.moreMenuUtamaNewCV {
  1000. return listMenuUtamaNew.count
  1001. }
  1002. else if collectionView == self.mainMenuCV {
  1003. return listMenuUtama.count
  1004. } else if collectionView == self.moreMenuUtamaCV {
  1005. return listMenuUtama.count
  1006. } else if collectionView == self.moreMenuAplikasiODSCV {
  1007. return listMenuAplikasiODS.count
  1008. } else if collectionView == self.moreMenuFotoLabelCV {
  1009. return listMenuFotoLabel.count
  1010. } else if collectionView == self.moreMenuAplikasiCV {
  1011. return listMenuAplikasi.count
  1012. } else if collectionView == self.moreMenuSP2SertifikatCV {
  1013. return listMenuSP2Sertifikat.count
  1014. } else if collectionView == self.moreMenuSP2TambahanCV {
  1015. return listMenuSP2Tambahan.count
  1016. } else if collectionView == self.moreMenuDaftarRHUCV {
  1017. return listMenuDaftarRHU.count
  1018. } else if collectionView == self.moreMenuSertifikatCV {
  1019. return listMenuSertifikat.count
  1020. } else if collectionView == self.moreMenuSurveyCV {
  1021. return listMenuSurvey.count
  1022. } else {
  1023. return 0
  1024. }
  1025. }
  1026. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  1027. if collectionView == self.moreMenuUtamaNewCV {
  1028. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellNewId, for: indexPath) as? MenuCell {
  1029. let menu = listMenuUtamaNew[indexPath.row]
  1030. cell.updateViews(menu: menu)
  1031. return cell
  1032. } else {
  1033. return MenuCell()
  1034. }
  1035. } else if collectionView == self.mainMenuCV {
  1036. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellId, for: indexPath) as? MenuCell {
  1037. let menu = listMenuUtama[indexPath.row]
  1038. cell.updateViews(menu: menu)
  1039. return cell
  1040. } else {
  1041. return MenuCell()
  1042. }
  1043. } else if collectionView == self.moreMenuUtamaCV {
  1044. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId, for: indexPath) as? MenuCell {
  1045. let menu = listMenuUtama[indexPath.row]
  1046. cell.updateViews(menu: menu)
  1047. return cell
  1048. } else {
  1049. return MenuCell()
  1050. }
  1051. } else if collectionView == self.moreMenuAplikasiODSCV {
  1052. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId, for: indexPath) as? MenuCell {
  1053. let menu = listMenuAplikasiODS[indexPath.row]
  1054. cell.updateViews(menu: menu)
  1055. return cell
  1056. } else {
  1057. return MenuCell()
  1058. }
  1059. } else if collectionView == self.moreMenuFotoLabelCV {
  1060. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuFotoLabelCellId, for: indexPath) as? MenuCell {
  1061. let menu = listMenuFotoLabel[indexPath.row]
  1062. cell.updateViews(menu: menu)
  1063. return cell
  1064. } else {
  1065. return MenuCell()
  1066. }
  1067. } else if collectionView == self.moreMenuAplikasiCV {
  1068. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiCellId, for: indexPath) as? MenuCell {
  1069. let menu = listMenuAplikasi[indexPath.row]
  1070. cell.updateViews(menu: menu)
  1071. return cell
  1072. } else {
  1073. return MenuCell()
  1074. }
  1075. } else if collectionView == self.moreMenuSP2SertifikatCV {
  1076. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId, for: indexPath) as? MenuCell {
  1077. let menu = listMenuSP2Sertifikat[indexPath.row]
  1078. cell.updateViews(menu: menu)
  1079. return cell
  1080. } else {
  1081. return MenuCell()
  1082. }
  1083. } else if collectionView == self.moreMenuSP2TambahanCV {
  1084. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId, for: indexPath) as? MenuCell {
  1085. let menu = listMenuSP2Tambahan[indexPath.row]
  1086. cell.updateViews(menu: menu)
  1087. return cell
  1088. } else {
  1089. return MenuCell()
  1090. }
  1091. } else if collectionView == self.moreMenuDaftarRHUCV {
  1092. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId, for: indexPath) as? MenuCell {
  1093. let menu = listMenuDaftarRHU[indexPath.row]
  1094. cell.updateViews(menu: menu)
  1095. return cell
  1096. } else {
  1097. return MenuCell()
  1098. }
  1099. } else if collectionView == self.moreMenuSertifikatCV {
  1100. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSertifikatCellId, for: indexPath) as? MenuCell {
  1101. let menu = listMenuSertifikat[indexPath.row]
  1102. cell.updateViews(menu: menu)
  1103. return cell
  1104. } else {
  1105. return MenuCell()
  1106. }
  1107. } else if collectionView == self.moreMenuSurveyCV {
  1108. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSurveyCellId, for: indexPath) as? MenuCell {
  1109. let menu = listMenuSurvey[indexPath.row]
  1110. cell.updateViews(menu: menu)
  1111. return cell
  1112. } else {
  1113. return MenuCell()
  1114. }
  1115. } else {
  1116. return MenuCell()
  1117. }
  1118. }
  1119. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  1120. var segueId = ""
  1121. if collectionView == self.moreMenuUtamaNewCV {
  1122. segueId = listMenuUtamaNew[indexPath.row].segueId
  1123. } else if collectionView == self.mainMenuCV {
  1124. segueId = listMenuUtama[indexPath.row].segueId
  1125. } else if collectionView == self.moreMenuUtamaCV {
  1126. segueId = listMenuUtama[indexPath.row].segueId
  1127. } else if collectionView == self.moreMenuAplikasiODSCV {
  1128. segueId = listMenuAplikasiODS[indexPath.row].segueId
  1129. } else if collectionView == self.moreMenuFotoLabelCV {
  1130. segueId = listMenuFotoLabel[indexPath.row].segueId
  1131. } else if collectionView == self.moreMenuAplikasiCV {
  1132. segueId = listMenuAplikasi[indexPath.row].segueId
  1133. } else if collectionView == self.moreMenuSP2SertifikatCV {
  1134. segueId = listMenuSP2Sertifikat[indexPath.row].segueId
  1135. } else if collectionView == self.moreMenuSP2TambahanCV {
  1136. segueId = listMenuSP2Tambahan[indexPath.row].segueId
  1137. } else if collectionView == self.moreMenuDaftarRHUCV {
  1138. segueId = listMenuDaftarRHU[indexPath.row].segueId
  1139. } else if collectionView == self.moreMenuSertifikatCV {
  1140. segueId = listMenuSertifikat[indexPath.row].segueId
  1141. } else if collectionView == self.moreMenuSurveyCV {
  1142. segueId = listMenuSurvey[indexPath.row].segueId
  1143. }
  1144. if !segueId.isEmpty {
  1145. if !loading {
  1146. performSegue(withIdentifier: segueId, sender: self)
  1147. }
  1148. }
  1149. }
  1150. }
  1151. // UITableController Protocols
  1152. extension HomeVC: UITableViewDelegate, UITableViewDataSource {
  1153. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  1154. return listNews.count
  1155. }
  1156. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  1157. if tableView == homeNewsTV {
  1158. if let cell = tableView.dequeueReusableCell(withIdentifier: homeNewsCellId, for: indexPath) as? HomeNewsCell {
  1159. let news = listNews[indexPath.row]
  1160. cell.updateViews(news: news)
  1161. return cell
  1162. } else {
  1163. return HomeNewsCell()
  1164. }
  1165. } else {
  1166. return HomeNewsCell()
  1167. }
  1168. }
  1169. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  1170. let selectedNews = self.listNews[indexPath.row]
  1171. self.selectedNewsId = selectedNews.id
  1172. self.date = selectedNews.dateNew()
  1173. self.judul = selectedNews.title_news
  1174. self.urlThumb = selectedNews.thumb_filename
  1175. performSegue(withIdentifier: "homeToNewsDetailSegueId", sender: self)
  1176. }
  1177. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  1178. return 140
  1179. }
  1180. }