12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196 |
- //
- // ViewController.swift
- // TestQmeraLite
- //
- // Created by Qindi on 29/11/21.
- //
- import UIKit
- import NexilisLite
- import AVKit
- import AVFoundation
- import SwiftUI
- import Speech
- import Alamofire
- import WebKit
- class ViewController: UITabBarController, UITabBarControllerDelegate, SettingMABDelegate, WKNavigationDelegate {
- let playerController = AVPlayerViewController()
- static var sURL = "https://www.google.com"
- static var tab3 = "0"
- public var isShow: Bool = false
- public static var chatButton = UIButton()
- public static var callButton = UIButton()
- public static var ccButton = UIButton()
- public static var streamingButton = UIButton()
- public static var postButton = UIButton()
- public static var middleButton = UIButton()
- var buttonChatGR : UITapGestureRecognizer?
- var buttonCallGR : UITapGestureRecognizer?
- var buttonCCGR : UITapGestureRecognizer?
- var buttonStreamGR : UITapGestureRecognizer?
- var floating : FloatingButton?
- var firstTab : FirstTabViewController?
- var secondTab : SecondTabViewController?
- var thirdTab : ThirdTabViewController?
- var fourthTab : FourthTabViewController?
- let emptyTab = EmptyTabViewController()
- public static var isTab1 = true
- public static var isTab2 = false
- public static var isTab3 = false
- public static var isTab4 = false
- public static var isExpandButton = false
- public static var alwaysHideButton = false
- static var listPullFB: [String] = []
- static var datePullFB: Date?
- let welcomeVC = UIViewController()
- let privacyPolicyVC = UIViewController()
- var termVC: UIViewController?
- let welcomeDesc = UILabel()
- let termText = "Read our Terms of Service. Tap \"Agree and Continue\" to accept Terms of Service.".localized()
- let term = "Terms of Service.".localized()
- var firstLoad = true
- let privacyWV = WKWebView()
-
- public static var def: ViewController?
- override func viewDidLoad() {
- super.viewDidLoad()
- ViewController.def = self
- title = Bundle.main.displayName
- let customTab = PrefsUtil.getCustomTab().split(separator: ",")
- let cpaasMode = PrefsUtil.getCpaasMode()
- var tabs : [UIViewController] = []
- firstTab = storyboard?.instantiateViewController(withIdentifier: "firstTabVC") as? FirstTabViewController
- secondTab = storyboard?.instantiateViewController(withIdentifier: "secondTabVC") as? SecondTabViewController
- thirdTab = storyboard?.instantiateViewController(withIdentifier: "thirdTabVC") as? ThirdTabViewController
- fourthTab = storyboard?.instantiateViewController(withIdentifier: "fourthTabVC") as? FourthTabViewController
-
- self.delegate = self
-
-
- firstTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_1_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
- firstTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
- secondTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_2_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
- secondTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
- thirdTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_3_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
- thirdTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
- fourthTab?.tabBarItem.image = resizeImage(image: UIImage(named: "tab_4_icon")!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal)
- fourthTab?.tabBarItem.imageInsets = UIEdgeInsets.init(top: 5,left: 0,bottom: -5,right: 0)
- var i = 0
- var j = 0
- while j < customTab.count {
- if(((i == 1 && customTab.count == 3) || i == 2) &&
- (cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
- tabs.append(emptyTab)
- }
- else {
- switch(customTab[j]){
- case "1":
- tabs.append(firstTab!)
- case "2":
- tabs.append(secondTab!)
- case "3":
- tabs.append(thirdTab!)
- case "4":
- tabs.append(fourthTab!)
- default:
- break
- }
- j += 1
- }
- i += 1
- }
- if(cpaasMode == PrefsUtil.CPAAS_MODE_BURGER){
- navigationController?.setNavigationBarHidden(false, animated: false)
- print("cpaas mode burger")
- let childrenMenu : [UIAction] = [
- UIAction(title: "Contact Center", handler: {[weak self](_) in
- self?.ccTap()
- }),
- UIAction(title: "Chat", handler: {[weak self](_) in
- self?.chatTap()
- }),
- UIAction(title: "Call", handler: {[weak self](_) in
- self?.callTap()
- }),
- UIAction(title: "New Post", handler: {[weak self](_) in
- self?.postTap()
- }),
- UIAction(title: "Live Streaming", handler: {[weak self](_) in
- self?.streamTap()
- }),
- // UIAction(title: "Settings", handler: {[weak self](_) in
- // self?.settingTap()
- // }),
- ]
- let menu = UIMenu(title: "", children: childrenMenu)
- if PrefsUtil.getIconDock() != nil {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getUrlDock()!)!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() { [self] in
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
- }
- }
- }
- } else {
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
- }
- }
- if((cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
- createMidFloatingButton()
- navigationController?.setNavigationBarHidden(true, animated: false)
- }
- // if((cpaasMode == PrefsUtil.CPAAS_MODE_FLOATING || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)) {
- // let rect = CGRect(x: self.view.bounds.width - 100, y: self.view.bounds.height / 2, width: 50, height: 250)
- // floating = FloatingButton()
- // floating?.frame = rect
- // floating?.isShow = true
- //
- // view.addSubview(floating!)
- // navigationController?.setNavigationBarHidden(true, animated: false)
- // }
-
- self.setViewControllers(tabs, animated: false)
- if(cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX){
- if(customTab.count == 3){
- self.tabBar.items?[1].isEnabled = false
- }
- self.tabBar.items?[2].isEnabled = false
- }
- let numberOfItems = CGFloat(tabBar.items!.count)
- let tabBarItemSize = CGSize(width: tabBar.frame.width / numberOfItems, height: tabBar.frame.height)
- tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor.black.withAlphaComponent(0.2), size: tabBarItemSize).resizableImage(withCapInsets: .zero)
- if Bundle.main.displayName == "DigiNetS" {
- tabBar.selectionIndicatorImage = UIImage.imageWithColor(color: UIColor.gray, size: tabBarItemSize).resizableImage(withCapInsets: .zero)
- }
- UIFont.overrideInitialize()
- }
- // override func viewDidLayoutSubviews() {
- // super.viewDidLayoutSubviews()
- // tabBar.frame.size.height = 65
- // tabBar.frame.origin.y = view.frame.height - 65
- // }
-
- func settingDelegate() {
- if self.viewControllers?.firstIndex(of: fourthTab!) == nil {
- let vc = fourthTab!
- vc.notInTab = true
- self.navigationController?.show(vc, sender: nil)
- } else {
- self.selectedIndex = (self.viewControllers?.firstIndex(of: fourthTab!))!
- }
- }
-
- static var alertChangeProfile = UIAlertController()
-
- public static func checkIsChangePerson() -> Bool {
- let isChangeProfile = Utils.getSetProfile()
- if !isChangeProfile {
- alertChangeProfile.dismiss(animated: false)
- alertChangeProfile = UIAlertController(title: "Change Profile".localized(), message: "You must change your name to use this feature".localized().localized(), preferredStyle: .alert)
- alertChangeProfile.addAction(UIAlertAction(title: "Cancel".localized(), style: .destructive, handler: {_ in
- if ViewController.def?.viewControllers?.firstIndex(of: (ViewController.def?.firstTab)!) == ViewController.def?.selectedIndex {
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("if(resumeAll){resumeAll();}")
- }
- if ViewController.def?.viewControllers?.firstIndex(of: (ViewController.def?.thirdTab)!) == ViewController.def?.selectedIndex {
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("if(resumeAll){resumeAll();}")
- }
- }))
- alertChangeProfile.addAction(UIAlertAction(title: "OK".localized(), style: UIAlertAction.Style.default, handler: {(_) in
- ViewController.resetTabSelected()
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "signupsignin") as! SignUpSignIn
- controller.forceLogin = true
- controller.isDismiss = { newThumb in
- FirstTabViewController.forceRefresh = true
- ThirdTabViewController.forceRefresh = true
- }
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- ViewController.def?.show(b: false)
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- let rootVC = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
- if rootVC?.presentedViewController == nil {
- rootVC?.present(navigationController, animated: true, completion: nil)
- } else {
- rootVC?.presentedViewController?.present(navigationController, animated: true, completion: nil)
- }
- }))
- let rootVC = UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.rootViewController
- if rootVC?.presentedViewController == nil {
- rootVC?.present(alertChangeProfile, animated: true, completion: nil)
- } else {
- rootVC?.presentedViewController?.present(alertChangeProfile, animated: true, completion: nil)
- }
- return false
- }
- return true
- }
- public static func resetTabSelected(){
- ViewController.isTab1 = true
- ViewController.isTab2 = false
- ViewController.isTab3 = false
- ViewController.isTab4 = false
- // if ViewController.isTab1 {
- // ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis")!
- // }
- // else {
- // ViewController.imageTab1.image = UIImage(named: "tab_1_nexilis_off")!
- // }
- // if ViewController.isTab2 {
- // ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis")!
- // }
- // else {
- // ViewController.imageTab2.image = UIImage(named: "tab_2_nexilis_off")!
- // }
- // if ViewController.isTab3 {
- // ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis")!
- // }
- // else {
- // ViewController.imageTab3.image = UIImage(named: "tab_3_nexilis_off")!
- // }
- // if ViewController.isTab4 {
- // ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis")!
- // }
- // else {
- // ViewController.imageTab4.image = UIImage(named: "tab_4_nexilis_off")!
- // }
- }
-
- override func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
- let cpaasMode = PrefsUtil.getCpaasMode()
- let customTab = PrefsUtil.getCustomTab().split(separator: ",")
- if(cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX){
- if(customTab.count == 2){
- ViewController.isTab1 = item == tabBar.items?[0]
- ViewController.isTab2 = item == tabBar.items?[2]
- }
- else if(customTab.count == 3){
- ViewController.isTab1 = item == tabBar.items?[0]
- ViewController.isTab2 = item == tabBar.items?[2]
- ViewController.isTab3 = item == tabBar.items?[3]
- }
- else if(customTab.count == 4){
- ViewController.isTab1 = item == tabBar.items?[0]
- ViewController.isTab2 = item == tabBar.items?[1]
- ViewController.isTab3 = item == tabBar.items?[3]
- ViewController.isTab4 = item == tabBar.items?[4]
- }
- }
- else{
- ViewController.isTab1 = item == tabBar.items?[0]
- ViewController.isTab2 = item == tabBar.items?[1]
- if(customTab.count > 2){
- ViewController.isTab3 = item == tabBar.items?[2]
- }
- if(customTab.count > 3){
- ViewController.isTab4 = item == tabBar.items?[3]
- }
- }
- }
-
- func createMidFloatingButton(){
- ViewController.chatButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 22.5 , y: self.view.bounds.height - 80, width: 45, height: 45))
- ViewController.chatButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- ViewController.chatButton.layer.shadowColor = UIColor.black.cgColor
- ViewController.chatButton.layer.shadowOpacity = 0.1
- ViewController.chatButton.layer.shadowOffset = CGSize(width: 4, height: 4)
- ViewController.chatButton.addTarget(self, action: #selector(chatTap), for: .touchUpInside)
- ViewController.callButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 22.5 , y: self.view.bounds.height - 80, width: 45, height: 45))
- ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_call", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- ViewController.callButton.layer.shadowColor = UIColor.black.cgColor
- ViewController.callButton.layer.shadowOpacity = 0.1
- ViewController.callButton.layer.shadowOffset = CGSize(width: 4, height: 4)
- ViewController.callButton.addTarget(self, action: #selector(callTap), for: .touchUpInside)
- ViewController.ccButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 22.5 , y: self.view.bounds.height - 80, width: 45, height: 45))
- ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_cc", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- ViewController.ccButton.layer.shadowColor = UIColor.black.cgColor
- ViewController.ccButton.layer.shadowOpacity = 0.1
- ViewController.ccButton.layer.shadowOffset = CGSize(width: 4, height: 4)
- ViewController.ccButton.addTarget(self, action: #selector(ccTap), for: .touchUpInside)
- ViewController.streamingButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 22.5 , y: self.view.bounds.height - 80, width: 45, height: 45))
- ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_stream", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- ViewController.streamingButton.layer.shadowColor = UIColor.black.cgColor
- ViewController.streamingButton.layer.shadowOpacity = 0.1
- ViewController.streamingButton.layer.shadowOffset = CGSize(width: 4, height: 4)
- ViewController.streamingButton.addTarget(self, action: #selector(streamTap), for: .touchUpInside)
- ViewController.postButton = UIButton(frame: CGRect(x: self.view.bounds.width / 2 - 22.5 , y: self.view.bounds.height - 80, width: 45, height: 45))
- ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_post", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- ViewController.postButton.layer.shadowColor = UIColor.black.cgColor
- ViewController.postButton.layer.shadowOpacity = 0.1
- ViewController.postButton.layer.shadowOffset = CGSize(width: 4, height: 4)
- ViewController.postButton.addTarget(self, action: #selector(postTap), for: .touchUpInside)
- let buttonCenterX = self.view.bounds.width / 2
- let buttonCenterY = self.view.bounds.height - self.tabBar.bounds.height
- print("buttonCenterX \(buttonCenterX)")
- print("buttonCenterY \(buttonCenterY)")
- ViewController.middleButton = UIButton(frame: CGRect(x: buttonCenterX - 40 , y: buttonCenterY - 40, width: 80, height: 80))
- if PrefsUtil.getIconDock() != nil {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getUrlDock()!)!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- ViewController.middleButton.setBackgroundImage(UIImage(data: data), for: .normal)
- }
- }
- }
- } else {
- ViewController.middleButton.setBackgroundImage(UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil), for: .normal)
- }
- ViewController.middleButton.layer.shadowColor = UIColor.black.cgColor
- ViewController.middleButton.layer.shadowOffset = CGSize(width: 0.0, height: 2.0)
- ViewController.middleButton.layer.shadowOpacity = 1.0
- ViewController.middleButton.layer.shadowRadius = 5.0
- ViewController.middleButton.layer.masksToBounds = false
- ViewController.middleButton.layer.cornerRadius = 4.0
- ViewController.middleButton.addTarget(self, action: #selector(middleBtnTapped), for: .touchUpInside)
- let longPressMidButton = UILongPressGestureRecognizer(target: self, action: #selector(longPressMidBtn(gestureRecognizer:)))
- ViewController.middleButton.addGestureRecognizer(longPressMidButton)
- self.view.addSubview(ViewController.chatButton)
- self.view.addSubview(ViewController.callButton)
- self.view.addSubview(ViewController.ccButton)
- self.view.addSubview(ViewController.postButton)
- self.view.addSubview(ViewController.streamingButton)
- self.view.addSubview(ViewController.middleButton)
-
- ViewController.hideDockedButton()
- }
-
- @objc func longPressMidBtn(gestureRecognizer: UILongPressGestureRecognizer) {
- if gestureRecognizer.state == .began {
- if self.viewControllers?.firstIndex(of: fourthTab!) == nil {
- let vc = fourthTab!
- vc.notInTab = true
- self.navigationController?.show(vc, sender: nil)
- } else {
- self.selectedIndex = (self.viewControllers?.firstIndex(of: fourthTab!))!
- }
- }
- }
-
- func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
- if(viewController == secondTab){
- if(!ViewController.checkIsChangePerson()){
- return false
- }
- }
- return true
- }
-
- func tabBarController(_ tabBarController: UITabBarController, didSelect viewController: UIViewController) {
- if viewController != secondTab {
- let idxTabChat = self.viewControllers?.firstIndex(where: {$0 == secondTab})
- if idxTabChat != nil {
- let vcTabChats = self.viewControllers![idxTabChat!] as! SecondTabViewController
- if vcTabChats.searchController.isActive {
- vcTabChats.searchController.isActive = false
- }
- }
- }
- let cpaasMode = PrefsUtil.getCpaasMode()
- var childrenMenu = [UIAction]()
- if(cpaasMode == PrefsUtil.CPAAS_MODE_BURGER){
- print("cpaas mode burger")
- childrenMenu.append(contentsOf: [
- UIAction(title: "Contact Center", handler: {[weak self](_) in
- self?.ccTap()
- }),
- UIAction(title: "Chat", handler: {[weak self](_) in
- self?.chatTap()
- }),
- UIAction(title: "Call", handler: {[weak self](_) in
- self?.callTap()
- }),
- UIAction(title: "New Post", handler: {[weak self](_) in
- self?.postTap()
- }),
- UIAction(title: "Live Streaming", handler: {[weak self](_) in
- self?.streamTap()
- }),
- // UIAction(title: "Settings", handler: {[weak self](_) in
- // self?.settingTap()
- // }),
- ])
- if let vc = viewController as? SecondTabViewController {
- childrenMenu.append(contentsOf: vc.childrenMenu)
- }
- let menu = UIMenu(title: "", children: childrenMenu)
- if PrefsUtil.getIconDock() != nil {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getUrlDock()!)!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() { [self] in
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(data: data)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
- }
- }
- }
- } else {
- navigationItem.rightBarButtonItem = UIBarButtonItem(image: resizeImage(image: UIImage(named: "pb_button", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!, targetSize: CGSize(width: 25, height: 25)).withRenderingMode(.alwaysOriginal), primaryAction: .none, menu: menu)
- }
- }
- }
-
- override func viewWillAppear(_ animated: Bool) {
- let acceptTerm = PrefsUtil.getTerms()
- let enable_privacy_policy = PrefsUtil.getEnablePrivacyPolicy()
- if !acceptTerm {
- showWelocomeView()
- return
- } else if enable_privacy_policy && !PrefsUtil.getAgreePrivacyPolicy() {
- showPrivacyPolicyView()
- return
- } else {
- if !Utils.getForceAnonymous() && !Utils.getSetProfile() {
- let controller = AppStoryBoard.Palio.instance.instantiateViewController(withIdentifier: "changeDevice") as! ChangeDeviceViewController
- controller.forceLogin = true
- let navigationController = UINavigationController(rootViewController: controller)
- navigationController.navigationBar.tintColor = .white
- navigationController.navigationBar.barTintColor = .mainColor
- navigationController.navigationBar.isTranslucent = false
- navigationController.navigationBar.overrideUserInterfaceStyle = .dark
- navigationController.navigationBar.barStyle = .black
- let cancelButtonAttributes: [NSAttributedString.Key: Any] = [NSAttributedString.Key.foregroundColor: UIColor.white]
- UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes, for: .normal)
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.white]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .mainColor
- navigationController.modalPresentationStyle = .fullScreen
- navigationController.modalTransitionStyle = .crossDissolve
- self.present(navigationController, animated: true)
- return
- }
- }
- if firstLoad {
- firstLoad = false
- if PrefsUtil.getCpaasMode() == PrefsUtil.CPAAS_MODE_DOCKED {
- ViewController.pullActionButton()
- }
- self.selectedViewController?.viewWillAppear(false)
- } else {
- self.selectedViewController?.viewWillAppear(false)
- }
- }
-
- func showPrivacyPolicyView() {
- if let privacyView = privacyPolicyVC.view {
- let bgImage = UIImageView()
- privacyView.addSubview(bgImage)
- bgImage.anchor(top: privacyView.topAnchor, left: privacyView.leftAnchor, bottom: privacyView.bottomAnchor, right: privacyView.rightAnchor)
- bgImage.backgroundColor = .white
- DispatchQueue.global().async {
- if let listBg = PrefsUtil.getBackground() {
- if listBg.isEmpty {
- return
- }
- var bgChoosen = ""
- let arrayBg = listBg.split(separator: ",")
- bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getURLBase() + "/dashboardv2/uploads/background/" + bgChoosen)!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- bgImage.image = UIImage(data: data)!
- }
- }
- }
- }
-
- let containerButton = UIView()
- privacyView.addSubview(containerButton)
- containerButton.anchor(left: privacyView.safeAreaLayoutGuide.leftAnchor, bottom: privacyView.safeAreaLayoutGuide.bottomAnchor, paddingLeft: 10, paddingBottom: 10, minHeight: 40)
- containerButton.rightAnchor.constraint(lessThanOrEqualTo: privacyView.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
- containerButton.isUserInteractionEnabled = true
- let tapgestureAgree = UITapGestureRecognizer(target: self, action: #selector(tappedOnAgreePrivacy(_ :)))
- tapgestureAgree.numberOfTapsRequired = 1
- containerButton.addGestureRecognizer(tapgestureAgree)
-
- let imageAgree = UIImageView()
- imageAgree.image = UIImage(systemName: "arrow.forward.circle")
- imageAgree.tintColor = .black
- containerButton.addSubview(imageAgree)
- imageAgree.anchor(left: containerButton.leftAnchor, centerY: containerButton.centerYAnchor, width: 40, height: 40)
-
- let titleAgree = UILabel()
- titleAgree.text = "Agree and Continue".localized()
- titleAgree.textColor = .black
- containerButton.addSubview(titleAgree)
- titleAgree.anchor(left: imageAgree.rightAnchor, right: containerButton.rightAnchor, paddingLeft: 5, centerY: containerButton.centerYAnchor)
-
- privacyWV.isOpaque = false
- privacyWV.backgroundColor = UIColor.clear
- privacyWV.scrollView.backgroundColor = UIColor.clear
- print("URL: \(PrefsUtil.getURLPrivacyPolicy())")
- let lang = UserDefaults.standard.string(forKey: "i18n_language")
- var urlPrivacyPolicy = PrefsUtil.getURLPrivacyPolicy()
- if lang == "id" {
- urlPrivacyPolicy = urlPrivacyPolicy.replacingOccurrences(of: "/en/", with: "/id/")
- }
- privacyWV.load(URLRequest(url: URL(string: urlPrivacyPolicy)!))
- privacyView.addSubview(privacyWV)
- privacyWV.navigationDelegate = self
- privacyWV.anchor(top: privacyView.safeAreaLayoutGuide.topAnchor, left: privacyView.leftAnchor, right: privacyView.rightAnchor, height: privacyView.bounds.height - 80)
-
- }
- privacyPolicyVC.modalPresentationStyle = .fullScreen
- privacyPolicyVC.modalTransitionStyle = .crossDissolve
- self.present(privacyPolicyVC, animated: true)
- }
-
- func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
- let js = "(function() { document.body.style.background='transparent'; })();"
- privacyWV.evaluateJavaScript(js) { (_, error) in
- print(error)
- }
- }
-
- func showWelocomeView() {
- if let viewWelcome = welcomeVC.view {
- let bgImage = UIImageView()
- viewWelcome.addSubview(bgImage)
- bgImage.anchor(top: viewWelcome.topAnchor, left: viewWelcome.leftAnchor, bottom: viewWelcome.bottomAnchor, right: viewWelcome.rightAnchor)
- bgImage.backgroundColor = .white
- DispatchQueue.global().async {
- if let listBg = PrefsUtil.getBackground() {
- if listBg.isEmpty {
- return
- }
- var bgChoosen = ""
- let arrayBg = listBg.split(separator: ",")
- bgChoosen = String(arrayBg[Int.random(in: 0..<arrayBg.count)])
- ViewController.getDataImageFromUrl(from: URL(string: PrefsUtil.getURLBase() + "/dashboardv2/uploads/background/" + bgChoosen)!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- bgImage.image = UIImage(data: data)!
- }
- }
- }
- }
- let welcomeTitle = UILabel()
- welcomeTitle.text = "Welcome to".localized() + " " + (Bundle.main.displayName ?? "")
- welcomeTitle.font = .systemFont(ofSize: 25, weight: .bold)
- welcomeTitle.numberOfLines = 0
- viewWelcome.addSubview(welcomeTitle)
- welcomeTitle.anchor(top: viewWelcome.safeAreaLayoutGuide.topAnchor, left: viewWelcome.safeAreaLayoutGuide.leftAnchor, right: viewWelcome.safeAreaLayoutGuide.rightAnchor, paddingTop: 10, paddingLeft: 10, paddingRight: 10)
-
- let logoImage = UIImageView()
- logoImage.image = UIImage(named: getHighResolutionAppIconName() ?? "")
- viewWelcome.addSubview(logoImage)
- logoImage.anchor(centerX: viewWelcome.centerXAnchor, centerY: viewWelcome.centerYAnchor, width: 200, height: 200)
-
- let containerButton = UIView()
- viewWelcome.addSubview(containerButton)
- containerButton.anchor(left: viewWelcome.safeAreaLayoutGuide.leftAnchor, bottom: viewWelcome.safeAreaLayoutGuide.bottomAnchor, paddingLeft: 10, paddingBottom: 10, minHeight: 40)
- containerButton.rightAnchor.constraint(lessThanOrEqualTo: viewWelcome.safeAreaLayoutGuide.rightAnchor, constant: -10).isActive = true
- containerButton.isUserInteractionEnabled = true
- let tapgestureAgree = UITapGestureRecognizer(target: self, action: #selector(tappedOnAgree(_ :)))
- tapgestureAgree.numberOfTapsRequired = 1
- containerButton.addGestureRecognizer(tapgestureAgree)
-
- let imageAgree = UIImageView()
- imageAgree.image = UIImage(systemName: "arrow.forward.circle")
- imageAgree.tintColor = .black
- containerButton.addSubview(imageAgree)
- imageAgree.anchor(left: containerButton.leftAnchor, centerY: containerButton.centerYAnchor, width: 40, height: 40)
-
- let titleAgree = UILabel()
- titleAgree.text = "Agree and Continue".localized()
- titleAgree.textColor = .black
- containerButton.addSubview(titleAgree)
- titleAgree.anchor(left: imageAgree.rightAnchor, right: containerButton.rightAnchor, paddingLeft: 5, centerY: containerButton.centerYAnchor)
-
- let formattedText = String.format(strings: [term], inString: termText)
- welcomeDesc.isUserInteractionEnabled = true
- welcomeDesc.attributedText = formattedText
- welcomeDesc.numberOfLines = 0
- viewWelcome.addSubview(welcomeDesc)
- welcomeDesc.anchor(left: viewWelcome.safeAreaLayoutGuide.leftAnchor, bottom: containerButton.topAnchor, right: viewWelcome.rightAnchor, paddingLeft: 10, paddingBottom: 10, paddingRight: 10)
- let tapgesture = UITapGestureRecognizer(target: self, action: #selector(tappedOnLabelTerms(_ :)))
- tapgesture.numberOfTapsRequired = 1
- welcomeDesc.addGestureRecognizer(tapgesture)
-
- }
- welcomeVC.modalPresentationStyle = .fullScreen
- welcomeVC.modalTransitionStyle = .crossDissolve
- self.present(welcomeVC, animated: true)
- }
-
- func getHighResolutionAppIconName() -> String? {
- guard let infoPlist = Bundle.main.infoDictionary else { return nil }
- guard let bundleIcons = infoPlist["CFBundleIcons"] as? NSDictionary else { return nil }
- guard let bundlePrimaryIcon = bundleIcons["CFBundlePrimaryIcon"] as? NSDictionary else { return nil }
- guard let bundleIconFiles = bundlePrimaryIcon["CFBundleIconFiles"] as? NSArray else { return nil }
- guard let appIcon = bundleIconFiles.lastObject as? String else { return nil }
- return appIcon
- }
-
- func showWebviewTerm() {
- termVC = UIViewController()
- if let viewTerm = termVC!.view {
- let webView = WKWebView()
- let lang = UserDefaults.standard.string(forKey: "i18n_language")
- var urlTerm = "https://newuniverse.io/newuniverse-tos"
- if lang == "id" {
- urlTerm = "https://newuniverse.io/newuniverse-tos-id"
- }
- let url = URL (string: urlTerm)
- let requestObj = URLRequest(url: url!)
- webView.load(requestObj)
- viewTerm.addSubview(webView)
- webView.anchor(top: viewTerm.safeAreaLayoutGuide.topAnchor, left: viewTerm.safeAreaLayoutGuide.leftAnchor, bottom: viewTerm.safeAreaLayoutGuide.bottomAnchor, right: viewTerm.safeAreaLayoutGuide.rightAnchor)
- }
- let navigationController = UINavigationController(rootViewController: termVC!)
- navigationController.navigationBar.tintColor = .mainColor
- navigationController.navigationBar.barTintColor = .white
- navigationController.navigationBar.isTranslucent = false
- let textAttributes = [NSAttributedString.Key.foregroundColor:UIColor.mainColor]
- navigationController.navigationBar.titleTextAttributes = textAttributes
- navigationController.view.backgroundColor = .white
- termVC!.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Close".localized(), style: .plain, target: self, action: #selector(closeTerm))
- welcomeVC.present(navigationController, animated: true)
- }
-
- @objc func closeTerm() {
- termVC!.dismiss(animated: true)
- }
-
- @objc func tappedOnLabelTerms(_ gesture: UITapGestureRecognizer) {
- let termString = termText as NSString
- let termRange = termString.range(of: term)
- let tapLocation = gesture.location(in: welcomeDesc)
- let index = welcomeDesc.indexOfAttributedTextCharacterAtPoint(point: tapLocation)
-
- if checkRange(termRange, contain: index) == true {
- showWebviewTerm()
- return
- }
- }
-
- @objc func tappedOnAgree(_ gesture: UITapGestureRecognizer) {
- PrefsUtil.setTerms(value: true)
- welcomeVC.dismiss(animated: true)
- }
-
- @objc func tappedOnAgreePrivacy(_ gesture: UITapGestureRecognizer) {
- PrefsUtil.setAgreePrivacyPolicy(value: true)
- privacyPolicyVC.dismiss(animated: true)
- }
-
- func checkRange(_ range: NSRange, contain index: Int) -> Bool {
- return index > range.location && index < range.location + range.length
- }
-
- @objc func middleBtnTapped() {
- ViewController.expandButton()
- }
- public func show(b: Bool) {
- if(!b){
- if(ViewController.isExpandButton){
- ViewController.expandButton()
- }
- }
- }
-
- @objc func ccTap() {
- print("ccTap")
- if(ViewController.checkIsChangePerson()){
- show(b: false)
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 2 {
- let package_id = ViewController.listPullFB[2].split(separator: "|")[0]
- var app_id = ""
- if ViewController.listPullFB[2].split(separator: "|").count > 1 {
- app_id = String(ViewController.listPullFB[2].split(separator: "|")[1])
- }
- if package_id.contains("_fb") {
- let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
- if indexTap == 99 {
- openTabPost()
- } else {
- if indexTap == 2 {
- let url = package_id.components(separatedBy: "_")[2]
- Nexilis.buttonClicked(index: indexTap, id: url)
- } else {
- Nexilis.buttonClicked(index: indexTap)
- }
- }
- } else {
- if !app_id.isEmpty {
- Nexilis.buttonClicked(index: 0, id: app_id)
- }
- }
- } else {
- Nexilis.buttonClicked(index: 9)
- }
- }
- }
-
- @objc func streamTap() {
- print("streamTap")
- if(ViewController.checkIsChangePerson()){
- show(b: false)
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 4 {
- let package_id = ViewController.listPullFB[4].split(separator: "|")[0]
- var app_id = ""
- if ViewController.listPullFB[4].split(separator: "|").count > 1 {
- app_id = String(ViewController.listPullFB[4].split(separator: "|")[1])
- }
- if package_id.contains("_fb") {
- let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
- if indexTap == 99 {
- openTabPost()
- } else {
- if indexTap == 2 {
- let url = package_id.components(separatedBy: "_")[2]
- Nexilis.buttonClicked(index: indexTap, id: url)
- } else {
- Nexilis.buttonClicked(index: indexTap)
- }
- }
- } else {
- if !app_id.isEmpty {
- Nexilis.buttonClicked(index: 0, id: app_id)
- }
- }
- } else {
- Nexilis.buttonClicked(index: 8)
- }
- }
- }
-
- @objc func callTap() {
- print("callTap")
- if(ViewController.checkIsChangePerson()){
- show(b: false)
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 1 {
- let package_id = ViewController.listPullFB[1].split(separator: "|")[0]
- var app_id = ""
- if ViewController.listPullFB[1].split(separator: "|").count > 1 {
- app_id = String(ViewController.listPullFB[1].split(separator: "|")[1])
- }
- if package_id.contains("_fb") {
- let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
- if indexTap == 99 {
- openTabPost()
- } else {
- if indexTap == 2 {
- let url = package_id.components(separatedBy: "_")[2]
- Nexilis.buttonClicked(index: indexTap, id: url)
- } else {
- Nexilis.buttonClicked(index: indexTap)
- }
- }
- } else {
- if !app_id.isEmpty {
- Nexilis.buttonClicked(index: 0, id: app_id)
- }
- }
- } else {
- Nexilis.buttonClicked(index: 7)
- }
- }
- }
-
- @objc func chatTap() {
- print("chatTap")
- if(ViewController.checkIsChangePerson()){
- show(b: false)
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 0 {
- let package_id = ViewController.listPullFB[0].split(separator: "|")[0]
- var app_id = ""
- if ViewController.listPullFB[0].split(separator: "|").count > 1 {
- app_id = String(ViewController.listPullFB[0].split(separator: "|")[1])
- }
- if package_id.contains("_fb") {
- let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
- if indexTap == 99 {
- openTabPost()
- } else {
- if indexTap == 2 {
- let url = package_id.components(separatedBy: "_")[2]
- Nexilis.buttonClicked(index: indexTap, id: url)
- } else {
- Nexilis.buttonClicked(index: indexTap)
- }
- }
- } else {
- if !app_id.isEmpty {
- Nexilis.buttonClicked(index: 0, id: app_id)
- }
- }
- } else {
- Nexilis.buttonClicked(index: 6)
- }
- }
- }
-
- @objc func postTap() {
- if(ViewController.checkIsChangePerson()){
- show(b: false)
- ViewController.def?.thirdTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- ViewController.def?.firstTab?.webView?.evaluateJavaScript("{if(pauseAll){pauseAll();}}")
- if ViewController.listPullFB.count != 0 && ViewController.listPullFB.count > 3 {
- let package_id = ViewController.listPullFB[3].split(separator: "|")[0]
- var app_id = ""
- if ViewController.listPullFB[3].split(separator: "|").count > 1 {
- app_id = String(ViewController.listPullFB[3].split(separator: "|")[1])
- }
- if package_id.contains("_fb") {
- let indexTap = Int(String(package_id.split(separator: "_")[1]).substring(from: 2, to: 2))!
- if indexTap == 99 {
- openTabPost()
- } else {
- if indexTap == 2 {
- let url = package_id.components(separatedBy: "_")[2]
- Nexilis.buttonClicked(index: indexTap, id: url)
- } else {
- Nexilis.buttonClicked(index: indexTap)
- }
- }
- } else {
- if !app_id.isEmpty {
- Nexilis.buttonClicked(index: 0, id: app_id)
- }
- }
- } else {
- openTabPost()
- }
- }
-
- }
-
- func openTabPost() {
- let customTab = PrefsUtil.getCustomTab().split(separator: ",")
- let cpaasMode = PrefsUtil.getCpaasMode()
- var i = 0
- var j = 0
- print("custom tab post tap = \(customTab)")
- while j < customTab.count {
- if(((i == 1 && customTab.count == 3) || i == 2) &&
- (cpaasMode == PrefsUtil.CPAAS_MODE_DOCKED || cpaasMode == PrefsUtil.CPAAS_MODE_MIX)){
-
- }
- else {
- if customTab[j] == "3" {
- break
- }
- j += 1
- }
- i += 1
- }
- if(j < customTab.count){
- self.selectedIndex = i
-
- DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + .seconds(1), execute: {
- let me = UserDefaults.standard.string(forKey: "me")
- let address = "\(PrefsUtil.getURLBase())nexilis/pages/tab5-new-post?f_pin=\(me ?? "")"
- self.thirdTab?.webView.evaluateJavaScript("window.location = '\(address)'")
-
- })
- }
- }
-
- static func pullActionButton() {
- if datePullFB == nil || Int(Date().timeIntervalSince(datePullFB!)) >= 60 {
- datePullFB = Date()
- DispatchQueue.global().async {
- if let response = Nexilis.writeSync(message: CoreMessage_TMessageBank.pullFloatingButton(), timeout: 30 * 1000) {
- if response.isOk() {
- let data = response.getBody(key: CoreMessage_TMessageKey.DATA, default_value: "")
- if !data.isEmpty {
- if let jsonArray = try! JSONSerialization.jsonObject(with: data.data(using: String.Encoding.utf8)!, options: JSONSerialization.ReadingOptions()) as? [AnyObject] {
- DispatchQueue.main.async { [self] in
- listPullFB.removeAll()
- if jsonArray.count != 0 {
- var count = 0
- for json in jsonArray {
- let package_id = json["package_act"] as! String
- let app_id = (json["app_id"] as? String) ?? ""
- let icon = (json["icon"] as? String) ?? ""
- listPullFB.append("\(package_id)|\(app_id)")
- if count == 0 {
- if !icon.isEmpty {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- ViewController.chatButton.setBackgroundImage(UIImage(data: data), for: .normal)
- }
- }
- }
- } else {
- ViewController.chatButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- }
- } else if count == 1 {
- if !icon.isEmpty {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- ViewController.callButton.setBackgroundImage(UIImage(data: data), for: .normal)
- }
- }
- }
- } else {
- ViewController.callButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- }
- } else if count == 2 {
- if !icon.isEmpty {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- ViewController.ccButton.setBackgroundImage(UIImage(data: data), for: .normal)
- }
- }
- }
- } else {
- ViewController.ccButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- }
- } else if count == 3 {
- if !icon.isEmpty {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- ViewController.postButton.setBackgroundImage(UIImage(data: data), for: .normal)
- }
- }
- }
- } else {
- ViewController.postButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- }
- } else if count == 4 {
- if !icon.isEmpty {
- DispatchQueue.global().async {
- ViewController.getDataImageFromUrl(from: URL(string: "http://\(Nexilis.ADDRESS)/filepalio/image/\(icon)")!) { data, response, error in
- guard let data = data, error == nil else { return }
- // always update the UI from the main thread
- DispatchQueue.main.async() {
- ViewController.streamingButton.setBackgroundImage(UIImage(data: data), for: .normal)
- }
- }
- }
- } else {
- ViewController.streamingButton.setBackgroundImage(UIImage(named: "pb_button_chat", in: Bundle.resourceBundle(for: Nexilis.self), with: nil)!.withRenderingMode(.alwaysOriginal), for: .normal)
- }
- }
- count += 1
- }
- }
- }
- }
- }
- }
- }
- }
- }
- }
-
- public static func showDockedButton() {
- ViewController.chatButton.isHidden = false
- ViewController.callButton.isHidden = false
- ViewController.ccButton.isHidden = false
- ViewController.streamingButton.isHidden = false
- ViewController.postButton.isHidden = false
- }
-
- public static func hideDockedButton() {
- ViewController.chatButton.isHidden = true
- ViewController.callButton.isHidden = true
- ViewController.ccButton.isHidden = true
- ViewController.streamingButton.isHidden = true
- ViewController.postButton.isHidden = true
- }
-
- public static func expandButton() {
- let cpaasMode = PrefsUtil.getCpaasMode()
- if cpaasMode != PrefsUtil.CPAAS_MODE_DOCKED && cpaasMode != PrefsUtil.CPAAS_MODE_MIX {
- return
- }
- if ViewController.alwaysHideButton && !ViewController.isExpandButton {
- return
- }
- if ViewController.isExpandButton {
- ViewController.isExpandButton = false
- let xChatPosition = ViewController.chatButton.frame.origin.x + 90
- let yChatPosition = ViewController.chatButton.frame.origin.y + 20
- let xCallPosition = ViewController.callButton.frame.origin.x + 55
- let yCallPosition = ViewController.callButton.frame.origin.y + 70
- let xCCPosition = ViewController.ccButton.frame.origin.x
- let yCCPosition = ViewController.ccButton.frame.origin.y + 90
- let xPostPosition = ViewController.postButton.frame.origin.x - 55
- let yPostPosition = ViewController.postButton.frame.origin.y + 70
- let xStreamingPosition = ViewController.streamingButton.frame.origin.x - 90
- let yStreamingPosition = ViewController.streamingButton.frame.origin.y + 20
- UIView.animate(withDuration: 0.5, animations: {
- // if !ViewController.isBlue {
- // ViewController.middleButton.transform = CGAffineTransform(rotationAngle: 0)
- // }
- ViewController.chatButton.frame.origin = CGPoint(x: xChatPosition, y: yChatPosition)
- ViewController.callButton.frame.origin = CGPoint(x: xCallPosition, y: yCallPosition)
- ViewController.ccButton.frame.origin = CGPoint(x: xCCPosition, y: yCCPosition)
- ViewController.streamingButton.frame.origin = CGPoint(x: xStreamingPosition, y: yStreamingPosition)
- ViewController.postButton.frame.origin = CGPoint(x: xPostPosition, y: yPostPosition)
- })
- DispatchQueue.main.asyncAfter(deadline: .now() + 0.5, execute: {
- if !ViewController.isExpandButton {
- ViewController.hideDockedButton()
- }
- })
- } else {
- ViewController.isExpandButton = true
- ViewController.showDockedButton()
- let xChatPosition = ViewController.chatButton.frame.origin.x - 90
- let yChatPosition = ViewController.chatButton.frame.origin.y - 20
- let xCallPosition = ViewController.callButton.frame.origin.x - 55
- let yCallPosition = ViewController.callButton.frame.origin.y - 70
- let xCCPosition = ViewController.ccButton.frame.origin.x
- let yCCPosition = ViewController.ccButton.frame.origin.y - 90
- let xPostPosition = ViewController.postButton.frame.origin.x + 55
- let yPostPosition = ViewController.postButton.frame.origin.y - 70
- let xStreamingPosition = ViewController.streamingButton.frame.origin.x + 90
- let yStreamingPosition = ViewController.streamingButton.frame.origin.y - 20
- UIView.animate(withDuration: 0.5, animations: {
- // if !ViewController.isBlue{
- // ViewController.middleButton.transform = CGAffineTransform(rotationAngle: .pi / 2)
- // }
- ViewController.chatButton.frame.origin = CGPoint(x: xChatPosition, y: yChatPosition)
- ViewController.callButton.frame.origin = CGPoint(x: xCallPosition, y: yCallPosition)
- ViewController.ccButton.frame.origin = CGPoint(x: xCCPosition, y: yCCPosition)
- ViewController.streamingButton.frame.origin = CGPoint(x: xStreamingPosition, y: yStreamingPosition)
- ViewController.postButton.frame.origin = CGPoint(x: xPostPosition, y: yPostPosition)
- })
- }
- }
-
- public static func removeMiddleButton() {
- // ViewController.chatButton.removeFromSuperview()
- // ViewController.callButton.removeFromSuperview()
- // ViewController.ccButton.removeFromSuperview()
- // ViewController.streamingButton.removeFromSuperview()
- // ViewController.postButton.removeFromSuperview()
- ViewController.middleButton.isHidden = true
- }
-
- public static func getDataImageFromUrl(from url: URL, completion: @escaping (Data?, URLResponse?, Error?) -> ()) {
- URLSession.shared.dataTask(with: url, completionHandler: completion).resume()
- }
- }
- class EmptyTabViewController: UIViewController {
- override func viewDidLoad() {
-
- }
- }
-
- extension Bundle {
- // Name of the app - title under the icon.
- var displayName: String? {
- return object(forInfoDictionaryKey: "CFBundleDisplayName") as? String ??
- object(forInfoDictionaryKey: "CFBundleName") as? String
- }
- }
- extension BinaryInteger {
- var degreesToRadians: CGFloat { CGFloat(self) * .pi / 180 }
- }
- extension FloatingPoint {
- var degreesToRadians: Self { self * .pi / 180 }
- var radiansToDegrees: Self { self * 180 / .pi }
- }
- extension UIImage {
- class func imageWithColor(color: UIColor, size: CGSize) -> UIImage {
- let rect: CGRect = CGRect(x: 0, y: 0, width: size.width, height: size.height)
- UIGraphicsBeginImageContextWithOptions(size, false, 0)
- color.setFill()
- UIRectFill(rect)
- let image: UIImage = UIGraphicsGetImageFromCurrentImageContext()!
- UIGraphicsEndImageContext()
- return image
- }
- }
- extension String {
- static func format(strings: [String],
- italicFont: UIFont = UIFont.italicSystemFont(ofSize: 12),
- italicColor: UIColor = UIColor.systemGreen,
- inString string: String,
- font: UIFont = UIFont.systemFont(ofSize: 12),
- color: UIColor = UIColor.black) -> NSAttributedString {
- let attributedString =
- NSMutableAttributedString(string: string,
- attributes: [
- NSAttributedString.Key.font: font,
- NSAttributedString.Key.foregroundColor: color])
- let italicFontAttribute = [NSAttributedString.Key.font: italicFont, NSAttributedString.Key.foregroundColor: italicColor]
- for italic in strings {
- attributedString.addAttributes(italicFontAttribute, range: (string as NSString).range(of: italic))
- }
- return attributedString
- }
- }
- extension UILabel {
- func indexOfAttributedTextCharacterAtPoint(point: CGPoint) -> Int {
- assert(self.attributedText != nil, "This method is developed for attributed string")
- let textStorage = NSTextStorage(attributedString: self.attributedText!)
- let layoutManager = NSLayoutManager()
- textStorage.addLayoutManager(layoutManager)
- let textContainer = NSTextContainer(size: self.frame.size)
- textContainer.lineFragmentPadding = 0
- textContainer.maximumNumberOfLines = self.numberOfLines
- textContainer.lineBreakMode = self.lineBreakMode
- layoutManager.addTextContainer(textContainer)
- let index = layoutManager.characterIndex(for: point, in: textContainer, fractionOfDistanceBetweenInsertionPoints: nil)
- return index
- }
- }
|