HomeVC.swift 41 KB

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