HomeVC.swift 44 KB

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