// // HomeVC.swift // Sirani // // Created by Anhar Solehudin on 24/03/19. // Copyright © 2019 Anhar Solehudin. All rights reserved. // import UIKit import ImageSlideshow class HomeVC: UIViewController { // Outlets @IBOutlet weak var notifContainer: UIView! @IBOutlet weak var notifBg: CircleView! @IBOutlet weak var lblNotif: UILabel! @IBOutlet weak var progressLayout: UIView! @IBOutlet weak var progress: UIActivityIndicatorView! @IBOutlet weak var slideshow: ImageSlideshow! @IBOutlet weak var container: UIView! @IBOutlet weak var moreMenuLayout: UIView! @IBOutlet weak var headerLayout: UIView! @IBOutlet weak var moreMenuContainer: UIView! @IBOutlet weak var mainMenuCV: UICollectionView! @IBOutlet weak var btnMoreMenu: UIButton! @IBOutlet weak var btnMoreNews: UIButton! @IBOutlet weak var homeNewsTV: UITableView! @IBOutlet weak var moreMenuUtamaCV: UICollectionView! @IBOutlet weak var moreMenuAplikasiODSTitleLayout: UIView! @IBOutlet weak var moreMenuOdsNotif: UIView! @IBOutlet weak var lblMoreMenuAplikasiODSNotif: UILabel! @IBOutlet weak var moreMenuAplikasiODSCV: UICollectionView! @IBOutlet weak var marginMoreMenuAplikasiODS: UIView! @IBOutlet weak var moreMenuFotoLabelTitleLayout: UIView! @IBOutlet weak var moreMenuFotoLabelNotif: UIView! @IBOutlet weak var lblMoreMenuFotoLabelNotif: UILabel! @IBOutlet weak var moreMenuFotoLabelCV: UICollectionView! @IBOutlet weak var marginMoreMenuFotoLabel: UIView! @IBOutlet weak var moreMenuAplikasiTitleLayout: UIView! @IBOutlet weak var moreMenuAplikasiNotif: UIView! @IBOutlet weak var lblMoreMenuAplikasiNotif: UILabel! @IBOutlet weak var moreMenuAplikasiCV: UICollectionView! @IBOutlet weak var marginMoreMenuAplikasi: UIView! @IBOutlet weak var moreMenuSP2SertifikatTitleLayout: UIView! @IBOutlet weak var moreMenuSP2SertifikatNotif: UIView! @IBOutlet weak var lblMoreMenuSP2SertifikatNotif: UILabel! @IBOutlet weak var moreMenuSP2SertifikatCV: UICollectionView! @IBOutlet weak var marginMoreMenuSP2Sertifikat: UIView! @IBOutlet weak var moreMenuSP2TambahanTItleLayout: UIView! @IBOutlet weak var moreMenuSP2TambahanNotif: UIView! @IBOutlet weak var lblMoreMenuSP2TambahanNotif: UILabel! @IBOutlet weak var moreMenuSP2TambahanCV: UICollectionView! @IBOutlet weak var marginMoreMenuSP2Tambahan: UIView! @IBOutlet weak var moreMenuDaftarRHUTitleLayout: UIView! @IBOutlet weak var moreMenuDaftarRhuNotif: UIView! @IBOutlet weak var lblMoreMenuDaftarRHUNotif: UILabel! @IBOutlet weak var moreMenuDaftarRHUCV: UICollectionView! @IBOutlet weak var marginMoreMenuDaftarRHU: UIView! @IBOutlet weak var moreMenuSertifikatTitleLayout: UIView! @IBOutlet weak var moreMenuSertifikatNotif: UIView! @IBOutlet weak var lblMoreMenuSertifikatNotif: UILabel! @IBOutlet weak var moreMenuSertifikatCV: UICollectionView! @IBOutlet weak var marginMoreMenuSertifikat: UIView! @IBOutlet weak var moreMenuSurveyTitleLayout: UIView! @IBOutlet weak var moreMenuSurveyNotif: UIView! @IBOutlet weak var lblMoreMenuNotif: UILabel! @IBOutlet weak var moreMenuSurveyCV: UICollectionView! @IBOutlet weak var marginMoreMenuSurvey: UIView! // id private let homeNewsCellId = "HomeNewsCellId" // initialize private let presenter = HomePresenter(siraniApiServices: SiraniApiServices()) // data list private var listNews = [News]() private let listMenuUtama = MenuListData.instance.getMenuUtamaData() private var listMenuAplikasiODS = [MenuItem]() private var listMenuFotoLabel = [MenuItem]() private var listMenuAplikasi = [MenuItem]() private var listMenuSP2Sertifikat = [MenuItem]() private var listMenuSP2Tambahan = [MenuItem]() private var listMenuDaftarRHU = [MenuItem]() private var listMenuSertifikat = [MenuItem]() private var listMenuSurvey = [MenuItem]() // Constants private let menuItemSize = 85.75 private let CUSTOMER_ROLE_ID = Constants.instance.CUSTOMER_ROLE_ID private let OPERATOR_ROLE_ID = Constants.instance.OPERATOR_ROLE_ID private let KEPALA_SEKSI_ROLE_ID = Constants.instance.KEPALA_SEKSI_ROLE_ID private let KEPALA_SUB_DIREKTORAT_ROLE_ID = Constants.instance.KEPALA_SUB_DIREKTORAT_ROLE_ID private let DIREKTUR_ROLE_ID = Constants.instance.DIREKTUR_ROLE_ID // Variables (notes : let is constants) private var moreMenuFrame: CGRect? private var loading = false private var selectedNewsId = 0 private var moreMenuShown = false private var showMoreMenuDuration = 0.2 private var userRoleId = "" public var openNotif = false // View Lifecycles override var preferredStatusBarStyle: UIStatusBarStyle { return .lightContent } override func viewWillAppear(_ animated: Bool) { AppUtility.lockOrientation(.portrait) btnMoreMenu.layer.cornerRadius = 5 btnMoreNews.layer.cornerRadius = 5 moreMenuFrame = moreMenuLayout.frame moreMenuLayout.frame = .init( x: 0, y: view.frame.height, width: moreMenuFrame!.size.width, height: moreMenuFrame!.size.height ) let gesture = UITapGestureRecognizer(target: self, action: #selector(self.openNotifList)) notifContainer.addGestureRecognizer(gesture) userRoleId = UserState.instance.getRoleId() let userId = UserState.instance.getUserId() let custId = UserState.instance.getCustId() print("userRoleId") print(userRoleId) print(userId) print(custId) if !userRoleId.isEmpty { showNotif() } else { hideNotif() } } override func viewDidLoad() { super.viewDidLoad() presenter.attachView(view: self) presenter.loadSlideshowImages() if openNotif { print("SSSSSS") performSegue(withIdentifier: "NotifListSegueId", sender: self) } setMainMenu() setNewsView() setMoreMainMenu() userRoleId = UserState.instance.getRoleId() if !userRoleId.isEmpty { setMoreMenuAplikasiODS(userRoleId: userRoleId) setMoreMenuFotoLabel(userRoleId: userRoleId) setMoreMenuAplikasi(userRoleId: userRoleId) setMoreMenuSP2Sertifikat(userRoleId: userRoleId) setMoreMenuSP2Tambahan(userRoleId: userRoleId) setMoreMenuDaftarRHU(userRoleId: userRoleId) setMoreMenuSertifikat(userRoleId: userRoleId) setMoreMenuSurvey(userRoleId: userRoleId) showNotif() } else { hideNotif() } } override func viewDidAppear(_ animated: Bool) { presenter.attachView(view: self) if openNotif { print("VVVVVV") performSegue(withIdentifier: "NotifListSegueId", sender: self) } if moreMenuShown { showMoreMenu() } // let roleId = UserState.instance.getRoleId() // if (userRoleId != roleId) { // userRoleId = roleId // if !userRoleId.isEmpty { clearMoreMenu() setMoreMenuAplikasiODS(userRoleId: userRoleId) setMoreMenuFotoLabel(userRoleId: userRoleId) setMoreMenuAplikasi(userRoleId: userRoleId) setMoreMenuSP2Sertifikat(userRoleId: userRoleId) setMoreMenuSP2Tambahan(userRoleId: userRoleId) setMoreMenuDaftarRHU(userRoleId: userRoleId) setMoreMenuSertifikat(userRoleId: userRoleId) setMoreMenuSurvey(userRoleId: userRoleId) clearMoreMenuNotifData() presenter.loadMenuNotifications() showNotif() } else { clearMoreMenu() clearMoreMenuNotifData() hideNotif() } // } } override func viewWillDisappear(_ animated: Bool) { AppUtility.lockOrientation(.all) } override func viewDidDisappear(_ animated: Bool) { presenter.detachView() } override func prepare(for segue: UIStoryboardSegue, sender: Any?) { if let destVC = segue.destination as? NewsDetailVC { destVC.newsId = self.selectedNewsId destVC.segueId = destVC.SEGUE_HOME_ID } } // private functions private func showNotif() { notifContainer.show() presenter.loadTotalUnreadNotif() } private func hideNotif() { notifContainer.hide() notifBg.hide() lblNotif.text = "" } private func setMainMenu() { let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 8, bottom: 0, right: 8) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 mainMenuCV.collectionViewLayout = flowLayout mainMenuCV.delegate = self mainMenuCV.dataSource = self mainMenuCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuUtamaCellId) } private func setNewsView() { homeNewsTV.delegate = self homeNewsTV.dataSource = self let footer = UIView() footer.backgroundColor = #colorLiteral(red: 0.9814968705, green: 0.9760531783, blue: 1, alpha: 1) homeNewsTV.tableFooterView = footer presenter.loadNews(cursor: 0, prev: 1, jenis: "", columns: "") } private func showMoreMenu() { if !loading { UIView.animate(withDuration: showMoreMenuDuration, delay: 0, options: [.curveEaseOut], animations: { self.moreMenuShown = true self.moreMenuLayout.show() self.moreMenuFrame = self.moreMenuLayout.frame self.moreMenuLayout.frame = .init(x: 0, y: self.headerLayout.frame.height, width: self.moreMenuFrame!.size.width, height: self.moreMenuFrame!.size.height) }) } } private func hideMoreMenu() { self.moreMenuShown = false self.moreMenuLayout.hide() self.moreMenuFrame = self.moreMenuLayout.frame self.moreMenuLayout.frame = .init(x: 0, y: view.frame.height, width: self.moreMenuFrame!.size.width, height: self.moreMenuFrame!.size.height) } private func clearMoreMenu() { moreMenuAplikasiODSTitleLayout.hide() moreMenuOdsNotif.hide() moreMenuAplikasiODSCV.hide() marginMoreMenuAplikasiODS.hide() moreMenuFotoLabelTitleLayout.hide() moreMenuFotoLabelNotif.hide() moreMenuFotoLabelCV.hide() marginMoreMenuFotoLabel.hide() moreMenuAplikasiTitleLayout.hide() moreMenuAplikasiNotif.hide() moreMenuAplikasiCV.hide() marginMoreMenuAplikasi.hide() moreMenuSP2SertifikatTitleLayout.hide() moreMenuSP2SertifikatNotif.hide() moreMenuSP2SertifikatCV.hide() marginMoreMenuSP2Sertifikat.hide() moreMenuSP2TambahanTItleLayout.hide() moreMenuSP2TambahanNotif.hide() moreMenuSP2TambahanCV.hide() marginMoreMenuSP2Tambahan.hide() moreMenuDaftarRHUTitleLayout.hide() moreMenuDaftarRhuNotif.hide() moreMenuDaftarRHUCV.hide() marginMoreMenuDaftarRHU.hide() moreMenuSertifikatTitleLayout.hide() moreMenuSertifikatNotif.hide() moreMenuSertifikatCV.hide() marginMoreMenuSertifikat.hide() moreMenuSurveyTitleLayout.hide() moreMenuSurveyNotif.hide() moreMenuSurveyCV.hide() marginMoreMenuSurvey.hide() } private func clearMoreMenuNotifData() { moreMenuOdsNotif.hide() moreMenuFotoLabelNotif.hide() moreMenuAplikasiNotif.hide() moreMenuSP2SertifikatNotif.hide() moreMenuSP2TambahanNotif.hide() moreMenuDaftarRhuNotif.hide() moreMenuSertifikatNotif.hide() moreMenuSurveyNotif.hide() for i in 0.. 0 { moreMenuAplikasiODSCV.reloadData() moreMenuAplikasiODSTitleLayout.show() moreMenuAplikasiODSCV.show() marginMoreMenuAplikasiODS.show() } } private func setMoreMenuFotoLabel(userRoleId: String) { // notif moreMenuFotoLabelNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuFotoLabelCV.collectionViewLayout = flowLayout moreMenuFotoLabelCV.delegate = self moreMenuFotoLabelCV.dataSource = self moreMenuFotoLabelCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuFotoLabelCellId) listMenuFotoLabel = MenuListData.instance.getMenuFotoLabelData(userRoleId: userRoleId) if listMenuFotoLabel.count > 0 { moreMenuFotoLabelCV.reloadData() moreMenuFotoLabelTitleLayout.show() moreMenuFotoLabelCV.show() marginMoreMenuFotoLabel.show() } } private func setMoreMenuAplikasi(userRoleId: String) { // notif moreMenuAplikasiNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuAplikasiCV.collectionViewLayout = flowLayout moreMenuAplikasiCV.delegate = self moreMenuAplikasiCV.dataSource = self moreMenuAplikasiCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuAplikasiCellId) listMenuAplikasi = MenuListData.instance.getMenuAplikasiData(userRoleId: userRoleId) if listMenuAplikasi.count > 0 { moreMenuAplikasiCV.reloadData() moreMenuAplikasiTitleLayout.show() moreMenuAplikasiCV.show() marginMoreMenuAplikasi.show() } } private func setMoreMenuSP2Sertifikat(userRoleId: String) { // notif moreMenuSP2SertifikatNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuSP2SertifikatCV.collectionViewLayout = flowLayout moreMenuSP2SertifikatCV.delegate = self moreMenuSP2SertifikatCV.dataSource = self moreMenuSP2SertifikatCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId) listMenuSP2Sertifikat = MenuListData.instance.getMenuSP2SertifikatData(userRoleId: userRoleId) if listMenuSP2Sertifikat.count > 0 { moreMenuSP2SertifikatCV.reloadData() moreMenuSP2SertifikatTitleLayout.show() moreMenuSP2SertifikatCV.show() marginMoreMenuSP2Sertifikat.show() } } private func setMoreMenuSP2Tambahan(userRoleId: String) { // notif moreMenuSP2TambahanNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuSP2TambahanCV.collectionViewLayout = flowLayout moreMenuSP2TambahanCV.delegate = self moreMenuSP2TambahanCV.dataSource = self moreMenuSP2TambahanCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId) listMenuSP2Tambahan = MenuListData.instance.getMenuSP2TambahanData(userRoleId: userRoleId) if listMenuSP2Tambahan.count > 0 { moreMenuSP2TambahanCV.reloadData() moreMenuSP2TambahanTItleLayout.show() moreMenuSP2TambahanCV.show() marginMoreMenuSP2Tambahan.show() } } private func setMoreMenuDaftarRHU(userRoleId: String) { // notif moreMenuDaftarRhuNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuDaftarRHUCV.collectionViewLayout = flowLayout moreMenuDaftarRHUCV.delegate = self moreMenuDaftarRHUCV.dataSource = self moreMenuDaftarRHUCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId) listMenuDaftarRHU = MenuListData.instance.getMenuDaftarRhuData(userRoleId: userRoleId) if listMenuDaftarRHU.count > 0 { moreMenuDaftarRHUCV.reloadData() moreMenuDaftarRHUTitleLayout.show() moreMenuDaftarRHUCV.show() marginMoreMenuDaftarRHU.show() } } private func setMoreMenuSertifikat(userRoleId: String) { // notif moreMenuSertifikatNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuSertifikatCV.collectionViewLayout = flowLayout moreMenuSertifikatCV.delegate = self moreMenuSertifikatCV.dataSource = self moreMenuSertifikatCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSertifikatCellId) listMenuSertifikat = MenuListData.instance.getMenuSertifikatData(userRoleId: userRoleId) if listMenuSertifikat.count > 0 { moreMenuSertifikatCV.reloadData() moreMenuSertifikatTitleLayout.show() moreMenuSertifikatCV.show() marginMoreMenuSertifikat.show() } } private func setMoreMenuSurvey(userRoleId: String) { // notif moreMenuSurveyNotif.layer.cornerRadius = 5 // menus let flowLayout = UICollectionViewFlowLayout() flowLayout.sectionInset = .init(top: 0, left: 0, bottom: 0, right: 0) flowLayout.itemSize = CGSize(width: menuItemSize, height: menuItemSize) flowLayout.minimumInteritemSpacing = 0 flowLayout.minimumLineSpacing = 0 moreMenuSurveyCV.collectionViewLayout = flowLayout moreMenuSurveyCV.delegate = self moreMenuSurveyCV.dataSource = self moreMenuSurveyCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuSurveyCellId) listMenuSurvey = MenuListData.instance.getMenuSurveyData(userRoleId: userRoleId) if listMenuSurvey.count > 0 { moreMenuSurveyCV.reloadData() moreMenuSurveyTitleLayout.show() moreMenuSurveyCV.show() marginMoreMenuSurvey.show() } } // IB Actions @IBAction func unwindToHome(segue: UIStoryboardSegue) {} @IBAction func onBtnMoreMenuTapped(_ sender: Any) { self.showMoreMenu() if !loading { let userRoleId = UserState.instance.getRoleId() if !userRoleId.isEmpty { clearMoreMenuNotifData() presenter.loadMenuNotifications() } } } @IBAction func dismissMoreMenuLayout(_ sender: Any) { self.hideMoreMenu() } @IBAction func onBtnMoreNewsTap(_ sender: Any) { if !loading { performSegue(withIdentifier: "NewsSegueId", sender: self) } } @objc func openNotifList(sender : UITapGestureRecognizer) { performSegue(withIdentifier: "NotifListSegueId", sender: self) } public func openNotifListPage() { performSegue(withIdentifier: "NotifListSegueId", sender: self) } } // HomeViewDelegate extension HomeVC: HomeViewDelegate { func showLoading() { loading = true progress.startAnimating() progressLayout.show() } func hideLoading() { loading = false progress.stopAnimating() progressLayout.hide() } func setTotalUnreadNotif(totalUnreadNotif: Int) { if totalUnreadNotif > 0 { lblNotif.text = String(totalUnreadNotif) notifBg.show() } else { lblNotif.text = "" notifBg.hide() } } func setSlideshowImages(images: [String]) { if !images.isEmpty { var sources = [SDWebImageSource]() for url in images { sources.append(SDWebImageSource(urlString: url)!) } self.slideshow.slideshowInterval = 2.0 self.slideshow.pageIndicatorPosition = .init(horizontal: .center, vertical: .under) self.slideshow.contentScaleMode = UIView.ContentMode.scaleAspectFill let pageControl = UIPageControl() pageControl.currentPageIndicatorTintColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) pageControl.pageIndicatorTintColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1) self.slideshow.pageIndicator = pageControl self.slideshow.setImageInputs(sources) } } func setNews(listNews: [News]) { if listNews.count > 0 { homeNewsTV.beginUpdates() for news in listNews { self.listNews.append(news) homeNewsTV.insertRows( at: [IndexPath(row: self.listNews.count-1, section: 0)], with: .automatic ) } homeNewsTV.endUpdates() } } func setMenuNotifications(menuNotification: MenuNotification) { let userRoleId = UserState.instance.getRoleId() if userRoleId == CUSTOMER_ROLE_ID { if listMenuSP2Sertifikat.count > 0 { // total notif let totalNotif = menuNotification.tot_sp2_sertifikat if (totalNotif > 0) { lblMoreMenuSP2SertifikatNotif.text = "\(totalNotif)" moreMenuSP2SertifikatNotif.show() } else { moreMenuSP2SertifikatNotif.hide() } // sp2 sertifikat listMenuSP2Sertifikat[0].totalNotif = menuNotification.tot_sp2_sertifikat moreMenuSP2SertifikatCV.reloadData() } if listMenuSP2Tambahan.count > 0 { // total notif let tot_ods = menuNotification.tot_sp2_tambahan if (tot_ods > 0) { lblMoreMenuSP2TambahanNotif.text = "\(tot_ods)" moreMenuSP2TambahanNotif.show() } else { moreMenuSP2TambahanNotif.hide() } // sp2 tambahan listMenuSP2Tambahan[0].totalNotif = menuNotification.tot_sp2_tambahan moreMenuSP2TambahanCV.reloadData() } if listMenuSertifikat.count > 0 { // total let tot_ods = menuNotification.tot_sertifikat if (tot_ods > 0) { lblMoreMenuSertifikatNotif.text = "\(tot_ods)" moreMenuSertifikatNotif.show() } else { moreMenuSertifikatNotif.hide() } // sert sementara listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara // sert berlaku listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku moreMenuSertifikatCV.reloadData() } } else if userRoleId == OPERATOR_ROLE_ID { if listMenuAplikasiODS.count > 0 { // total notif let totalNotif = menuNotification.tot_ods if (totalNotif > 0) { lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)" moreMenuOdsNotif.show() } else { moreMenuOdsNotif.hide() } // ods sp2 baru listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2baru // ods sp2 otirisasi listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2otorisasi moreMenuAplikasiODSCV.reloadData() } if listMenuSertifikat.count > 0 { // total notif let totalNotif = menuNotification.tot_sertifikat if (totalNotif > 0) { lblMoreMenuSertifikatNotif.text = "\(totalNotif)" moreMenuSertifikatNotif.show() } else { moreMenuSertifikatNotif.hide() } // sert sementara listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara // sert berlaku listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku moreMenuSertifikatCV.reloadData() } } else if userRoleId == KEPALA_SEKSI_ROLE_ID { if listMenuAplikasiODS.count > 0 { // total notif let totalNotif = menuNotification.tot_ods if (totalNotif > 0) { lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)" moreMenuOdsNotif.show() } else { moreMenuOdsNotif.hide() } // ods sp2 otorisasi listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi //sp2 before listMenuAplikasiODS[1].totalNotif = menuNotification.cnt_ods_sp2before //sp2 after listMenuAplikasiODS[2].totalNotif = menuNotification.cnt_ods_sp2after moreMenuAplikasiODSCV.reloadData() } if listMenuSertifikat.count > 0 { // total notif let totalNotif = menuNotification.tot_sertifikat if (totalNotif > 0) { lblMoreMenuSertifikatNotif.text = "\(totalNotif)" moreMenuSertifikatNotif.show() } else { moreMenuSertifikatNotif.hide() } // sert sementara listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara // sert berlaku listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku moreMenuSertifikatCV.reloadData() } } else if userRoleId == KEPALA_SUB_DIREKTORAT_ROLE_ID { if listMenuAplikasiODS.count > 0 { // total notif let totalNotif = menuNotification.tot_ods if (totalNotif > 0) { lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)" moreMenuOdsNotif.show() } else { moreMenuOdsNotif.hide() } // ods sp2 otorisasi listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi moreMenuAplikasiODSCV.reloadData() } if listMenuSertifikat.count > 0 { // total notif let totalNotif = menuNotification.tot_sertifikat if (totalNotif > 0) { lblMoreMenuSertifikatNotif.text = "\(totalNotif)" moreMenuSertifikatNotif.show() } else { moreMenuSertifikatNotif.hide() } // sert sementara listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara // sert berlaku listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku moreMenuSertifikatCV.reloadData() } } else if userRoleId == DIREKTUR_ROLE_ID { if listMenuAplikasiODS.count > 0 { // total notif let totalNotif = menuNotification.tot_ods if (totalNotif > 0) { lblMoreMenuAplikasiODSNotif.text = "\(totalNotif)" moreMenuOdsNotif.show() } else { moreMenuOdsNotif.hide() } // ods sp2 otorisasi listMenuAplikasiODS[0].totalNotif = menuNotification.cnt_ods_sp2otorisasi moreMenuAplikasiODSCV.reloadData() } if listMenuSertifikat.count > 0 { // total notif let totalNotif = menuNotification.tot_sertifikat if (totalNotif > 0) { lblMoreMenuSertifikatNotif.text = "\(totalNotif)" moreMenuSertifikatNotif.show() } else { moreMenuSertifikatNotif.hide() } // sert sementara listMenuSertifikat[0].totalNotif = menuNotification.cnt_sertifikatsementara // sert berlaku listMenuSertifikat[1].totalNotif = menuNotification.cnt_sertifikatberlaku moreMenuSertifikatCV.reloadData() } } } } // CollectionView functions extension HomeVC : UICollectionViewDelegate, UICollectionViewDataSource { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { if collectionView == self.mainMenuCV { return listMenuUtama.count } else if collectionView == self.moreMenuUtamaCV { return listMenuUtama.count } else if collectionView == self.moreMenuAplikasiODSCV { return listMenuAplikasiODS.count } else if collectionView == self.moreMenuFotoLabelCV { return listMenuFotoLabel.count } else if collectionView == self.moreMenuAplikasiCV { return listMenuAplikasi.count } else if collectionView == self.moreMenuSP2SertifikatCV { return listMenuSP2Sertifikat.count } else if collectionView == self.moreMenuSP2TambahanCV { return listMenuSP2Tambahan.count } else if collectionView == self.moreMenuDaftarRHUCV { return listMenuDaftarRHU.count } else if collectionView == self.moreMenuSertifikatCV { return listMenuSertifikat.count } else if collectionView == self.moreMenuSurveyCV { return listMenuSurvey.count } else { return 0 } } func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { if collectionView == self.mainMenuCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellId, for: indexPath) as? MenuCell { let menu = listMenuUtama[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuUtamaCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId, for: indexPath) as? MenuCell { let menu = listMenuUtama[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuAplikasiODSCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId, for: indexPath) as? MenuCell { let menu = listMenuAplikasiODS[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuFotoLabelCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuFotoLabelCellId, for: indexPath) as? MenuCell { let menu = listMenuFotoLabel[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuAplikasiCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuAplikasiCellId, for: indexPath) as? MenuCell { let menu = listMenuAplikasi[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuSP2SertifikatCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2SertifikatCellId, for: indexPath) as? MenuCell { let menu = listMenuSP2Sertifikat[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuSP2TambahanCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSP2TambahanCellId, for: indexPath) as? MenuCell { let menu = listMenuSP2Tambahan[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuDaftarRHUCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuDaftarRhuCellId, for: indexPath) as? MenuCell { let menu = listMenuDaftarRHU[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuSertifikatCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSertifikatCellId, for: indexPath) as? MenuCell { let menu = listMenuSertifikat[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else if collectionView == self.moreMenuSurveyCV { if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuSurveyCellId, for: indexPath) as? MenuCell { let menu = listMenuSurvey[indexPath.row] cell.updateViews(menu: menu) return cell } else { return MenuCell() } } else { return MenuCell() } } func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { var segueId = "" if collectionView == self.mainMenuCV { segueId = listMenuUtama[indexPath.row].segueId } else if collectionView == self.moreMenuUtamaCV { segueId = listMenuUtama[indexPath.row].segueId } else if collectionView == self.moreMenuAplikasiODSCV { segueId = listMenuAplikasiODS[indexPath.row].segueId } else if collectionView == self.moreMenuFotoLabelCV { segueId = listMenuFotoLabel[indexPath.row].segueId } else if collectionView == self.moreMenuAplikasiCV { segueId = listMenuAplikasi[indexPath.row].segueId } else if collectionView == self.moreMenuSP2SertifikatCV { segueId = listMenuSP2Sertifikat[indexPath.row].segueId } else if collectionView == self.moreMenuSP2TambahanCV { segueId = listMenuSP2Tambahan[indexPath.row].segueId } else if collectionView == self.moreMenuDaftarRHUCV { segueId = listMenuDaftarRHU[indexPath.row].segueId } else if collectionView == self.moreMenuSertifikatCV { segueId = listMenuSertifikat[indexPath.row].segueId } else if collectionView == self.moreMenuSurveyCV { segueId = listMenuSurvey[indexPath.row].segueId } if !segueId.isEmpty { if !loading { performSegue(withIdentifier: segueId, sender: self) } } } } // UITableController Protocols extension HomeVC: UITableViewDelegate, UITableViewDataSource { func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return listNews.count } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { if tableView == homeNewsTV { if let cell = tableView.dequeueReusableCell(withIdentifier: homeNewsCellId, for: indexPath) as? HomeNewsCell { let news = listNews[indexPath.row] cell.updateViews(news: news) return cell } else { return HomeNewsCell() } } else { return HomeNewsCell() } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let selectedNews = self.listNews[indexPath.row] self.selectedNewsId = selectedNews.id performSegue(withIdentifier: "homeToNewsDetailSegueId", sender: self) } }