CCMore.swift 11 KB

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