HomeVC.swift 45 KB

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