HomeVC.swift 47 KB

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