HomeVC.swift 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092
  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. sources.append(SDWebImageSource(urlString: url)!)
  591. }
  592. self.slideshow.slideshowInterval = 2.0
  593. self.slideshow.pageIndicatorPosition = .init(horizontal: .center, vertical: .under)
  594. self.slideshow.contentScaleMode = UIView.ContentMode.scaleAspectFill
  595. let pageControl = UIPageControl()
  596. pageControl.currentPageIndicatorTintColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1)
  597. pageControl.pageIndicatorTintColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1)
  598. self.slideshow.pageIndicator = pageControl
  599. self.slideshow.setImageInputs(sources)
  600. }
  601. }
  602. func setNews(listNews: [News]) {
  603. if listNews.count > 0 {
  604. homeNewsTV.beginUpdates()
  605. for news in listNews {
  606. self.listNews.append(news)
  607. homeNewsTV.insertRows(
  608. at: [IndexPath(row: self.listNews.count-1, section: 0)],
  609. with: .automatic
  610. )
  611. }
  612. homeNewsTV.endUpdates()
  613. }
  614. }
  615. func setMenuNotifications(menuNotification: MenuNotification) {
  616. let userRoleId = UserState.instance.getRoleId()
  617. if userRoleId == CUSTOMER_ROLE_ID {
  618. if listMenuSP2Sertifikat.count > 0 {
  619. // total notif
  620. let totalNotif = menuNotification.tot_sp2_sertifikat
  621. if (totalNotif > 0) {
  622. lblMoreMenuSP2SertifikatNotif.text = "\(totalNotif)"
  623. moreMenuSP2SertifikatNotif.show()
  624. } else {
  625. moreMenuSP2SertifikatNotif.hide()
  626. }
  627. // sp2 sertifikat
  628. listMenuSP2Sertifikat[0].totalNotif = menuNotification.tot_sp2_sertifikat
  629. moreMenuSP2SertifikatCV.reloadData()
  630. }
  631. if listMenuSP2Tambahan.count > 0 {
  632. // total notif
  633. let tot_ods = menuNotification.tot_sp2_tambahan
  634. if (tot_ods > 0) {
  635. lblMoreMenuSP2TambahanNotif.text = "\(tot_ods)"
  636. moreMenuSP2TambahanNotif.show()
  637. } else {
  638. moreMenuSP2TambahanNotif.hide()
  639. }
  640. // sp2 tambahan
  641. listMenuSP2Tambahan[0].totalNotif = menuNotification.tot_sp2_tambahan
  642. moreMenuSP2TambahanCV.reloadData()
  643. }
  644. if listMenuSertifikat.count > 0 {
  645. // total
  646. let tot_ods = menuNotification.tot_sertifikat
  647. if (tot_ods > 0) {
  648. lblMoreMenuSertifikatNotif.text = "\(tot_ods)"
  649. moreMenuSertifikatNotif.show()
  650. } else {
  651. moreMenuSertifikatNotif.hide()
  652. }
  653. // sert sementara
  654. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  655. // sert berlaku
  656. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  657. moreMenuSertifikatCV.reloadData()
  658. }
  659. } else if userRoleId == OPERATOR_ROLE_ID {
  660. if listMenuAplikasiODS.count > 0 {
  661. // total notif
  662. let totalNotif = menuNotification.tot_ods
  663. if (totalNotif > 0) {
  664. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  665. moreMenuOdsNotif.show()
  666. } else {
  667. moreMenuOdsNotif.hide()
  668. }
  669. // ods sp2 baru
  670. listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2baru
  671. // ods sp2 otirisasi
  672. listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  673. moreMenuAplikasiODSCV.reloadData()
  674. }
  675. if listMenuSertifikat.count > 0 {
  676. // total notif
  677. let totalNotif = menuNotification.tot_sertifikat
  678. if (totalNotif > 0) {
  679. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  680. moreMenuSertifikatNotif.show()
  681. } else {
  682. moreMenuSertifikatNotif.hide()
  683. }
  684. // sert sementara
  685. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  686. // sert berlaku
  687. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  688. moreMenuSertifikatCV.reloadData()
  689. }
  690. } else if userRoleId == KEPALA_SEKSI_ROLE_ID {
  691. if listMenuAplikasiODS.count > 0 {
  692. // total notif
  693. let totalNotif = menuNotification.tot_ods
  694. if (totalNotif > 0) {
  695. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  696. moreMenuOdsNotif.show()
  697. } else {
  698. moreMenuOdsNotif.hide()
  699. }
  700. // ods sp2 otorisasi
  701. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  702. //sp2 before
  703. listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2before
  704. //sp2 after
  705. listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2after
  706. moreMenuAplikasiODSCV.reloadData()
  707. }
  708. if listMenuSertifikat.count > 0 {
  709. // total notif
  710. let totalNotif = menuNotification.tot_sertifikat
  711. if (totalNotif > 0) {
  712. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  713. moreMenuSertifikatNotif.show()
  714. } else {
  715. moreMenuSertifikatNotif.hide()
  716. }
  717. // sert sementara
  718. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  719. // sert berlaku
  720. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  721. moreMenuSertifikatCV.reloadData()
  722. }
  723. } else if userRoleId == KEPALA_SUB_DIREKTORAT_ROLE_ID {
  724. if listMenuAplikasiODS.count > 0 {
  725. // total notif
  726. let totalNotif = menuNotification.tot_ods
  727. if (totalNotif > 0) {
  728. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  729. moreMenuOdsNotif.show()
  730. } else {
  731. moreMenuOdsNotif.hide()
  732. }
  733. // ods sp2 otorisasi
  734. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  735. moreMenuAplikasiODSCV.reloadData()
  736. }
  737. if listMenuSertifikat.count > 0 {
  738. // total notif
  739. let totalNotif = menuNotification.tot_sertifikat
  740. if (totalNotif > 0) {
  741. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  742. moreMenuSertifikatNotif.show()
  743. } else {
  744. moreMenuSertifikatNotif.hide()
  745. }
  746. // sert sementara
  747. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  748. // sert berlaku
  749. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  750. moreMenuSertifikatCV.reloadData()
  751. }
  752. } else if userRoleId == DIREKTUR_ROLE_ID {
  753. if listMenuAplikasiODS.count > 0 {
  754. // total notif
  755. let totalNotif = menuNotification.tot_ods
  756. if (totalNotif > 0) {
  757. lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)"
  758. moreMenuOdsNotif.show()
  759. } else {
  760. moreMenuOdsNotif.hide()
  761. }
  762. // ods sp2 otorisasi
  763. listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi
  764. moreMenuAplikasiODSCV.reloadData()
  765. }
  766. if listMenuSertifikat.count > 0 {
  767. // total notif
  768. let totalNotif = menuNotification.tot_sertifikat
  769. if (totalNotif > 0) {
  770. lblMoreMenuSertifikatNotif.text = "\(totalNotif)"
  771. moreMenuSertifikatNotif.show()
  772. } else {
  773. moreMenuSertifikatNotif.hide()
  774. }
  775. // sert sementara
  776. listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara
  777. // sert berlaku
  778. listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku
  779. moreMenuSertifikatCV.reloadData()
  780. }
  781. }
  782. }
  783. }
  784. // CollectionView functions
  785. extension HomeVC : UICollectionViewDelegate, UICollectionViewDataSource {
  786. func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
  787. if collectionView == self.moreMenuUtamaNewCV {
  788. return listMenuUtamaNew.count
  789. }
  790. else if collectionView == self.mainMenuCV {
  791. return listMenuUtama.count
  792. } else if collectionView == self.moreMenuUtamaCV {
  793. return listMenuUtama.count
  794. } else if collectionView == self.moreMenuAplikasiODSCV {
  795. return listMenuAplikasiODS.count
  796. } else if collectionView == self.moreMenuFotoLabelCV {
  797. return listMenuFotoLabel.count
  798. } else if collectionView == self.moreMenuAplikasiCV {
  799. return listMenuAplikasi.count
  800. } else if collectionView == self.moreMenuSP2SertifikatCV {
  801. return listMenuSP2Sertifikat.count
  802. } else if collectionView == self.moreMenuSP2TambahanCV {
  803. return listMenuSP2Tambahan.count
  804. } else if collectionView == self.moreMenuDaftarRHUCV {
  805. return listMenuDaftarRHU.count
  806. } else if collectionView == self.moreMenuSertifikatCV {
  807. return listMenuSertifikat.count
  808. } else if collectionView == self.moreMenuSurveyCV {
  809. return listMenuSurvey.count
  810. } else {
  811. return 0
  812. }
  813. }
  814. func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
  815. if collectionView == self.moreMenuUtamaNewCV {
  816. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellNewId, for: indexPath) as? MenuCell {
  817. let menu = listMenuUtamaNew[indexPath.row]
  818. cell.updateViews(menu: menu)
  819. return cell
  820. } else {
  821. return MenuCell()
  822. }
  823. } else if collectionView == self.mainMenuCV {
  824. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellId, for: indexPath) as? MenuCell {
  825. let menu = listMenuUtama[indexPath.row]
  826. cell.updateViews(menu: menu)
  827. return cell
  828. } else {
  829. return MenuCell()
  830. }
  831. } else if collectionView == self.moreMenuUtamaCV {
  832. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId, for: indexPath) as? MenuCell {
  833. let menu = listMenuUtama[indexPath.row]
  834. cell.updateViews(menu: menu)
  835. return cell
  836. } else {
  837. return MenuCell()
  838. }
  839. } else if collectionView == self.moreMenuAplikasiODSCV {
  840. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId, for: indexPath) as? MenuCell {
  841. let menu = listMenuAplikasiODS[indexPath.row]
  842. cell.updateViews(menu: menu)
  843. return cell
  844. } else {
  845. return MenuCell()
  846. }
  847. } else if collectionView == self.moreMenuFotoLabelCV {
  848. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuFotoLabelCellId, for: indexPath) as? MenuCell {
  849. let menu = listMenuFotoLabel[indexPath.row]
  850. cell.updateViews(menu: menu)
  851. return cell
  852. } else {
  853. return MenuCell()
  854. }
  855. } else if collectionView == self.moreMenuAplikasiCV {
  856. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiCellId, for: indexPath) as? MenuCell {
  857. let menu = listMenuAplikasi[indexPath.row]
  858. cell.updateViews(menu: menu)
  859. return cell
  860. } else {
  861. return MenuCell()
  862. }
  863. } else if collectionView == self.moreMenuSP2SertifikatCV {
  864. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId, for: indexPath) as? MenuCell {
  865. let menu = listMenuSP2Sertifikat[indexPath.row]
  866. cell.updateViews(menu: menu)
  867. return cell
  868. } else {
  869. return MenuCell()
  870. }
  871. } else if collectionView == self.moreMenuSP2TambahanCV {
  872. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId, for: indexPath) as? MenuCell {
  873. let menu = listMenuSP2Tambahan[indexPath.row]
  874. cell.updateViews(menu: menu)
  875. return cell
  876. } else {
  877. return MenuCell()
  878. }
  879. } else if collectionView == self.moreMenuDaftarRHUCV {
  880. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId, for: indexPath) as? MenuCell {
  881. let menu = listMenuDaftarRHU[indexPath.row]
  882. cell.updateViews(menu: menu)
  883. return cell
  884. } else {
  885. return MenuCell()
  886. }
  887. } else if collectionView == self.moreMenuSertifikatCV {
  888. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSertifikatCellId, for: indexPath) as? MenuCell {
  889. let menu = listMenuSertifikat[indexPath.row]
  890. cell.updateViews(menu: menu)
  891. return cell
  892. } else {
  893. return MenuCell()
  894. }
  895. } else if collectionView == self.moreMenuSurveyCV {
  896. if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSurveyCellId, for: indexPath) as? MenuCell {
  897. let menu = listMenuSurvey[indexPath.row]
  898. cell.updateViews(menu: menu)
  899. return cell
  900. } else {
  901. return MenuCell()
  902. }
  903. } else {
  904. return MenuCell()
  905. }
  906. }
  907. func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
  908. var segueId = ""
  909. if collectionView == self.moreMenuUtamaNewCV {
  910. segueId = listMenuUtamaNew[indexPath.row].segueId
  911. } else if collectionView == self.mainMenuCV {
  912. segueId = listMenuUtama[indexPath.row].segueId
  913. } else if collectionView == self.moreMenuUtamaCV {
  914. segueId = listMenuUtama[indexPath.row].segueId
  915. } else if collectionView == self.moreMenuAplikasiODSCV {
  916. segueId = listMenuAplikasiODS[indexPath.row].segueId
  917. } else if collectionView == self.moreMenuFotoLabelCV {
  918. segueId = listMenuFotoLabel[indexPath.row].segueId
  919. } else if collectionView == self.moreMenuAplikasiCV {
  920. segueId = listMenuAplikasi[indexPath.row].segueId
  921. } else if collectionView == self.moreMenuSP2SertifikatCV {
  922. segueId = listMenuSP2Sertifikat[indexPath.row].segueId
  923. } else if collectionView == self.moreMenuSP2TambahanCV {
  924. segueId = listMenuSP2Tambahan[indexPath.row].segueId
  925. } else if collectionView == self.moreMenuDaftarRHUCV {
  926. segueId = listMenuDaftarRHU[indexPath.row].segueId
  927. } else if collectionView == self.moreMenuSertifikatCV {
  928. segueId = listMenuSertifikat[indexPath.row].segueId
  929. } else if collectionView == self.moreMenuSurveyCV {
  930. segueId = listMenuSurvey[indexPath.row].segueId
  931. }
  932. if !segueId.isEmpty {
  933. if !loading {
  934. performSegue(withIdentifier: segueId, sender: self)
  935. }
  936. }
  937. }
  938. }
  939. // UITableController Protocols
  940. extension HomeVC: UITableViewDelegate, UITableViewDataSource {
  941. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  942. return listNews.count
  943. }
  944. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  945. if tableView == homeNewsTV {
  946. if let cell = tableView.dequeueReusableCell(withIdentifier: homeNewsCellId, for: indexPath) as? HomeNewsCell {
  947. let news = listNews[indexPath.row]
  948. cell.updateViews(news: news)
  949. return cell
  950. } else {
  951. return HomeNewsCell()
  952. }
  953. } else {
  954. return HomeNewsCell()
  955. }
  956. }
  957. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  958. let selectedNews = self.listNews[indexPath.row]
  959. self.selectedNewsId = selectedNews.id
  960. self.date = selectedNews.dateNew()
  961. self.judul = selectedNews.title_news
  962. self.urlThumb = selectedNews.thumb_filename
  963. performSegue(withIdentifier: "homeToNewsDetailSegueId", sender: self)
  964. }
  965. func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  966. return 140
  967. }
  968. }