CCMore.swift 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 tableView: UITableView!
  28. @IBOutlet weak var labelQuota: UILabel!
  29. @IBOutlet weak var progressQuota: UIProgressView!
  30. let itemsMenuLabelText = [["_transfers_","_activity_"], ["_settings_"]]
  31. let itemsMenuImage = [["transfers","activity"], ["settings"]]
  32. let appDelegate = UIApplication.shared.delegate as! AppDelegate
  33. var menuExternalSite: [TableExternalSites]?
  34. var tableAccont : TableAccount?
  35. override func viewDidLoad() {
  36. super.viewDidLoad()
  37. self.tableView.delegate = self
  38. self.tableView.dataSource = self
  39. CCAspect.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: true)
  40. CCAspect.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  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.progressQuota.progress = Float((self.tableAccont?.quotaRelative)!) / 100
  47. let quota : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaTotal)!))
  48. let quotaUsed : String = CCUtility.transformedSize(Double((self.tableAccont?.quotaUsed)!))
  49. self.labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
  50. }
  51. // Avatar
  52. let avatar : UIImage? = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/avatar.png")
  53. if (avatar != nil) {
  54. //avatar = CCGraphics.scale(avatar, to: CGSize(width: 50, height: 50))
  55. //let avatarView : APAvatarImageView = APAvatarImageView.init(image: CCGraphics.scale(avatar, to: CGSize(width: 50, height: 50)), borderColor: UIColor.white, borderWidth: 0.5)
  56. self.imageAvatar.image = avatar
  57. } else {
  58. self.imageAvatar.image = UIImage.init(named: "avatar")
  59. }
  60. /*
  61. if (avatar) {
  62. avatar = [CCGraphics scaleImage:avatar toSize:CGSizeMake(50, 50)];
  63. APAvatarImageView *avatarImageView = [[APAvatarImageView alloc] initWithImage:avatar borderColor:[UIColor lightGrayColor] borderWidth:0.5];
  64. CGSize imageSize = avatarImageView.bounds.size;
  65. UIGraphicsBeginImageContextWithOptions(imageSize, NO, 0);
  66. CGContextRef context = UIGraphicsGetCurrentContext();
  67. [avatarImageView.layer renderInContext:context];
  68. avatar = UIGraphicsGetImageFromCurrentImageContext();
  69. UIGraphicsEndImageContext();
  70. }
  71. */
  72. // Aspect
  73. CCAspect.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: true)
  74. CCAspect.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  75. tableView.reloadData()
  76. }
  77. func numberOfSections(in tableView: UITableView) -> Int {
  78. if (self.menuExternalSite == nil) {
  79. return 2
  80. } else {
  81. return 3
  82. }
  83. }
  84. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  85. var height : CGFloat
  86. if (section == 0) {
  87. height = 10
  88. } else {
  89. height = 30
  90. }
  91. return height
  92. }
  93. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  94. return self.itemsMenuLabelText[section].count
  95. }
  96. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  97. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
  98. cell.imageIcon?.image = UIImage.init(named: self.itemsMenuImage[indexPath.section][indexPath.row])
  99. cell.labelText?.text = NSLocalizedString(self.itemsMenuLabelText[indexPath.section][indexPath.row], comment: "")
  100. return cell
  101. }
  102. // method to run when table view cell is tapped
  103. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  104. print("You tapped cell number \(indexPath.row).")
  105. self.navigationController?.performSegue(withIdentifier: "segueSettings", sender: self)
  106. }
  107. }
  108. class CCCellMore: UITableViewCell {
  109. @IBOutlet weak var labelText: UILabel!
  110. @IBOutlet weak var imageIcon: UIImageView!
  111. }