CCMore.swift 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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. let itemsMenuLabelText = [["_transfers_","_activity_","_local_storage_"], ["_settings_"]]
  32. let itemsMenuImage = [["transfers","activity","localStorage"], ["settings"]]
  33. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  34. var menuExternalSite: [TableExternalSites]?
  35. var tableAccont : TableAccount?
  36. override func viewDidLoad() {
  37. super.viewDidLoad()
  38. self.tableView.delegate = self
  39. self.tableView.dataSource = self
  40. self.imageLogo.image = UIImage.init(named: image_brandLogoMenu)
  41. }
  42. override func viewWillAppear(_ animated: Bool) {
  43. self.tableAccont = CCCoreData.getActiveAccount()
  44. self.menuExternalSite = CCCoreData.getAllTableExternalSites(with: NSPredicate(format: "(account == '\(appDelegate.activeAccount!)')")) as? [TableExternalSites]
  45. if (self.tableAccont != nil) {
  46. self.labelUsername.text = self.tableAccont?.user
  47. self.progressQuota.progress = Float((self.tableAccont?.quotaRelative)!) / 100
  48. let quota : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaTotal)!))
  49. let quotaUsed : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaUsed)!))
  50. self.labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
  51. }
  52. // Avatar
  53. let avatar : UIImage? = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/avatar.png")
  54. if (avatar != nil) {
  55. self.imageAvatar.image = avatar
  56. } else {
  57. self.imageAvatar.image = UIImage.init(named: "avatar")
  58. }
  59. // Aspect
  60. CCAspect.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: true)
  61. CCAspect.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  62. tableView.reloadData()
  63. }
  64. func numberOfSections(in tableView: UITableView) -> Int {
  65. if (self.menuExternalSite == nil) {
  66. return 2
  67. } else {
  68. return 3
  69. }
  70. }
  71. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  72. if (section == 0) {
  73. return 10
  74. } else {
  75. return 30
  76. }
  77. }
  78. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  79. return self.itemsMenuLabelText[section].count
  80. }
  81. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  82. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
  83. cell.imageIcon?.image = UIImage.init(named: self.itemsMenuImage[indexPath.section][indexPath.row])
  84. cell.labelText?.text = NSLocalizedString(self.itemsMenuLabelText[indexPath.section][indexPath.row], comment: "")
  85. return cell
  86. }
  87. // method to run when table view cell is tapped
  88. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  89. // Menu Function
  90. if (indexPath.section == 0) {
  91. }
  92. // Menu External Site
  93. if (indexPath.section == 1 && self.menuExternalSite != nil) {
  94. }
  95. // Menu Settings
  96. if ((indexPath.section == 1 && self.menuExternalSite == nil) || (indexPath.section == 2 && self.menuExternalSite != nil)) {
  97. if (indexPath.row == 0) {
  98. self.navigationController?.performSegue(withIdentifier: "segueSettings", sender: self)
  99. }
  100. }
  101. }
  102. }
  103. class CCCellMore: UITableViewCell {
  104. @IBOutlet weak var labelText: UILabel!
  105. @IBOutlet weak var imageIcon: UIImageView!
  106. }