NCLoginWeb+Menu.swift 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. //
  2. // NCLoginWeb+Menu.swift
  3. // Nextcloud
  4. //
  5. // Created by Marino Faggiana on 03/03/2021.
  6. // Copyright © 2021 Marino Faggiana. All rights reserved.
  7. //
  8. // Author Marino Faggiana <marino.faggiana@nextcloud.com>
  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 FloatingPanel
  24. extension NCLoginWeb {
  25. func toggleMenu() {
  26. let menuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
  27. var actions = [NCMenuAction]()
  28. let accounts = NCManageDatabase.shared.getAllAccount()
  29. var avatar = UIImage(named: "avatarCredentials")!.image(color: NCBrandColor.shared.icon, size: 50)
  30. for account in accounts {
  31. let title = account.user + " " + (URL(string: account.urlBase)?.host ?? "")
  32. var fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(account.user, urlBase: account.urlBase) + "-" + account.user
  33. fileNamePath = fileNamePath + ".png"
  34. if var userImage = UIImage(contentsOfFile: fileNamePath) {
  35. userImage = userImage.resizeImage(size: CGSize(width: 50, height: 50), isAspectRation: true)!
  36. let userImageView = UIImageView(image: userImage)
  37. userImageView.avatar(roundness: 2, borderWidth: 1, borderColor: NCBrandColor.shared.avatarBorder, backgroundColor: .clear)
  38. UIGraphicsBeginImageContext(userImageView.bounds.size)
  39. userImageView.layer.render(in: UIGraphicsGetCurrentContext()!)
  40. if let newAvatar = UIGraphicsGetImageFromCurrentImageContext() {
  41. avatar = newAvatar
  42. }
  43. UIGraphicsEndImageContext()
  44. }
  45. actions.append(
  46. NCMenuAction(
  47. title: title,
  48. icon: avatar,
  49. onTitle: title,
  50. onIcon: avatar,
  51. selected: account.active == true,
  52. on: account.active == true,
  53. action: { menuAction in
  54. if self.appDelegate.account != account.account {
  55. NCManageDatabase.shared.setAccountActive(account.account)
  56. self.dismiss(animated: true) {
  57. self.appDelegate.settingAccount(account.account, urlBase: account.urlBase, user: account.user, userId: account.userId, password: CCUtility.getPassword(account.account))
  58. self.appDelegate.initializeMain()
  59. }
  60. }
  61. }
  62. )
  63. )
  64. }
  65. menuViewController.actions = actions
  66. let menuPanelController = NCMenuPanelController()
  67. menuPanelController.parentPresenter = self
  68. menuPanelController.delegate = menuViewController
  69. menuPanelController.set(contentViewController: menuViewController)
  70. menuPanelController.track(scrollView: menuViewController.tableView)
  71. self.present(menuPanelController, animated: true, completion: nil)
  72. }
  73. }