CCMore.swift 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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 progressQuota: UIProgressView!
  31. var functionMenu = [OCExternalSites]()
  32. var settingsMenu = [OCExternalSites]()
  33. var quotaMenu = [OCExternalSites]()
  34. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  35. var menuExternalSite: [TableExternalSites]?
  36. var tableAccont : TableAccount?
  37. override func viewDidLoad() {
  38. super.viewDidLoad()
  39. self.tableView.delegate = self
  40. self.tableView.dataSource = self
  41. self.imageLogo.image = UIImage.init(named: image_brandLogoMenu)
  42. }
  43. override func viewWillAppear(_ animated: Bool) {
  44. // Clear Menu
  45. functionMenu.removeAll()
  46. settingsMenu.removeAll()
  47. quotaMenu.removeAll()
  48. // Internal
  49. var item = OCExternalSites.init()
  50. item.name = "_transfers_"
  51. item.icon = "moreTransfers"
  52. item.url = "segueTransfers"
  53. functionMenu.append(item)
  54. item = OCExternalSites.init()
  55. item.name = "_activity_"
  56. item.icon = "moreActivity"
  57. item.url = "segueActivity"
  58. functionMenu.append(item)
  59. item = OCExternalSites.init()
  60. item.name = "_local_storage_"
  61. item.icon = "moreLocalStorage"
  62. item.url = "segueLocalStorage"
  63. functionMenu.append(item)
  64. item = OCExternalSites.init()
  65. item.name = "_settings_"
  66. item.icon = "moreSettings"
  67. item.url = "segueSettings"
  68. settingsMenu.append(item)
  69. // External
  70. self.menuExternalSite = CCCoreData.getAllTableExternalSites(with: NSPredicate(format: "(account == '\(appDelegate.activeAccount!)')")) as? [TableExternalSites]
  71. for table in self.menuExternalSite! {
  72. item = OCExternalSites.init()
  73. item.name = table.name
  74. item.url = table.url
  75. item.icon = table.icon
  76. if (table.type == "link") {
  77. functionMenu.append(item)
  78. }
  79. if (table.type == "settings") {
  80. settingsMenu.append(item)
  81. }
  82. if (table.type == "quota") {
  83. quotaMenu.append(item)
  84. }
  85. }
  86. self.tableAccont = CCCoreData.getActiveAccount()
  87. if (self.tableAccont != nil) {
  88. self.labelUsername.text = self.tableAccont?.user
  89. self.progressQuota.progress = Float((self.tableAccont?.quotaRelative)!) / 100
  90. let quota : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaTotal)!))
  91. let quotaUsed : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaUsed)!))
  92. self.labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
  93. }
  94. // Avatar
  95. let avatar : UIImage? = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/avatar.png")
  96. if (avatar != nil) {
  97. self.imageAvatar.image = avatar
  98. } else {
  99. self.imageAvatar.image = UIImage.init(named: "moreAvatar")
  100. }
  101. // Aspect
  102. CCAspect.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: true)
  103. CCAspect.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  104. tableView.reloadData()
  105. }
  106. func numberOfSections(in tableView: UITableView) -> Int {
  107. return 2
  108. }
  109. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  110. if (section == 0) {
  111. return 10
  112. } else {
  113. return 30
  114. }
  115. }
  116. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  117. var cont = 0
  118. // Menu Normal
  119. if (section == 0) {
  120. cont = functionMenu.count
  121. }
  122. // Menu Settings
  123. if (section == 1) {
  124. cont = settingsMenu.count
  125. }
  126. return cont
  127. }
  128. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  129. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
  130. // change color selection
  131. let selectionColor : UIView = UIView.init()
  132. selectionColor.backgroundColor = Constant.GlobalConstants.k_Color_SelectBackgrond
  133. cell.selectedBackgroundView = selectionColor
  134. // Menu Normal
  135. if (indexPath.section == 0) {
  136. let item = functionMenu[indexPath.row]
  137. cell.imageIcon?.image = UIImage.init(named: item.icon)
  138. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  139. cell.labelText.textColor = Constant.GlobalConstants.k_Color_Nextcloud
  140. }
  141. // Menu Settings
  142. if (indexPath.section == 1) {
  143. let item = settingsMenu[indexPath.row]
  144. cell.imageIcon?.image = UIImage.init(named: item.icon)
  145. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  146. cell.labelText.textColor = Constant.GlobalConstants.k_Color_GrayMenuMore
  147. }
  148. return cell
  149. }
  150. // method to run when table view cell is tapped
  151. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  152. var item: OCExternalSites = OCExternalSites.init()
  153. // Menu Function
  154. if (indexPath.section == 0) {
  155. item = functionMenu[indexPath.row]
  156. }
  157. // Menu Settings
  158. if (indexPath.section == 1) {
  159. item = settingsMenu[indexPath.row]
  160. }
  161. if (item.url.contains("segue")) {
  162. self.navigationController?.performSegue(withIdentifier: item.url, sender: self)
  163. }
  164. if (item.url.contains("//")) {
  165. if (self.splitViewController?.isCollapsed)! {
  166. let webVC = SwiftWebVC(urlString: item.url)
  167. self.navigationController?.pushViewController(webVC, animated: true)
  168. self.navigationController?.navigationBar.isHidden = false
  169. } else {
  170. let webVC = SwiftModalWebVC(urlString: item.url)
  171. self.present(webVC, animated: true, completion: nil)
  172. }
  173. }
  174. }
  175. }
  176. class CCCellMore: UITableViewCell {
  177. @IBOutlet weak var labelText: UILabel!
  178. @IBOutlet weak var imageIcon: UIImageView!
  179. }