| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024 |
- //
- // 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..<listMenuAplikasiODS.count {
- listMenuAplikasiODS[i].totalNotif = 0
- }
- for i in 0..<listMenuFotoLabel.count {
- listMenuFotoLabel[i].totalNotif = 0
- }
- for i in 0..<listMenuAplikasi.count {
- listMenuAplikasi[i].totalNotif = 0
- }
- for i in 0..<listMenuSP2Sertifikat.count {
- listMenuSP2Sertifikat[i].totalNotif = 0
- }
- for i in 0..<listMenuSP2Tambahan.count {
- listMenuSP2Tambahan[i].totalNotif = 0
- }
- for i in 0..<listMenuDaftarRHU.count {
- listMenuDaftarRHU[i].totalNotif = 0
- }
- for i in 0..<listMenuSertifikat.count {
- listMenuSertifikat[i].totalNotif = 0
- }
- for i in 0..<listMenuSurvey.count {
- listMenuSurvey[i].totalNotif = 0
- }
-
- moreMenuAplikasiODSCV.reloadData()
- moreMenuFotoLabelCV.reloadData()
- moreMenuAplikasiCV.reloadData()
- moreMenuSP2SertifikatCV.reloadData()
- moreMenuSP2TambahanCV.reloadData()
- moreMenuDaftarRHUCV.reloadData()
- moreMenuSertifikatCV.reloadData()
- moreMenuSurveyCV.reloadData()
- }
-
- private func setMoreMainMenu() {
- 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
- moreMenuUtamaCV.collectionViewLayout = flowLayout
- moreMenuUtamaCV.delegate = self
- moreMenuUtamaCV.dataSource = self
- moreMenuUtamaCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.moreMenuUtamaCellId)
- }
-
- private func setMoreMenuAplikasiODS(userRoleId: String) {
- // notif
- moreMenuOdsNotif.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
- moreMenuAplikasiODSCV.collectionViewLayout = flowLayout
- moreMenuAplikasiODSCV.delegate = self
- moreMenuAplikasiODSCV.dataSource = self
- moreMenuAplikasiODSCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuAplikasiODSCellId)
-
- listMenuAplikasiODS = MenuListData.instance.getMenuAplikasiOdsData(userRoleId: userRoleId)
- if listMenuAplikasiODS.count > 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)
- }
- }
|