CCMore.swift 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  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 imageLogo: UIImageView!
  26. @IBOutlet weak var imageAvatar: 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. imageLogo.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. imageLogo.isUserInteractionEnabled = true
  50. imageLogo.addGestureRecognizer(tapImageLogo)
  51. // Notification theming
  52. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  53. }
  54. override func viewWillAppear(_ animated: Bool) {
  55. super.viewWillAppear(animated)
  56. // Clear
  57. functionMenu.removeAll()
  58. settingsMenu.removeAll()
  59. quotaMenu.removeAll()
  60. labelQuotaExternalSite.text = ""
  61. // Internal
  62. var item = OCExternalSites.init()
  63. item.name = "_transfers_"
  64. item.icon = "moreTransfers"
  65. item.url = "segueTransfers"
  66. functionMenu.append(item)
  67. item = OCExternalSites.init()
  68. item.name = "_activity_"
  69. item.icon = "moreActivity"
  70. item.url = "segueActivity"
  71. functionMenu.append(item)
  72. item = OCExternalSites.init()
  73. item.name = "_local_storage_"
  74. item.icon = "moreLocalStorage"
  75. item.url = "segueLocalStorage"
  76. functionMenu.append(item)
  77. item = OCExternalSites.init()
  78. item.name = "_settings_"
  79. item.icon = "moreSettings"
  80. item.url = "segueSettings"
  81. settingsMenu.append(item)
  82. // External
  83. menuExternalSite = CCCoreData.getAllTableExternalSites(with: NSPredicate(format: "(account == '\(appDelegate.activeAccount!)')")) as? [TableExternalSites]
  84. if (menuExternalSite != nil) {
  85. for table in menuExternalSite! {
  86. item = OCExternalSites.init()
  87. item.name = table.name
  88. item.url = table.url
  89. item.icon = table.icon
  90. if (table.type == "link") {
  91. item.icon = "moreExternalSite"
  92. functionMenu.append(item)
  93. }
  94. if (table.type == "settings") {
  95. item.icon = "moreSettingsExternalSite"
  96. settingsMenu.append(item)
  97. }
  98. if (table.type == "quota") {
  99. quotaMenu.append(item)
  100. }
  101. }
  102. }
  103. // Display Name user & Quota
  104. tableAccont = CCCoreData.getActiveAccount()
  105. if (tableAccont != nil) {
  106. if let displayName = self.tableAccont!.displayName {
  107. if displayName.isEmpty {
  108. labelUsername.text = self.tableAccont!.user
  109. }
  110. else{
  111. labelUsername.text = self.tableAccont!.displayName
  112. }
  113. }
  114. else{
  115. labelUsername.text = self.tableAccont!.user
  116. }
  117. progressQuota.progress = Float((self.tableAccont?.quotaRelative)!) / 100
  118. progressQuota.progressTintColor = NCBrandColor.sharedInstance.brand
  119. let quota : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaTotal)!))
  120. let quotaUsed : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaUsed)!))
  121. labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
  122. // imageLogo
  123. let theminBackground = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/themingBackground.png")
  124. if (theminBackground != nil) {
  125. imageLogo.image = theminBackground
  126. } else {
  127. imageLogo.image = UIImage.init(named: NCBrandImages.sharedInstance.themingBackground)
  128. }
  129. }
  130. if (quotaMenu.count > 0) {
  131. let item = quotaMenu[0]
  132. labelQuotaExternalSite.text = item.name
  133. }
  134. // Avatar
  135. let avatar : UIImage? = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/avatar.png")
  136. if (avatar != nil) {
  137. imageAvatar.image = avatar
  138. } else {
  139. imageAvatar.image = UIImage.init(named: "moreAvatar")
  140. }
  141. // Title
  142. self.navigationItem.title = NSLocalizedString("_more_", comment: "")
  143. // Aspect
  144. appDelegate.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: false)
  145. appDelegate.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  146. // +
  147. appDelegate.plusButtonVisibile(true)
  148. self.navigationController?.setNavigationBarHidden(true, animated: animated)
  149. tableView.reloadData()
  150. }
  151. override func viewDidAppear(_ animated: Bool) {
  152. super.viewDidAppear(animated)
  153. }
  154. override func viewWillDisappear(_ animated: Bool) {
  155. super.viewWillDisappear(animated)
  156. self.navigationController?.setNavigationBarHidden(false, animated: animated)
  157. }
  158. func changeTheming() {
  159. // Navigation & TabBar color
  160. appDelegate.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: false)
  161. appDelegate.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  162. }
  163. func numberOfSections(in tableView: UITableView) -> Int {
  164. return 2
  165. }
  166. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  167. if (section == 0) {
  168. return 10
  169. } else {
  170. return 30
  171. }
  172. }
  173. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  174. var cont = 0
  175. // Menu Normal
  176. if (section == 0) {
  177. cont = functionMenu.count
  178. }
  179. // Menu Settings
  180. if (section == 1) {
  181. cont = settingsMenu.count
  182. }
  183. return cont
  184. }
  185. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  186. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
  187. // change color selection and disclosure indicator
  188. let selectionColor : UIView = UIView.init()
  189. selectionColor.backgroundColor = NCBrandColor.sharedInstance.selectBackgrond
  190. cell.selectedBackgroundView = selectionColor
  191. cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
  192. // Menu Normal
  193. if (indexPath.section == 0) {
  194. let item = functionMenu[indexPath.row]
  195. cell.imageIcon?.image = UIImage.init(named: item.icon)
  196. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  197. cell.labelText.textColor = NCBrandColor.sharedInstance.moreNormal
  198. }
  199. // Menu Settings
  200. if (indexPath.section == 1) {
  201. let item = settingsMenu[indexPath.row]
  202. cell.imageIcon?.image = UIImage.init(named: item.icon)
  203. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  204. cell.labelText.textColor = NCBrandColor.sharedInstance.moreSettings
  205. }
  206. return cell
  207. }
  208. // method to run when table view cell is tapped
  209. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  210. var item: OCExternalSites = OCExternalSites.init()
  211. // Menu Function
  212. if (indexPath.section == 0) {
  213. item = functionMenu[indexPath.row]
  214. }
  215. // Menu Settings
  216. if (indexPath.section == 1) {
  217. item = settingsMenu[indexPath.row]
  218. }
  219. if (item.url.contains("segue") && !item.url.contains("//")) {
  220. self.navigationController?.performSegue(withIdentifier: item.url, sender: self)
  221. }
  222. if (item.url.contains("//")) {
  223. if (self.splitViewController?.isCollapsed)! {
  224. let webVC = SwiftWebVC(urlString: item.url)
  225. self.navigationController?.pushViewController(webVC, animated: true)
  226. self.navigationController?.navigationBar.isHidden = false
  227. } else {
  228. let webVC = SwiftModalWebVC(urlString: item.url)
  229. self.present(webVC, animated: true, completion: nil)
  230. }
  231. }
  232. }
  233. func tapLabelQuotaExternalSite() {
  234. if (quotaMenu.count > 0) {
  235. let item = quotaMenu[0]
  236. if (self.splitViewController?.isCollapsed)! {
  237. let webVC = SwiftWebVC(urlString: item.url)
  238. self.navigationController?.pushViewController(webVC, animated: true)
  239. self.navigationController?.navigationBar.isHidden = false
  240. } else {
  241. let webVC = SwiftModalWebVC(urlString: item.url)
  242. self.present(webVC, animated: true, completion: nil)
  243. }
  244. }
  245. }
  246. func tapImageLogoManageAccount() {
  247. let controller = CCManageAccount.init()
  248. self.navigationController?.pushViewController(controller, animated: true)
  249. }
  250. }
  251. class CCCellMore: UITableViewCell {
  252. @IBOutlet weak var labelText: UILabel!
  253. @IBOutlet weak var imageIcon: UIImageView!
  254. }