HomeVC.swift 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084
  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. // View Lifecycles
  107. override var preferredStatusBarStyle: UIStatusBarStyle {
  108. return .lightContent
  109. }
  110. override func viewWillAppear(_ animated: Bool) {
  111. AppUtility.lockOrientation(.portrait)
  112. btnMoreMenu.layer.cornerRadius = 5
  113. btnMoreNews.layer.cornerRadius = 5
  114. moreMenuFrame = moreMenuLayout.frame
  115. moreMenuLayout.frame = .init(
  116. x: 0,
  117. y: view.frame.height,
  118. width: moreMenuFrame!.size.width,
  119. height: moreMenuFrame!.size.height
  120. )
  121. let gesture = UITapGestureRecognizer(target: self, action: #selector(self.openNotifList))
  122. notifContainer.addGestureRecognizer(gesture)
  123. userRoleId = UserState.instance.getRoleId()
  124. let userId = UserState.instance.getUserId()
  125. let custId = UserState.instance.getCustId()
  126. print("userRoleId")
  127. print(userRoleId)
  128. print(userId)
  129. print(custId)
  130. if !userRoleId.isEmpty {
  131. showNotif()
  132. } else {
  133. hideNotif()
  134. }
  135. }
  136. override func viewDidLoad() {
  137. super.viewDidLoad()
  138. presenter.attachView(view: self)
  139. presenter.loadSlideshowImages()
  140. if openNotif {
  141. print("SSSSSS")
  142. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  143. }
  144. setMainMenu()
  145. setNewsView()
  146. setMoreMainMenu()
  147. userRoleId = UserState.instance.getRoleId()
  148. if !userRoleId.isEmpty {
  149. setMoreMenuUtamaNew(userRoleId: userRoleId)
  150. setMoreMenuAplikasiODS(userRoleId: userRoleId)
  151. setMoreMenuFotoLabel(userRoleId: userRoleId)
  152. setMoreMenuAplikasi(userRoleId: userRoleId)
  153. setMoreMenuSP2Sertifikat(userRoleId: userRoleId)
  154. setMoreMenuSP2Tambahan(userRoleId: userRoleId)
  155. setMoreMenuDaftarRHU(userRoleId: userRoleId)
  156. setMoreMenuSertifikat(userRoleId: userRoleId)
  157. setMoreMenuSurvey(userRoleId: userRoleId)
  158. showNotif()
  159. } else {
  160. hideNotif()
  161. }
  162. }
  163. override func viewDidAppear(_ animated: Bool) {
  164. presenter.attachView(view: self)
  165. if openNotif {
  166. print("VVVVVV")
  167. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  168. }
  169. if moreMenuShown {
  170. showMoreMenu()
  171. }
  172. // let roleId = UserState.instance.getRoleId()
  173. // if (userRoleId != roleId) {
  174. // userRoleId = roleId
  175. //
  176. if !userRoleId.isEmpty {
  177. clearMoreMenu()
  178. setMoreMenuUtamaNew(userRoleId: userRoleId)
  179. setMoreMenuAplikasiODS(userRoleId: userRoleId)
  180. setMoreMenuFotoLabel(userRoleId: userRoleId)
  181. setMoreMenuAplikasi(userRoleId: userRoleId)
  182. setMoreMenuSP2Sertifikat(userRoleId: userRoleId)
  183. setMoreMenuSP2Tambahan(userRoleId: userRoleId)
  184. setMoreMenuDaftarRHU(userRoleId: userRoleId)
  185. setMoreMenuSertifikat(userRoleId: userRoleId)
  186. setMoreMenuSurvey(userRoleId: userRoleId)
  187. clearMoreMenuNotifData()
  188. presenter.loadMenuNotifications()
  189. showNotif()
  190. } else {
  191. clearMoreMenu()
  192. clearMoreMenuNotifData()
  193. hideNotif()
  194. }
  195. // }
  196. }
  197. override func viewWillDisappear(_ animated: Bool) {
  198. AppUtility.lockOrientation(.all)
  199. }
  200. override func viewDidDisappear(_ animated: Bool) {
  201. presenter.detachView()
  202. }
  203. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  204. if let destVC = segue.destination as? NewsDetailVC {
  205. destVC.newsId = self.selectedNewsId
  206. destVC.date = self.date
  207. destVC.judul = self.judul
  208. destVC.urlThumb = self.urlThumb.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
  209. destVC.segueId = destVC.SEGUE_HOME_ID
  210. }
  211. }
  212. // private functions
  213. private func showNotif() {
  214. notifContainer.show()
  215. presenter.loadTotalUnreadNotif()
  216. }
  217. private func hideNotif() {
  218. notifContainer.hide()
  219. notifBg.hide()
  220. lblNotif.text = ""
  221. }
  222. private func setMainMenu() {
  223. let flowLayout = UICollectionViewFlowLayout()
  224. flowLayout.sectionInset = .init(top: 0, left: 8, bottom: 0, right: 8)
  225. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  226. flowLayout.minimumInteritemSpacing = 0
  227. flowLayout.minimumLineSpacing = 0
  228. mainMenuCV.collectionViewLayout = flowLayout
  229. mainMenuCV.delegate = self
  230. mainMenuCV.dataSource = self
  231. mainMenuCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuUtamaCellId)
  232. }
  233. private func setNewsView() {
  234. homeNewsTV.delegate = self
  235. homeNewsTV.dataSource = self
  236. let footer = UIView()
  237. footer.backgroundColor = #colorLiteral(red: 0.9814968705, green: 0.9760531783, blue: 1, alpha: 1)
  238. homeNewsTV.tableFooterView = footer
  239. presenter.loadNews(cursor: 5, prev: 1, jenis: "", columns: "")
  240. }
  241. private func showMoreMenu() {
  242. if !loading {
  243. UIView.animate(withDuration: showMoreMenuDuration, delay: 0, options: [.curveEaseOut], animations: {
  244. self.moreMenuShown = true
  245. self.moreMenuLayout.show()
  246. self.moreMenuFrame = self.moreMenuLayout.frame
  247. self.moreMenuLayout.frame = .init(x: 0, y: self.headerLayout.frame.height, width: self.moreMenuFrame!.size.width, height: self.moreMenuFrame!.size.height)
  248. })
  249. }
  250. }
  251. private func hideMoreMenu() {
  252. self.moreMenuShown = false
  253. self.moreMenuLayout.hide()
  254. self.moreMenuFrame = self.moreMenuLayout.frame
  255. self.moreMenuLayout.frame = .init(x: 0, y: view.frame.height, width: self.moreMenuFrame!.size.width, height: self.moreMenuFrame!.size.height)
  256. }
  257. private func clearMoreMenu() {
  258. moreMenuAplikasiODSTitleLayout.hide()
  259. moreMenuOdsNotif.hide()
  260. moreMenuAplikasiODSCV.hide()
  261. marginMoreMenuAplikasiODS.hide()
  262. moreMenuFotoLabelTitleLayout.hide()
  263. moreMenuFotoLabelNotif.hide()
  264. moreMenuFotoLabelCV.hide()
  265. marginMoreMenuFotoLabel.hide()
  266. moreMenuAplikasiTitleLayout.hide()
  267. moreMenuAplikasiNotif.hide()
  268. moreMenuAplikasiCV.hide()
  269. marginMoreMenuAplikasi.hide()
  270. moreMenuSP2SertifikatTitleLayout.hide()
  271. moreMenuSP2SertifikatNotif.hide()
  272. moreMenuSP2SertifikatCV.hide()
  273. marginMoreMenuSP2Sertifikat.hide()
  274. moreMenuSP2TambahanTItleLayout.hide()
  275. moreMenuSP2TambahanNotif.hide()
  276. moreMenuSP2TambahanCV.hide()
  277. marginMoreMenuSP2Tambahan.hide()
  278. moreMenuDaftarRHUTitleLayout.hide()
  279. moreMenuDaftarRhuNotif.hide()
  280. moreMenuDaftarRHUCV.hide()
  281. marginMoreMenuDaftarRHU.hide()
  282. moreMenuSertifikatTitleLayout.hide()
  283. moreMenuSertifikatNotif.hide()
  284. moreMenuSertifikatCV.hide()
  285. marginMoreMenuSertifikat.hide()
  286. moreMenuSurveyTitleLayout.hide()
  287. moreMenuSurveyNotif.hide()
  288. moreMenuSurveyCV.hide()
  289. marginMoreMenuSurvey.hide()
  290. }
  291. private func clearMoreMenuNotifData() {
  292. moreMenuOdsNotif.hide()
  293. moreMenuFotoLabelNotif.hide()
  294. moreMenuAplikasiNotif.hide()
  295. moreMenuSP2SertifikatNotif.hide()
  296. moreMenuSP2TambahanNotif.hide()
  297. moreMenuDaftarRhuNotif.hide()
  298. moreMenuSertifikatNotif.hide()
  299. moreMenuSurveyNotif.hide()
  300. for i in 0..<listMenuAplikasiODS.count {
  301. listMenuAplikasiODS[i].totalNotif = 0
  302. }
  303. for i in 0..<listMenuFotoLabel.count {
  304. listMenuFotoLabel[i].totalNotif = 0
  305. }
  306. for i in 0..<listMenuAplikasi.count {
  307. listMenuAplikasi[i].totalNotif = 0
  308. }
  309. for i in 0..<listMenuSP2Sertifikat.count {
  310. listMenuSP2Sertifikat[i].totalNotif = 0
  311. }
  312. for i in 0..<listMenuSP2Tambahan.count {
  313. listMenuSP2Tambahan[i].totalNotif = 0
  314. }
  315. for i in 0..<listMenuDaftarRHU.count {
  316. listMenuDaftarRHU[i].totalNotif = 0
  317. }
  318. for i in 0..<listMenuSertifikat.count {
  319. listMenuSertifikat[i].totalNotif = 0
  320. }
  321. for i in 0..<listMenuSurvey.count {
  322. listMenuSurvey[i].totalNotif = 0
  323. }
  324. moreMenuAplikasiODSCV.reloadData()
  325. moreMenuFotoLabelCV.reloadData()
  326. moreMenuAplikasiCV.reloadData()
  327. moreMenuSP2SertifikatCV.reloadData()
  328. moreMenuSP2TambahanCV.reloadData()
  329. moreMenuDaftarRHUCV.reloadData()
  330. moreMenuSertifikatCV.reloadData()
  331. moreMenuSurveyCV.reloadData()
  332. }
  333. private func setMoreMainMenu() {
  334. let flowLayout = UICollectionViewFlowLayout()
  335. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  336. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  337. flowLayout.minimumInteritemSpacing = 0
  338. flowLayout.minimumLineSpacing = 0
  339. moreMenuUtamaCV.collectionViewLayout = flowLayout
  340. moreMenuUtamaCV.delegate = self
  341. moreMenuUtamaCV.dataSource = self
  342. moreMenuUtamaCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId)
  343. }
  344. private func setMoreMenuAplikasiODS(userRoleId: String) {
  345. // notif
  346. moreMenuOdsNotif.layer.cornerRadius = 5
  347. // menus
  348. let flowLayout = UICollectionViewFlowLayout()
  349. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  350. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  351. flowLayout.minimumInteritemSpacing = 0
  352. flowLayout.minimumLineSpacing = 0
  353. moreMenuAplikasiODSCV.collectionViewLayout = flowLayout
  354. moreMenuAplikasiODSCV.delegate = self
  355. moreMenuAplikasiODSCV.dataSource = self
  356. moreMenuAplikasiODSCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId)
  357. listMenuAplikasiODS = MenuListData.instance.getMenuAplikasiOdsData(userRoleId: userRoleId)
  358. if listMenuAplikasiODS.count > 0 {
  359. moreMenuAplikasiODSCV.reloadData()
  360. moreMenuAplikasiODSTitleLayout.show()
  361. moreMenuAplikasiODSCV.show()
  362. marginMoreMenuAplikasiODS.show()
  363. }
  364. }
  365. private func setMoreMenuFotoLabel(userRoleId: String) {
  366. // notif
  367. moreMenuFotoLabelNotif.layer.cornerRadius = 5
  368. // menus
  369. let flowLayout = UICollectionViewFlowLayout()
  370. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  371. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  372. flowLayout.minimumInteritemSpacing = 0
  373. flowLayout.minimumLineSpacing = 0
  374. moreMenuFotoLabelCV.collectionViewLayout = flowLayout
  375. moreMenuFotoLabelCV.delegate = self
  376. moreMenuFotoLabelCV.dataSource = self
  377. moreMenuFotoLabelCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuFotoLabelCellId)
  378. listMenuFotoLabel = MenuListData.instance.getMenuFotoLabelData(userRoleId: userRoleId)
  379. if listMenuFotoLabel.count > 0 {
  380. moreMenuFotoLabelCV.reloadData()
  381. moreMenuFotoLabelTitleLayout.show()
  382. moreMenuFotoLabelCV.show()
  383. marginMoreMenuFotoLabel.show()
  384. }
  385. }
  386. private func setMoreMenuAplikasi(userRoleId: String) {
  387. // notif
  388. moreMenuAplikasiNotif.layer.cornerRadius = 5
  389. // menus
  390. let flowLayout = UICollectionViewFlowLayout()
  391. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  392. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  393. flowLayout.minimumInteritemSpacing = 0
  394. flowLayout.minimumLineSpacing = 0
  395. moreMenuAplikasiCV.collectionViewLayout = flowLayout
  396. moreMenuAplikasiCV.delegate = self
  397. moreMenuAplikasiCV.dataSource = self
  398. moreMenuAplikasiCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuAplikasiCellId)
  399. listMenuAplikasi = MenuListData.instance.getMenuAplikasiData(userRoleId: userRoleId)
  400. if listMenuAplikasi.count > 0 {
  401. moreMenuAplikasiCV.reloadData()
  402. moreMenuAplikasiTitleLayout.show()
  403. moreMenuAplikasiCV.show()
  404. marginMoreMenuAplikasi.show()
  405. }
  406. }
  407. private func setMoreMenuSP2Sertifikat(userRoleId: String) {
  408. // notif
  409. moreMenuSP2SertifikatNotif.layer.cornerRadius = 5
  410. // menus
  411. let flowLayout = UICollectionViewFlowLayout()
  412. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  413. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  414. flowLayout.minimumInteritemSpacing = 0
  415. flowLayout.minimumLineSpacing = 0
  416. moreMenuSP2SertifikatCV.collectionViewLayout = flowLayout
  417. moreMenuSP2SertifikatCV.delegate = self
  418. moreMenuSP2SertifikatCV.dataSource = self
  419. moreMenuSP2SertifikatCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId)
  420. listMenuSP2Sertifikat = MenuListData.instance.getMenuSP2SertifikatData(userRoleId: userRoleId)
  421. if listMenuSP2Sertifikat.count > 0 {
  422. moreMenuSP2SertifikatCV.reloadData()
  423. moreMenuSP2SertifikatTitleLayout.show()
  424. moreMenuSP2SertifikatCV.show()
  425. marginMoreMenuSP2Sertifikat.show()
  426. }
  427. }
  428. private func setMoreMenuSP2Tambahan(userRoleId: String) {
  429. // notif
  430. moreMenuSP2TambahanNotif.layer.cornerRadius = 5
  431. // menus
  432. let flowLayout = UICollectionViewFlowLayout()
  433. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  434. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  435. flowLayout.minimumInteritemSpacing = 0
  436. flowLayout.minimumLineSpacing = 0
  437. moreMenuSP2TambahanCV.collectionViewLayout = flowLayout
  438. moreMenuSP2TambahanCV.delegate = self
  439. moreMenuSP2TambahanCV.dataSource = self
  440. moreMenuSP2TambahanCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId)
  441. listMenuSP2Tambahan = MenuListData.instance.getMenuSP2TambahanData(userRoleId: userRoleId)
  442. if listMenuSP2Tambahan.count > 0 {
  443. moreMenuSP2TambahanCV.reloadData()
  444. moreMenuSP2TambahanTItleLayout.show()
  445. moreMenuSP2TambahanCV.show()
  446. marginMoreMenuSP2Tambahan.show()
  447. }
  448. }
  449. private func setMoreMenuDaftarRHU(userRoleId: String) {
  450. // notif
  451. moreMenuDaftarRhuNotif.layer.cornerRadius = 5
  452. // menus
  453. let flowLayout = UICollectionViewFlowLayout()
  454. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  455. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  456. flowLayout.minimumInteritemSpacing = 0
  457. flowLayout.minimumLineSpacing = 0
  458. moreMenuDaftarRHUCV.collectionViewLayout = flowLayout
  459. moreMenuDaftarRHUCV.delegate = self
  460. moreMenuDaftarRHUCV.dataSource = self
  461. moreMenuDaftarRHUCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId)
  462. listMenuDaftarRHU = MenuListData.instance.getMenuDaftarRhuData(userRoleId: userRoleId)
  463. if listMenuDaftarRHU.count > 0 {
  464. moreMenuDaftarRHUCV.reloadData()
  465. moreMenuDaftarRHUTitleLayout.show()
  466. moreMenuDaftarRHUCV.show()
  467. marginMoreMenuDaftarRHU.show()
  468. }
  469. }
  470. private func setMoreMenuSertifikat(userRoleId: String) {
  471. // notif
  472. moreMenuSertifikatNotif.layer.cornerRadius = 5
  473. // menus
  474. let flowLayout = UICollectionViewFlowLayout()
  475. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  476. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  477. flowLayout.minimumInteritemSpacing = 0
  478. flowLayout.minimumLineSpacing = 0
  479. moreMenuSertifikatCV.collectionViewLayout = flowLayout
  480. moreMenuSertifikatCV.delegate = self
  481. moreMenuSertifikatCV.dataSource = self
  482. moreMenuSertifikatCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSertifikatCellId)
  483. listMenuSertifikat = MenuListData.instance.getMenuSertifikatData(userRoleId: userRoleId)
  484. if listMenuSertifikat.count > 0 {
  485. moreMenuSertifikatCV.reloadData()
  486. moreMenuSertifikatTitleLayout.show()
  487. moreMenuSertifikatCV.show()
  488. marginMoreMenuSertifikat.show()
  489. }
  490. }
  491. private func setMoreMenuSurvey(userRoleId: String) {
  492. // notif
  493. moreMenuSurveyNotif.layer.cornerRadius = 5
  494. // menus
  495. let flowLayout = UICollectionViewFlowLayout()
  496. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  497. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  498. flowLayout.minimumInteritemSpacing = 0
  499. flowLayout.minimumLineSpacing = 0
  500. moreMenuSurveyCV.collectionViewLayout = flowLayout
  501. moreMenuSurveyCV.delegate = self
  502. moreMenuSurveyCV.dataSource = self
  503. moreMenuSurveyCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSurveyCellId)
  504. listMenuSurvey = MenuListData.instance.getMenuSurveyData(userRoleId: userRoleId)
  505. if listMenuSurvey.count > 0 {
  506. moreMenuSurveyCV.reloadData()
  507. moreMenuSurveyTitleLayout.show()
  508. moreMenuSurveyCV.show()
  509. marginMoreMenuSurvey.show()
  510. }
  511. }
  512. private func setMoreMenuUtamaNew(userRoleId: String) {
  513. // notif
  514. moreMenuNewNotif.layer.cornerRadius = 5
  515. // menus
  516. let flowLayout = UICollectionViewFlowLayout()
  517. flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0)
  518. flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize)
  519. flowLayout.minimumInteritemSpacing = 0
  520. flowLayout.minimumLineSpacing = 0
  521. moreMenuUtamaNewCV.collectionViewLayout = flowLayout
  522. moreMenuUtamaNewCV.delegate = self
  523. moreMenuUtamaNewCV.dataSource = self
  524. moreMenuUtamaNewCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuUtamaCellNewId)
  525. listMenuUtamaNew = MenuListData.instance.getMenuUtamaNewData(userRoleId: userRoleId)
  526. if listMenuUtamaNew.count > 0 {
  527. moreMenuUtamaNewCV.reloadData()
  528. moreMenuNewTitleLayout.show()
  529. moreMenuUtamaNewCV.show()
  530. marginMoreMenuUtamaNew.show()
  531. }
  532. }
  533. // IB Actions
  534. @IBAction func unwindToHome(segue: UIStoryboardSegue) {}
  535. @IBAction func onBtnMoreMenuTapped(_ sender: Any) {
  536. self.showMoreMenu()
  537. if !loading {
  538. let userRoleId = UserState.instance.getRoleId()
  539. if !userRoleId.isEmpty {
  540. clearMoreMenuNotifData()
  541. presenter.loadMenuNotifications()
  542. }
  543. }
  544. }
  545. @IBAction func dismissMoreMenuLayout(_ sender: Any) {
  546. self.hideMoreMenu()
  547. }
  548. @IBAction func onBtnMoreNewsTap(_ sender: Any) {
  549. if !loading {
  550. performSegue(withIdentifier: "NewsSegueId", sender: self)
  551. }
  552. }
  553. @objc func openNotifList(sender : UITapGestureRecognizer) {
  554. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  555. }
  556. public func openNotifListPage() {
  557. performSegue(withIdentifier: "NotifListSegueId", sender: self)
  558. }
  559. }
  560. // HomeViewDelegate
  561. extension HomeVC: HomeViewDelegate {
  562. func showLoading() {
  563. loading = true
  564. progress.startAnimating()
  565. progressLayout.show()
  566. }
  567. func hideLoading() {
  568. loading = false
  569. progress.stopAnimating()
  570. progressLayout.hide()
  571. }
  572. func setTotalUnreadNotif(totalUnreadNotif: Int) {
  573. if totalUnreadNotif > 0 {
  574. lblNotif.text = String(totalUnreadNotif)
  575. notifBg.show()
  576. } else {
  577. lblNotif.text = ""
  578. notifBg.hide()
  579. }
  580. }
  581. func setSlideshowImages(images: [String]) {
  582. if !images.isEmpty {
  583. var sources = [SDWebImageSource]()
  584. for url in images {
  585. sources.append(SDWebImageSource(urlString: url)!)
  586. }
  587. self.slideshow.slideshowInterval = 2.0
  588. self.slideshow.pageIndicatorPosition = .init(horizontal: .center, vertical: .under)
  589. self.slideshow.contentScaleMode = UIView.ContentMode.scaleAspectFill
  590. let pageControl = UIPageControl()
  591. pageControl.currentPageIndicatorTintColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
  592. pageControl.pageIndicatorTintColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
  593. self.slideshow.pageIndicator = pageControl
  594. self.slideshow.setImageInputs(sources)
  595. }
  596. }
  597. func setNews(listNews: [News]) {
  598. if listNews.count > 0 {
  599. homeNewsTV.beginUpdates()
  600. for news in listNews {
  601. self.listNews.append(news)
  602. homeNewsTV.insertRows(
  603. at: [IndexPath(row: self.listNews.count-1, section: 0)],
  604. with: .automatic
  605. )
  606. }
  607. homeNewsTV.endUpdates()
  608. }
  609. }
  610. func setMenuNotifications(menuNotification: MenuNotification) {
  611. let userRoleId = UserState.instance.getRoleId()
  612. if userRoleId == CUSTOMER_ROLE_ID {
  613. if listMenuSP2Sertifikat.count > 0 {
  614. // total notif
  615. let totalNotif = menuNotification.tot_sp2_sertifikat
  616. if (totalNotif > 0) {
  617. lblMoreMenuSP2SertifikatNotif.text = "\(totalNotif)"
  618. moreMenuSP2SertifikatNotif.show()
  619. } else {
  620. moreMenuSP2SertifikatNotif.hide()
  621. }
  622. // sp2 sertifikat
  623. listMenuSP2Sertifikat[0].totalNotif = menuNotification.tot_sp2_sertifikat
  624. moreMenuSP2SertifikatCV.reloadData()
  625. }
  626. if listMenuSP2Tambahan.count > 0 {
  627. // total notif
  628. let tot_ods = menuNotification.tot_sp2_tambahan
  629. if (tot_ods > 0) {
  630. lblMoreMenuSP2TambahanNotif.text = "\(tot_ods)"
  631. moreMenuSP2TambahanNotif.show()
  632. } else {
  633. moreMenuSP2TambahanNotif.hide()
  634. }
  635. // sp2 tambahan
  636. listMenuSP2Tambahan[0].totalNotif = menuNotification.tot_sp2_tambahan
  637. moreMenuSP2TambahanCV.reloadData()
  638. }
  639. if listMenuSertifikat.count > 0 {
  640. // total
  641. let tot_ods = menuNotification.tot_sertifikat
  642. if (tot_ods > 0) {
  643. lblMoreMenuSertifikatNotif.text = "\(tot_ods)"
  644. moreMenuSertifikatNotif.show()
  645. } else {
  646. moreMenuSertifikatNotif.hide()
  647. }
  648. // sert sementara
  649. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  650. // sert berlaku
  651. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  652. moreMenuSertifikatCV.reloadData()
  653. }
  654. } else if userRoleId == OPERATOR_ROLE_ID {
  655. if listMenuAplikasiODS.count > 0 {
  656. // total notif
  657. let totalNotif = menuNotification.tot_ods
  658. if (totalNotif > 0) {
  659. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  660. moreMenuOdsNotif.show()
  661. } else {
  662. moreMenuOdsNotif.hide()
  663. }
  664. // ods sp2 baru
  665. listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2baru
  666. // ods sp2 otirisasi
  667. listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  668. moreMenuAplikasiODSCV.reloadData()
  669. }
  670. if listMenuSertifikat.count > 0 {
  671. // total notif
  672. let totalNotif = menuNotification.tot_sertifikat
  673. if (totalNotif > 0) {
  674. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  675. moreMenuSertifikatNotif.show()
  676. } else {
  677. moreMenuSertifikatNotif.hide()
  678. }
  679. // sert sementara
  680. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  681. // sert berlaku
  682. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  683. moreMenuSertifikatCV.reloadData()
  684. }
  685. } else if userRoleId == KEPALA_SEKSI_ROLE_ID {
  686. if listMenuAplikasiODS.count > 0 {
  687. // total notif
  688. let totalNotif = menuNotification.tot_ods
  689. if (totalNotif > 0) {
  690. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  691. moreMenuOdsNotif.show()
  692. } else {
  693. moreMenuOdsNotif.hide()
  694. }
  695. // ods sp2 otorisasi
  696. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  697. //sp2 before
  698. listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2before
  699. //sp2 after
  700. listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2after
  701. moreMenuAplikasiODSCV.reloadData()
  702. }
  703. if listMenuSertifikat.count > 0 {
  704. // total notif
  705. let totalNotif = menuNotification.tot_sertifikat
  706. if (totalNotif > 0) {
  707. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  708. moreMenuSertifikatNotif.show()
  709. } else {
  710. moreMenuSertifikatNotif.hide()
  711. }
  712. // sert sementara
  713. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  714. // sert berlaku
  715. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  716. moreMenuSertifikatCV.reloadData()
  717. }
  718. } else if userRoleId == KEPALA_SUB_DIREKTORAT_ROLE_ID {
  719. if listMenuAplikasiODS.count > 0 {
  720. // total notif
  721. let totalNotif = menuNotification.tot_ods
  722. if (totalNotif > 0) {
  723. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  724. moreMenuOdsNotif.show()
  725. } else {
  726. moreMenuOdsNotif.hide()
  727. }
  728. // ods sp2 otorisasi
  729. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  730. moreMenuAplikasiODSCV.reloadData()
  731. }
  732. if listMenuSertifikat.count > 0 {
  733. // total notif
  734. let totalNotif = menuNotification.tot_sertifikat
  735. if (totalNotif > 0) {
  736. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  737. moreMenuSertifikatNotif.show()
  738. } else {
  739. moreMenuSertifikatNotif.hide()
  740. }
  741. // sert sementara
  742. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  743. // sert berlaku
  744. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  745. moreMenuSertifikatCV.reloadData()
  746. }
  747. } else if userRoleId == DIREKTUR_ROLE_ID {
  748. if listMenuAplikasiODS.count > 0 {
  749. // total notif
  750. let totalNotif = menuNotification.tot_ods
  751. if (totalNotif > 0) {
  752. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  753. moreMenuOdsNotif.show()
  754. } else {
  755. moreMenuOdsNotif.hide()
  756. }
  757. // ods sp2 otorisasi
  758. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  759. moreMenuAplikasiODSCV.reloadData()
  760. }
  761. if listMenuSertifikat.count > 0 {
  762. // total notif
  763. let totalNotif = menuNotification.tot_sertifikat
  764. if (totalNotif > 0) {
  765. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  766. moreMenuSertifikatNotif.show()
  767. } else {
  768. moreMenuSertifikatNotif.hide()
  769. }
  770. // sert sementara
  771. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  772. // sert berlaku
  773. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  774. moreMenuSertifikatCV.reloadData()
  775. }
  776. }
  777. }
  778. }
  779. // CollectionView functions
  780. extension HomeVC : UICollectionViewDelegate, UICollectionViewDataSource {
  781. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  782. if collectionView == self.moreMenuUtamaNewCV {
  783. return listMenuUtamaNew.count
  784. }
  785. else if collectionView == self.mainMenuCV {
  786. return listMenuUtama.count
  787. } else if collectionView == self.moreMenuUtamaCV {
  788. return listMenuUtama.count
  789. } else if collectionView == self.moreMenuAplikasiODSCV {
  790. return listMenuAplikasiODS.count
  791. } else if collectionView == self.moreMenuFotoLabelCV {
  792. return listMenuFotoLabel.count
  793. } else if collectionView == self.moreMenuAplikasiCV {
  794. return listMenuAplikasi.count
  795. } else if collectionView == self.moreMenuSP2SertifikatCV {
  796. return listMenuSP2Sertifikat.count
  797. } else if collectionView == self.moreMenuSP2TambahanCV {
  798. return listMenuSP2Tambahan.count
  799. } else if collectionView == self.moreMenuDaftarRHUCV {
  800. return listMenuDaftarRHU.count
  801. } else if collectionView == self.moreMenuSertifikatCV {
  802. return listMenuSertifikat.count
  803. } else if collectionView == self.moreMenuSurveyCV {
  804. return listMenuSurvey.count
  805. } else {
  806. return 0
  807. }
  808. }
  809. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  810. if collectionView == self.moreMenuUtamaNewCV {
  811. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellNewId, for: indexPath) as? MenuCell {
  812. let menu = listMenuUtamaNew[indexPath.row]
  813. cell.updateViews(menu: menu)
  814. return cell
  815. } else {
  816. return MenuCell()
  817. }
  818. } else if collectionView == self.mainMenuCV {
  819. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellId, for: indexPath) as? MenuCell {
  820. let menu = listMenuUtama[indexPath.row]
  821. cell.updateViews(menu: menu)
  822. return cell
  823. } else {
  824. return MenuCell()
  825. }
  826. } else if collectionView == self.moreMenuUtamaCV {
  827. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId, for: indexPath) as? MenuCell {
  828. let menu = listMenuUtama[indexPath.row]
  829. cell.updateViews(menu: menu)
  830. return cell
  831. } else {
  832. return MenuCell()
  833. }
  834. } else if collectionView == self.moreMenuAplikasiODSCV {
  835. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId, for: indexPath) as? MenuCell {
  836. let menu = listMenuAplikasiODS[indexPath.row]
  837. cell.updateViews(menu: menu)
  838. return cell
  839. } else {
  840. return MenuCell()
  841. }
  842. } else if collectionView == self.moreMenuFotoLabelCV {
  843. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuFotoLabelCellId, for: indexPath) as? MenuCell {
  844. let menu = listMenuFotoLabel[indexPath.row]
  845. cell.updateViews(menu: menu)
  846. return cell
  847. } else {
  848. return MenuCell()
  849. }
  850. } else if collectionView == self.moreMenuAplikasiCV {
  851. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiCellId, for: indexPath) as? MenuCell {
  852. let menu = listMenuAplikasi[indexPath.row]
  853. cell.updateViews(menu: menu)
  854. return cell
  855. } else {
  856. return MenuCell()
  857. }
  858. } else if collectionView == self.moreMenuSP2SertifikatCV {
  859. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId, for: indexPath) as? MenuCell {
  860. let menu = listMenuSP2Sertifikat[indexPath.row]
  861. cell.updateViews(menu: menu)
  862. return cell
  863. } else {
  864. return MenuCell()
  865. }
  866. } else if collectionView == self.moreMenuSP2TambahanCV {
  867. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId, for: indexPath) as? MenuCell {
  868. let menu = listMenuSP2Tambahan[indexPath.row]
  869. cell.updateViews(menu: menu)
  870. return cell
  871. } else {
  872. return MenuCell()
  873. }
  874. } else if collectionView == self.moreMenuDaftarRHUCV {
  875. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId, for: indexPath) as? MenuCell {
  876. let menu = listMenuDaftarRHU[indexPath.row]
  877. cell.updateViews(menu: menu)
  878. return cell
  879. } else {
  880. return MenuCell()
  881. }
  882. } else if collectionView == self.moreMenuSertifikatCV {
  883. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSertifikatCellId, for: indexPath) as? MenuCell {
  884. let menu = listMenuSertifikat[indexPath.row]
  885. cell.updateViews(menu: menu)
  886. return cell
  887. } else {
  888. return MenuCell()
  889. }
  890. } else if collectionView == self.moreMenuSurveyCV {
  891. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSurveyCellId, for: indexPath) as? MenuCell {
  892. let menu = listMenuSurvey[indexPath.row]
  893. cell.updateViews(menu: menu)
  894. return cell
  895. } else {
  896. return MenuCell()
  897. }
  898. } else {
  899. return MenuCell()
  900. }
  901. }
  902. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  903. var segueId = ""
  904. if collectionView == self.moreMenuUtamaNewCV {
  905. segueId = listMenuUtamaNew[indexPath.row].segueId
  906. } else if collectionView == self.mainMenuCV {
  907. segueId = listMenuUtama[indexPath.row].segueId
  908. } else if collectionView == self.moreMenuUtamaCV {
  909. segueId = listMenuUtama[indexPath.row].segueId
  910. } else if collectionView == self.moreMenuAplikasiODSCV {
  911. segueId = listMenuAplikasiODS[indexPath.row].segueId
  912. } else if collectionView == self.moreMenuFotoLabelCV {
  913. segueId = listMenuFotoLabel[indexPath.row].segueId
  914. } else if collectionView == self.moreMenuAplikasiCV {
  915. segueId = listMenuAplikasi[indexPath.row].segueId
  916. } else if collectionView == self.moreMenuSP2SertifikatCV {
  917. segueId = listMenuSP2Sertifikat[indexPath.row].segueId
  918. } else if collectionView == self.moreMenuSP2TambahanCV {
  919. segueId = listMenuSP2Tambahan[indexPath.row].segueId
  920. } else if collectionView == self.moreMenuDaftarRHUCV {
  921. segueId = listMenuDaftarRHU[indexPath.row].segueId
  922. } else if collectionView == self.moreMenuSertifikatCV {
  923. segueId = listMenuSertifikat[indexPath.row].segueId
  924. } else if collectionView == self.moreMenuSurveyCV {
  925. segueId = listMenuSurvey[indexPath.row].segueId
  926. }
  927. if !segueId.isEmpty {
  928. if !loading {
  929. performSegue(withIdentifier: segueId, sender: self)
  930. }
  931. }
  932. }
  933. }
  934. // UITableController Protocols
  935. extension HomeVC: UITableViewDelegate, UITableViewDataSource {
  936. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  937. return listNews.count
  938. }
  939. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  940. if tableView == homeNewsTV {
  941. if let cell = tableView.dequeueReusableCell(withIdentifier: homeNewsCellId, for: indexPath) as? HomeNewsCell {
  942. let news = listNews[indexPath.row]
  943. cell.updateViews(news: news)
  944. return cell
  945. } else {
  946. return HomeNewsCell()
  947. }
  948. } else {
  949. return HomeNewsCell()
  950. }
  951. }
  952. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  953. let selectedNews = self.listNews[indexPath.row]
  954. self.selectedNewsId = selectedNews.id
  955. self.date = selectedNews.dateNew()
  956. self.judul = selectedNews.title_news
  957. self.urlThumb = selectedNews.thumb_filename
  958. performSegue(withIdentifier: "homeToNewsDetailSegueId", sender: self)
  959. }
  960. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  961. return 140
  962. }
  963. }