| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094 |
- //
- // 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 moreMenuNewTitleLayout: UIView!
- @IBOutlet weak var moreMenuNewNotif: UIView!
- @IBOutlet weak var lblMoreMenuUtamaNewNotif: UILabel!
- @IBOutlet weak var moreMenuUtamaNewCV: UICollectionView!
- @IBOutlet weak var marginMoreMenuUtamaNew: UIView!
-
- @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 listMenuUtamaNew = [MenuItem]()
- 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 date = ""
- private var judul = ""
- private var urlThumb = ""
- 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)
-
- checkUserState()
-
- 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()
- 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 {
- setMoreMenuUtamaNew(userRoleId: userRoleId)
- // 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()
- setMoreMenuUtamaNew(userRoleId: userRoleId)
- // 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.date = self.date
- destVC.judul = self.judul
- destVC.urlThumb = self.urlThumb.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
- destVC.segueId = destVC.SEGUE_HOME_ID
- }
- }
-
- // private functions
- private func checkUserState() {
- let isLoggedIn = UserState.instance.isLoggedIn()
- if isLoggedIn {
- btnMoreMenu.show()
- } else {
- btnMoreMenu.hide()
- }
- }
-
- 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: 5, 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()
- }
- }
-
- private func setMoreMenuUtamaNew(userRoleId: String) {
- // notif
- moreMenuNewNotif.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
- moreMenuUtamaNewCV.collectionViewLayout = flowLayout
- moreMenuUtamaNewCV.delegate = self
- moreMenuUtamaNewCV.dataSource = self
- moreMenuUtamaNewCV.register(MenuCell.self, forCellWithReuseIdentifier: MenuListData.instance.menuUtamaCellNewId)
-
- listMenuUtamaNew = MenuListData.instance.getMenuUtamaNewData(userRoleId: userRoleId)
- if listMenuUtamaNew.count > 0 {
- moreMenuUtamaNewCV.reloadData()
- moreMenuNewTitleLayout.show()
- moreMenuUtamaNewCV.show()
- marginMoreMenuUtamaNew.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 {
- if let webpSource = SDWebImageSource(urlString: url) {
- sources.append(webpSource)
- }
- }
-
- 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.moreMenuUtamaNewCV {
- return listMenuUtamaNew.count
- }
- else 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.moreMenuUtamaNewCV {
- if let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MenuListData.instance.menuUtamaCellNewId, for: indexPath) as? MenuCell {
- let menu = listMenuUtamaNew[indexPath.row]
- cell.updateViews(menu: menu)
- return cell
- } else {
- return MenuCell()
- }
-
- } else 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.moreMenuUtamaNewCV {
- segueId = listMenuUtamaNew[indexPath.row].segueId
- } else 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
- self.date = selectedNews.dateNew()
- self.judul = selectedNews.title_news
- self.urlThumb = selectedNews.thumb_filename
- performSegue(withIdentifier: "homeToNewsDetailSegueId", sender: self)
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
- return 140
- }
- }
|