CCMore.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. //
  2. // CCMore.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/04/17.
  6. // Copyright © 2017 TWS. All rights reserved.
  7. //
  8. // Author Marino Faggiana <m.faggiana@twsweb.it>
  9. //
  10. // This program is free software: you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation, either version 3 of the License, or
  13. // (at your option) any later version.
  14. //
  15. // This program is distributed in the hope that it will be useful,
  16. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. // GNU General Public License for more details.
  19. //
  20. // You should have received a copy of the GNU General Public License
  21. // along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. //
  23. import UIKit
  24. class CCMore: UIViewController, UITableViewDelegate, UITableViewDataSource {
  25. @IBOutlet weak var themingBackground: UIImageView!
  26. @IBOutlet weak var themingAvatar: UIImageView!
  27. @IBOutlet weak var labelUsername: UILabel!
  28. @IBOutlet weak var tableView: UITableView!
  29. @IBOutlet weak var labelQuota: UILabel!
  30. @IBOutlet weak var labelQuotaExternalSite: UILabel!
  31. @IBOutlet weak var progressQuota: UIProgressView!
  32. var functionMenu = [OCExternalSites]()
  33. var settingsMenu = [OCExternalSites]()
  34. var quotaMenu = [OCExternalSites]()
  35. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  36. var menuExternalSite: [TableExternalSites]?
  37. var tableAccont : TableAccount?
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. tableView.delegate = self
  41. tableView.dataSource = self
  42. tableView.separatorColor = NCBrandColor.sharedInstance.seperator
  43. themingBackground.image = UIImage.init(named: NCBrandImages.sharedInstance.themingBackground)
  44. // create tap gesture recognizer
  45. let tapQuota = UITapGestureRecognizer(target: self, action: #selector(tapLabelQuotaExternalSite))
  46. labelQuotaExternalSite.isUserInteractionEnabled = true
  47. labelQuotaExternalSite.addGestureRecognizer(tapQuota)
  48. let tapImageLogo = UITapGestureRecognizer(target: self, action: #selector(tapImageLogoManageAccount))
  49. themingBackground.isUserInteractionEnabled = true
  50. themingBackground.addGestureRecognizer(tapImageLogo)
  51. // Notification
  52. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  53. NotificationCenter.default.addObserver(self, selector: #selector(self.changeUserProfile), name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
  54. }
  55. // Apparirà
  56. override func viewWillAppear(_ animated: Bool) {
  57. super.viewWillAppear(animated)
  58. // Clear
  59. functionMenu.removeAll()
  60. settingsMenu.removeAll()
  61. quotaMenu.removeAll()
  62. labelQuotaExternalSite.text = ""
  63. // Internal
  64. var item = OCExternalSites.init()
  65. item.name = "_transfers_"
  66. item.icon = "moreTransfers"
  67. item.url = "segueTransfers"
  68. functionMenu.append(item)
  69. item = OCExternalSites.init()
  70. item.name = "_activity_"
  71. item.icon = "moreActivity"
  72. item.url = "segueActivity"
  73. functionMenu.append(item)
  74. item = OCExternalSites.init()
  75. item.name = "_local_storage_"
  76. item.icon = "moreLocalStorage"
  77. item.url = "segueLocalStorage"
  78. functionMenu.append(item)
  79. item = OCExternalSites.init()
  80. item.name = "_settings_"
  81. item.icon = "moreSettings"
  82. item.url = "segueSettings"
  83. settingsMenu.append(item)
  84. // External
  85. menuExternalSite = CCCoreData.getAllTableExternalSites(with: NSPredicate(format: "(account == '\(appDelegate.activeAccount!)')")) as? [TableExternalSites]
  86. if (menuExternalSite != nil) {
  87. for table in menuExternalSite! {
  88. item = OCExternalSites.init()
  89. item.name = table.name
  90. item.url = table.url
  91. item.icon = table.icon
  92. if (table.type == "link") {
  93. item.icon = "moreExternalSite"
  94. functionMenu.append(item)
  95. }
  96. if (table.type == "settings") {
  97. item.icon = "moreSettingsExternalSite"
  98. settingsMenu.append(item)
  99. }
  100. if (table.type == "quota") {
  101. quotaMenu.append(item)
  102. }
  103. }
  104. }
  105. if (quotaMenu.count > 0) {
  106. let item = quotaMenu[0]
  107. labelQuotaExternalSite.text = item.name
  108. }
  109. // User data & Theming
  110. changeUserProfile()
  111. changeTheming()
  112. // Title
  113. self.navigationItem.title = NSLocalizedString("_more_", comment: "")
  114. // Aspect
  115. appDelegate.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: false)
  116. appDelegate.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  117. // +
  118. appDelegate.plusButtonVisibile(true)
  119. self.navigationController?.setNavigationBarHidden(true, animated: animated)
  120. tableView.reloadData()
  121. }
  122. override func viewWillDisappear(_ animated: Bool) {
  123. super.viewWillDisappear(animated)
  124. self.navigationController?.setNavigationBarHidden(false, animated: animated)
  125. }
  126. func changeTheming() {
  127. // Theming Background
  128. let theminBackgroundFile = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/themingBackground.png")
  129. if (theminBackgroundFile != nil) {
  130. themingBackground.image = theminBackgroundFile
  131. } else {
  132. themingBackground.image = UIImage.init(named: NCBrandImages.sharedInstance.themingBackground)
  133. }
  134. if (self.isViewLoaded && (self.view.window != nil)) {
  135. appDelegate.changeTheming(self)
  136. }
  137. }
  138. func changeUserProfile() {
  139. let themingAvatarFile : UIImage? = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/avatar.png")
  140. if (themingAvatarFile != nil) {
  141. themingAvatar.image = themingAvatarFile
  142. } else {
  143. themingAvatar.image = UIImage.init(named: "moreAvatar")
  144. }
  145. // Display Name user & Quota
  146. tableAccont = CCCoreData.getActiveAccount()
  147. if (tableAccont != nil) {
  148. if let displayName = self.tableAccont!.displayName {
  149. if displayName.isEmpty {
  150. labelUsername.text = self.tableAccont!.user
  151. }
  152. else{
  153. labelUsername.text = self.tableAccont!.displayName
  154. }
  155. }
  156. else{
  157. labelUsername.text = self.tableAccont!.user
  158. }
  159. // fix CCMore.swift line 208 Version 2.17.2 (00005)
  160. if (self.tableAccont?.quotaRelative != nil && self.tableAccont?.quotaTotal != nil && self.tableAccont?.quotaUsed != nil) {
  161. progressQuota.progress = Float((self.tableAccont?.quotaRelative)!) / 100
  162. progressQuota.progressTintColor = NCBrandColor.sharedInstance.brand
  163. let quota : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaTotal)!))
  164. let quotaUsed : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaUsed)!))
  165. labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
  166. }
  167. }
  168. }
  169. func numberOfSections(in tableView: UITableView) -> Int {
  170. return 2
  171. }
  172. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  173. if (section == 0) {
  174. return 10
  175. } else {
  176. return 30
  177. }
  178. }
  179. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  180. var cont = 0
  181. // Menu Normal
  182. if (section == 0) {
  183. cont = functionMenu.count
  184. }
  185. // Menu Settings
  186. if (section == 1) {
  187. cont = settingsMenu.count
  188. }
  189. return cont
  190. }
  191. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  192. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
  193. // change color selection and disclosure indicator
  194. let selectionColor : UIView = UIView.init()
  195. selectionColor.backgroundColor = NCBrandColor.sharedInstance.getColorSelectBackgrond()
  196. cell.selectedBackgroundView = selectionColor
  197. cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
  198. // Menu Normal
  199. if (indexPath.section == 0) {
  200. let item = functionMenu[indexPath.row]
  201. cell.imageIcon?.image = UIImage.init(named: item.icon)
  202. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  203. cell.labelText.textColor = NCBrandColor.sharedInstance.moreNormal
  204. }
  205. // Menu Settings
  206. if (indexPath.section == 1) {
  207. let item = settingsMenu[indexPath.row]
  208. cell.imageIcon?.image = UIImage.init(named: item.icon)
  209. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  210. cell.labelText.textColor = NCBrandColor.sharedInstance.moreSettings
  211. }
  212. return cell
  213. }
  214. // method to run when table view cell is tapped
  215. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  216. var item: OCExternalSites = OCExternalSites.init()
  217. // Menu Function
  218. if (indexPath.section == 0) {
  219. item = functionMenu[indexPath.row]
  220. }
  221. // Menu Settings
  222. if (indexPath.section == 1) {
  223. item = settingsMenu[indexPath.row]
  224. }
  225. if (item.url.contains("segue") && !item.url.contains("//")) {
  226. self.navigationController?.performSegue(withIdentifier: item.url, sender: self)
  227. }
  228. if (item.url.contains("//")) {
  229. if (self.splitViewController?.isCollapsed)! {
  230. let webVC = SwiftWebVC(urlString: item.url)
  231. self.navigationController?.pushViewController(webVC, animated: true)
  232. self.navigationController?.navigationBar.isHidden = false
  233. } else {
  234. let webVC = SwiftModalWebVC(urlString: item.url)
  235. self.present(webVC, animated: true, completion: nil)
  236. }
  237. }
  238. }
  239. func tapLabelQuotaExternalSite() {
  240. if (quotaMenu.count > 0) {
  241. let item = quotaMenu[0]
  242. if (self.splitViewController?.isCollapsed)! {
  243. let webVC = SwiftWebVC(urlString: item.url)
  244. self.navigationController?.pushViewController(webVC, animated: true)
  245. self.navigationController?.navigationBar.isHidden = false
  246. } else {
  247. let webVC = SwiftModalWebVC(urlString: item.url)
  248. self.present(webVC, animated: true, completion: nil)
  249. }
  250. }
  251. }
  252. func tapImageLogoManageAccount() {
  253. let controller = CCManageAccount.init()
  254. self.navigationController?.pushViewController(controller, animated: true)
  255. }
  256. }
  257. class CCCellMore: UITableViewCell {
  258. @IBOutlet weak var labelText: UILabel!
  259. @IBOutlet weak var imageIcon: UIImageView!
  260. }