O2AppViewController.swift 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. //
  2. // O2AppViewController.swift
  3. // O2Platform
  4. //
  5. // Created by 刘振兴 on 16/7/25.
  6. // Copyright © 2016年 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import WebKit
  10. import SwiftyJSON
  11. import Alamofire
  12. import ObjectMapper
  13. import AlamofireObjectMapper
  14. import CocoaLumberjack
  15. class O2AppViewController: UIViewController{
  16. @IBOutlet weak var collectionView: UICollectionView!
  17. private let reuseIdentifier = "myCell"
  18. // let loadUrl1 = AppDelegate.o2Collect.genrateURLWithWebContextKey2(ApplicationContext.applicationListQuery2,parameter: nil)
  19. //
  20. // let loadUrl2 = AppDelegate.o2Collect.generateURLWithAppContextKey(ApplicationContext.applicationContextKey2, query: ApplicationContext.applicationListQueryForPortal, parameter: nil)
  21. fileprivate let collectionViewDelegate = ZLCollectionView()
  22. var o2apps:[O2App] = []
  23. var apps2:[[O2App]] = [[],[]]
  24. override func viewDidLoad() {
  25. super.viewDidLoad()
  26. self.title = "应用"
  27. navigationItem.rightBarButtonItem = UIBarButtonItem(title: "编辑", style: .plain, target: self, action: #selector(_forwardEditSegue))
  28. //self.collectionView.contentInset = UIEdgeInsetsMake(160, 0, 0, 0)
  29. self.collectionViewDelegate.delegate = self
  30. //self.collectionViewDelegate.cellHeight = Float(self.collectionViewDelegate.ItemWithSize) * 2
  31. self.collectionView.dataSource = self.collectionViewDelegate
  32. self.collectionView.delegate = self.collectionViewDelegate
  33. self.o2apps = []
  34. self.apps2 = []
  35. //self.loadAppConfigDb()
  36. }
  37. override func viewWillAppear(_ animated: Bool) {
  38. super.viewWillAppear(animated)
  39. self.loadAppConfigDb()
  40. }
  41. func loadAppConfigDb() {
  42. let mainApps = OOAppsInfoDB.shareInstance.queryMainData()
  43. o2apps = mainApps
  44. let allApps = OOAppsInfoDB.shareInstance.queryData()
  45. apps2 = [mainApps,allApps]
  46. self.collectionViewDelegate.apps = apps2
  47. DispatchQueue.main.async {
  48. self.collectionView.reloadData()
  49. }
  50. }
  51. @objc private func _forwardEditSegue() {
  52. self.performSegue(withIdentifier: "showAppEditSegue", sender: nil)
  53. }
  54. override func didReceiveMemoryWarning() {
  55. super.didReceiveMemoryWarning()
  56. }
  57. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  58. if segue.identifier == "showMailSegue" {
  59. MailViewController.app = sender as? O2App
  60. }
  61. }
  62. @IBAction func unBackAppsForApps(_ segue:UIStoryboardSegue){
  63. DDLogDebug("返回应用列表")
  64. }
  65. }
  66. extension O2AppViewController:ZLCollectionViewDelegate{
  67. func clickWithApp(_ app: O2App) {
  68. //设置返回标志,其它应用根据此返回标志调用返回unwindSegue
  69. AppConfigSettings.shared.appBackType = 2
  70. if let segueIdentifier = app.segueIdentifier,segueIdentifier != "" { // portal 门户 走这边
  71. if app.storyBoard! == "webview" { // 打开MailViewController
  72. DDLogDebug("open webview for : "+app.title!+" url: "+app.vcName!)
  73. self.performSegue(withIdentifier: segueIdentifier, sender: app)
  74. }else {
  75. self.performSegue(withIdentifier: segueIdentifier, sender: nil)
  76. }
  77. } else {
  78. if app.storyBoard! == "webview" {
  79. DDLogDebug("open webview for : "+app.title!+" url: "+app.vcName!)
  80. let webConfiguration = WKWebViewConfiguration()
  81. let myURL = URL(string: app.vcName!)
  82. let webView = WKWebView(frame: self.view.bounds, configuration: webConfiguration)
  83. let myRequest = URLRequest(url: myURL!)
  84. webView.load(myRequest)
  85. self.view.addSubview(webView)
  86. } else {
  87. // 内置应用走这边 根据appkey 打开对应的storyboard
  88. // 语音助手还没做
  89. if app.appId == "o2ai" {
  90. DDLogInfo("语音助手还没做,,,,,,,,,,,,,,,,")
  91. // self.showError(title: "语音助手正在开发中......")
  92. // return
  93. app.storyBoard = "ai"
  94. }
  95. let story = O2AppUtil.apps.first { (appInfo) -> Bool in
  96. return app.appId == appInfo.appId
  97. }
  98. var storyBoardName = app.storyBoard
  99. if story != nil {
  100. storyBoardName = story?.storyBoard
  101. }
  102. DDLogDebug("storyboard: \(storyBoardName!) , app:\(app.appId!)")
  103. let storyBoard = UIStoryboard(name: storyBoardName!, bundle: nil)
  104. var destVC:UIViewController!
  105. if let vcname = app.vcName,vcname.isEmpty == false {
  106. destVC = storyBoard.instantiateViewController(withIdentifier: app.vcName!)
  107. }else{
  108. destVC = storyBoard.instantiateInitialViewController()
  109. }
  110. if app.vcName == "todoTask" {
  111. if "taskcompleted" == app.appId {
  112. AppConfigSettings.shared.taskIndex = 2
  113. }else if "read" == app.appId {
  114. AppConfigSettings.shared.taskIndex = 1
  115. }else if "readcompleted" == app.appId {
  116. AppConfigSettings.shared.taskIndex = 3
  117. }else {
  118. AppConfigSettings.shared.taskIndex = 0
  119. }
  120. }
  121. if destVC.isKind(of: ZLNavigationController.self) {
  122. self.show(destVC, sender: nil)
  123. }else{
  124. self.navigationController?.pushViewController(destVC, animated: true)
  125. }
  126. }
  127. }
  128. }
  129. }
  130. extension O2AppViewController:AppEditControllerUpdater {
  131. func appEditControllerUpdater() {
  132. self.loadAppConfigDb()
  133. }
  134. }