CCMore.swift 5.0 KB

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