CCMore.swift 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 themingBackground: UIImageView!
  26. @IBOutlet weak var themingAvatar: 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 tabAccount : tableAccount?
  38. override func viewDidLoad() {
  39. super.viewDidLoad()
  40. tableView.delegate = self
  41. tableView.dataSource = self
  42. tableView.separatorColor = NCBrandColor.sharedInstance.seperator
  43. themingBackground.image = UIImage.init(named: "themingBackground")
  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. themingBackground.isUserInteractionEnabled = true
  50. themingBackground.addGestureRecognizer(tapImageLogo)
  51. // Notification
  52. NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
  53. NotificationCenter.default.addObserver(self, selector: #selector(self.changeUserProfile), name: NSNotification.Name(rawValue: "changeUserProfile"), object: nil)
  54. }
  55. // Apparirà
  56. override func viewWillAppear(_ animated: Bool) {
  57. super.viewWillAppear(animated)
  58. // Clear
  59. functionMenu.removeAll()
  60. settingsMenu.removeAll()
  61. quotaMenu.removeAll()
  62. labelQuotaExternalSite.text = ""
  63. // ITEM : Transfer
  64. var item = OCExternalSites.init()
  65. item.name = "_transfers_"
  66. item.icon = "moreTransfers"
  67. item.url = "segueTransfers"
  68. functionMenu.append(item)
  69. // ITEM : Activity
  70. item = OCExternalSites.init()
  71. if NCBrandOptions.sharedInstance.use_recent_activity_title == true {
  72. item.name = "_recent_activity_"
  73. } else {
  74. item.name = "_activity_"
  75. }
  76. item.icon = "moreActivity"
  77. item.url = "segueActivity"
  78. functionMenu.append(item)
  79. // ITEM : Notification [CUSTOM]
  80. if NCBrandOptions.sharedInstance.use_notification_on_menu_more == true {
  81. item = OCExternalSites.init()
  82. item.name = "_notifications_"
  83. item.icon = "notification"
  84. item.url = "openCCNotification"
  85. functionMenu.append(item)
  86. }
  87. // ITEM : Local storage
  88. item = OCExternalSites.init()
  89. item.name = "_local_storage_"
  90. item.icon = "moreLocalStorage"
  91. item.url = "segueLocalStorage"
  92. functionMenu.append(item)
  93. // ITEM : External
  94. menuExternalSite = NCManageDatabase.sharedInstance.getAllExternalSites(predicate: NSPredicate(format: "(account == '\(appDelegate.activeAccount!)')"))
  95. //menuExternalSite = NCManageDatabase.sharedInstance.getAllExternalSitesWithPredicate(NSPredicate(format: "(account == '\(appDelegate.activeAccount!)')"))
  96. for table in menuExternalSite! {
  97. item = OCExternalSites.init()
  98. item.name = table.name
  99. item.url = table.url
  100. item.icon = table.icon
  101. if (table.type == "link") {
  102. item.icon = "moreExternalSite"
  103. functionMenu.append(item)
  104. }
  105. if (table.type == "settings") {
  106. item.icon = "moreSettingsExternalSite"
  107. settingsMenu.append(item)
  108. }
  109. if (table.type == "quota") {
  110. quotaMenu.append(item)
  111. }
  112. }
  113. // ITEM : Settings
  114. item = OCExternalSites.init()
  115. item.name = "_settings_"
  116. item.icon = "moreSettings"
  117. item.url = "segueSettings"
  118. settingsMenu.append(item)
  119. if (quotaMenu.count > 0) {
  120. let item = quotaMenu[0]
  121. labelQuotaExternalSite.text = item.name
  122. }
  123. // ITEM : Logout [CUSTOM]
  124. if NCBrandOptions.sharedInstance.use_logout_on_menu_more == true {
  125. item = OCExternalSites.init()
  126. item.name = "_logout_"
  127. item.icon = "logout"
  128. item.url = "logout"
  129. settingsMenu.append(item)
  130. }
  131. // User data & Theming
  132. changeUserProfile()
  133. changeTheming()
  134. // Title
  135. self.navigationItem.title = NSLocalizedString("_more_", comment: "")
  136. // Aspect
  137. appDelegate.aspectNavigationControllerBar(self.navigationController?.navigationBar, encrypted: false, online: appDelegate.reachability.isReachable(), hidden: false)
  138. appDelegate.aspectTabBar(self.tabBarController?.tabBar, hidden: false)
  139. // +
  140. appDelegate.plusButtonVisibile(true)
  141. self.navigationController?.setNavigationBarHidden(true, animated: animated)
  142. tableView.reloadData()
  143. }
  144. override func viewWillDisappear(_ animated: Bool) {
  145. super.viewWillDisappear(animated)
  146. self.navigationController?.setNavigationBarHidden(false, animated: animated)
  147. }
  148. func changeTheming() {
  149. // Theming Background
  150. let theminBackgroundFile = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/themingBackground.png")
  151. if (theminBackgroundFile != nil) {
  152. themingBackground.image = theminBackgroundFile
  153. } else {
  154. themingBackground.image = UIImage.init(named: "themingBackground")
  155. }
  156. if (self.isViewLoaded && (self.view.window != nil)) {
  157. appDelegate.changeTheming(self)
  158. }
  159. }
  160. func changeUserProfile() {
  161. let themingAvatarFile : UIImage? = UIImage.init(contentsOfFile: "\(appDelegate.directoryUser!)/avatar.png")
  162. if (themingAvatarFile != nil) {
  163. themingAvatar.image = themingAvatarFile
  164. } else {
  165. themingAvatar.image = UIImage.init(named: "moreAvatar")
  166. }
  167. // Display Name user & Quota
  168. tabAccount = NCManageDatabase.sharedInstance.getAccountActive()
  169. if (tabAccount != nil) {
  170. if let displayName = tabAccount?.displayName {
  171. if displayName.isEmpty {
  172. labelUsername.text = tabAccount!.user
  173. }
  174. else{
  175. labelUsername.text = tabAccount!.displayName
  176. }
  177. }
  178. else{
  179. labelUsername.text = tabAccount!.user
  180. }
  181. // fix CCMore.swift line 208 Version 2.17.2 (00005)
  182. if (tabAccount?.quotaRelative != nil && tabAccount?.quotaTotal != nil && tabAccount?.quotaUsed != nil) {
  183. progressQuota.progress = Float((tabAccount?.quotaRelative)!) / 100
  184. progressQuota.progressTintColor = NCBrandColor.sharedInstance.brand
  185. let quota : String = CCUtility.transformedSize(Double((tabAccount?.quotaTotal)!))
  186. let quotaUsed : String = CCUtility.transformedSize(Double((tabAccount?.quotaUsed)!))
  187. labelQuota.text = String.localizedStringWithFormat(NSLocalizedString("_quota_using_", comment: ""), quotaUsed, quota)
  188. }
  189. }
  190. }
  191. func numberOfSections(in tableView: UITableView) -> Int {
  192. return 2
  193. }
  194. func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
  195. if (section == 0) {
  196. return 10
  197. } else {
  198. return 30
  199. }
  200. }
  201. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  202. var cont = 0
  203. // Menu Normal
  204. if (section == 0) {
  205. cont = functionMenu.count
  206. }
  207. // Menu Settings
  208. if (section == 1) {
  209. cont = settingsMenu.count
  210. }
  211. return cont
  212. }
  213. func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  214. let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! CCCellMore
  215. // change color selection and disclosure indicator
  216. let selectionColor : UIView = UIView.init()
  217. selectionColor.backgroundColor = NCBrandColor.sharedInstance.getColorSelectBackgrond()
  218. cell.selectedBackgroundView = selectionColor
  219. cell.accessoryType = UITableViewCellAccessoryType.disclosureIndicator
  220. // Menu Normal
  221. if (indexPath.section == 0) {
  222. let item = functionMenu[indexPath.row]
  223. cell.imageIcon?.image = UIImage.init(named: item.icon)
  224. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  225. cell.labelText.textColor = NCBrandColor.sharedInstance.moreNormal
  226. }
  227. // Menu Settings
  228. if (indexPath.section == 1) {
  229. let item = settingsMenu[indexPath.row]
  230. cell.imageIcon?.image = UIImage.init(named: item.icon)
  231. cell.labelText?.text = NSLocalizedString(item.name, comment: "")
  232. cell.labelText.textColor = NCBrandColor.sharedInstance.moreSettings
  233. }
  234. return cell
  235. }
  236. // method to run when table view cell is tapped
  237. func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  238. var item: OCExternalSites = OCExternalSites.init()
  239. // Menu Function
  240. if indexPath.section == 0 {
  241. item = functionMenu[indexPath.row]
  242. }
  243. // Menu Settings
  244. if indexPath.section == 1 {
  245. item = settingsMenu[indexPath.row]
  246. }
  247. // Action
  248. if item.url.contains("segue") && !item.url.contains("//") {
  249. self.navigationController?.performSegue(withIdentifier: item.url, sender: self)
  250. } else if item.url.contains("open") && !item.url.contains("//") {
  251. let nameStoryboard = item.url.substring(from: item.url.index(item.url.startIndex, offsetBy: 4))
  252. let storyboard = UIStoryboard(name: nameStoryboard, bundle: nil)
  253. let controller = storyboard.instantiateViewController(withIdentifier: nameStoryboard)
  254. self.present(controller, animated: true, completion: nil)
  255. } else if item.url.contains("//") {
  256. if (self.splitViewController?.isCollapsed)! {
  257. let webVC = SwiftWebVC(urlString: item.url, hideToolbar: false)
  258. self.navigationController?.pushViewController(webVC, animated: true)
  259. self.navigationController?.navigationBar.isHidden = false
  260. } else {
  261. let webVC = SwiftModalWebVC(urlString: item.url)
  262. self.present(webVC, animated: true, completion: nil)
  263. }
  264. } else if item.url == "logout" {
  265. let alertController = UIAlertController(title: "", message: NSLocalizedString("_want_delete_", comment: ""), preferredStyle: .alert)
  266. let actionYes = UIAlertAction(title: NSLocalizedString("_yes_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  267. let manageAccount = CCManageAccount()
  268. manageAccount.delete(self.appDelegate.activeAccount)
  269. manageAccount.addFoced()
  270. }
  271. let actionNo = UIAlertAction(title: NSLocalizedString("_no_delete_", comment: ""), style: .default) { (action:UIAlertAction) in
  272. print("You've pressed No button");
  273. }
  274. alertController.addAction(actionYes)
  275. alertController.addAction(actionNo)
  276. self.present(alertController, animated: true, completion:nil)
  277. }
  278. }
  279. func tapLabelQuotaExternalSite() {
  280. if (quotaMenu.count > 0) {
  281. let item = quotaMenu[0]
  282. if (self.splitViewController?.isCollapsed)! {
  283. let webVC = SwiftWebVC(urlString: item.url, hideToolbar: false)
  284. self.navigationController?.pushViewController(webVC, animated: true)
  285. self.navigationController?.navigationBar.isHidden = false
  286. } else {
  287. let webVC = SwiftModalWebVC(urlString: item.url)
  288. self.present(webVC, animated: true, completion: nil)
  289. }
  290. }
  291. }
  292. func tapImageLogoManageAccount() {
  293. let controller = CCManageAccount.init()
  294. self.navigationController?.pushViewController(controller, animated: true)
  295. }
  296. }
  297. class CCCellMore: UITableViewCell {
  298. @IBOutlet weak var labelText: UILabel!
  299. @IBOutlet weak var imageIcon: UIImageView!
  300. }