O2AppViewController.swift 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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 Flutter
  15. import CocoaLumberjack
  16. class O2AppViewController: UIViewController{
  17. @IBOutlet weak var collectionView: UICollectionView!
  18. private let reuseIdentifier = "myCell"
  19. // let loadUrl1 = AppDelegate.o2Collect.genrateURLWithWebContextKey2(ApplicationContext.applicationListQuery2,parameter: nil)
  20. //
  21. // let loadUrl2 = AppDelegate.o2Collect.generateURLWithAppContextKey(ApplicationContext.applicationContextKey2, query: ApplicationContext.applicationListQueryForPortal, parameter: nil)
  22. fileprivate let collectionViewDelegate = ZLCollectionView()
  23. var o2apps:[O2App] = []
  24. var apps2:[[O2App]] = [[],[]]
  25. override func viewDidLoad() {
  26. super.viewDidLoad()
  27. self.title = "应用"
  28. navigationItem.rightBarButtonItem = UIBarButtonItem(title: "编辑", style: .plain, target: self, action: #selector(_forwardEditSegue))
  29. //self.collectionView.contentInset = UIEdgeInsetsMake(160, 0, 0, 0)
  30. self.collectionViewDelegate.delegate = self
  31. //self.collectionViewDelegate.cellHeight = Float(self.collectionViewDelegate.ItemWithSize) * 2
  32. self.collectionView.dataSource = self.collectionViewDelegate
  33. self.collectionView.delegate = self.collectionViewDelegate
  34. self.o2apps = []
  35. self.apps2 = []
  36. //self.loadAppConfigDb()
  37. }
  38. override func viewWillAppear(_ animated: Bool) {
  39. super.viewWillAppear(animated)
  40. self.loadAppConfigDb()
  41. }
  42. func loadAppConfigDb() {
  43. let mainApps = DBManager.shared.queryMainData()
  44. o2apps = mainApps
  45. let allApps = DBManager.shared.queryData()
  46. apps2 = [mainApps,allApps]
  47. self.collectionViewDelegate.apps = apps2
  48. DispatchQueue.main.async {
  49. self.collectionView.reloadData()
  50. }
  51. }
  52. @objc private func _forwardEditSegue() {
  53. self.performSegue(withIdentifier: "showAppEditSegue", sender: nil)
  54. }
  55. override func didReceiveMemoryWarning() {
  56. super.didReceiveMemoryWarning()
  57. }
  58. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  59. if segue.identifier == "showMailSegue" {
  60. segue.destination.modalPresentationStyle = .fullScreen
  61. if let nav = segue.destination as? ZLNavigationController {
  62. nav.viewControllers.forEach { (vc) in
  63. if vc is MailViewController {
  64. DDLogDebug("显示门户。。。。")
  65. (vc as! MailViewController).app = sender as? O2App
  66. }
  67. }
  68. }else if let mail = segue.destination as? MailViewController {
  69. mail.app = sender as? O2App
  70. }
  71. }
  72. }
  73. @IBAction func unBackAppsForApps(_ segue:UIStoryboardSegue){
  74. DDLogDebug("返回应用列表")
  75. }
  76. // MARK: - Flutter
  77. //打开flutter应用
  78. /**
  79. @param routeName flutter的路由 打开不同的页面
  80. **/
  81. func openFlutterApp(routeName: String) {
  82. let flutterViewController = O2FlutterViewController()
  83. DDLogDebug("init route:\(routeName)")
  84. flutterViewController.setInitialRoute(routeName)
  85. self.present(flutterViewController, animated: false, completion: nil)
  86. }
  87. }
  88. extension O2AppViewController:ZLCollectionViewDelegate{
  89. func clickWithApp(_ app: O2App) {
  90. if let flutter = app.storyBoard, flutter == "flutter" {
  91. openFlutterApp(routeName: app.appId!)
  92. }else {
  93. //设置返回标志,其它应用根据此返回标志调用返回unwindSegue
  94. AppConfigSettings.shared.appBackType = 2
  95. if let segueIdentifier = app.segueIdentifier,segueIdentifier != "" { // portal 门户 走这边
  96. if app.storyBoard! == "webview" { // 打开MailViewController
  97. DDLogDebug("open webview for : "+app.title!+" url: "+app.vcName!)
  98. self.performSegue(withIdentifier: segueIdentifier, sender: app)
  99. }else {
  100. self.performSegue(withIdentifier: segueIdentifier, sender: nil)
  101. }
  102. } else {
  103. if app.storyBoard! == "webview" {
  104. DDLogError("321 open webview for : "+app.title!+" url: "+app.vcName!)
  105. } else {
  106. // 内置应用走这边 根据appkey 打开对应的storyboard
  107. if app.appId == "o2ai" {
  108. app.storyBoard = "ai"
  109. }
  110. let story = O2AppUtil.apps.first { (appInfo) -> Bool in
  111. return app.appId == appInfo.appId
  112. }
  113. var storyBoardName = app.storyBoard
  114. if story != nil {
  115. storyBoardName = story?.storyBoard
  116. }
  117. DDLogDebug("storyboard: \(storyBoardName!) , app:\(app.appId!)")
  118. ///新版云盘 2019-11-20
  119. if storyBoardName == "cloudStorage" {
  120. storyBoardName = "CloudFile"
  121. }
  122. ////
  123. let storyBoard = UIStoryboard(name: storyBoardName!, bundle: nil)
  124. var destVC:UIViewController!
  125. if let vcname = app.vcName,vcname.isEmpty == false {
  126. destVC = storyBoard.instantiateViewController(withIdentifier: app.vcName!)
  127. }else{
  128. destVC = storyBoard.instantiateInitialViewController()
  129. }
  130. if app.vcName == "todoTask" {
  131. if "taskcompleted" == app.appId {
  132. AppConfigSettings.shared.taskIndex = 2
  133. }else if "read" == app.appId {
  134. AppConfigSettings.shared.taskIndex = 1
  135. }else if "readcompleted" == app.appId {
  136. AppConfigSettings.shared.taskIndex = 3
  137. }else {
  138. AppConfigSettings.shared.taskIndex = 0
  139. }
  140. }
  141. destVC.modalPresentationStyle = .fullScreen
  142. if destVC.isKind(of: ZLNavigationController.self) {
  143. DDLogInfo("cloudFIle 进来了?")
  144. self.show(destVC, sender: nil)
  145. }else{
  146. self.navigationController?.pushViewController(destVC, animated: true)
  147. }
  148. }
  149. }
  150. }
  151. }
  152. }
  153. extension O2AppViewController:AppEditControllerUpdater {
  154. func appEditControllerUpdater() {
  155. self.loadAppConfigDb()
  156. }
  157. }