CCMore.swift 9.7 KB

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