Browse Source

Change user menu

marinofaggiana 4 years ago
parent
commit
8b589c15ee

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -276,6 +276,7 @@
 		F7BAADCB1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */; };
 		F7BAADCC1ED5A87C00B7EAD4 /* NCManageDatabase.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7BAADB51ED5A87C00B7EAD4 /* NCManageDatabase.swift */; };
 		F7BF1B431D51E893000854F6 /* CCLogin.m in Sources */ = {isa = PBXBuildFile; fileRef = F7BF1B401D51E893000854F6 /* CCLogin.m */; };
+		F7C174DD25E509EE004078E4 /* NCChangeUserMenu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C174DC25E509EE004078E4 /* NCChangeUserMenu.swift */; };
 		F7C1EEA525053A9C00866ACC /* NCDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7C1EEA425053A9C00866ACC /* NCDataSource.swift */; };
 		F7C40BEF219994ED0004137E /* KTVCocoaHTTPServer.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40BEE219994ED0004137E /* KTVCocoaHTTPServer.framework */; };
 		F7C40BF1219994F20004137E /* KTVHTTPCache.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F7C40BF0219994F20004137E /* KTVHTTPCache.framework */; };
@@ -643,6 +644,7 @@
 		F7BF1B401D51E893000854F6 /* CCLogin.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCLogin.m; sourceTree = "<group>"; };
 		F7C0F46E1C8880540059EC54 /* ShareViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; lineEnding = 0; path = ShareViewController.h; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objcpp; };
 		F7C0F46F1C8880540059EC54 /* ShareViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ShareViewController.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
+		F7C174DC25E509EE004078E4 /* NCChangeUserMenu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NCChangeUserMenu.swift; sourceTree = "<group>"; };
 		F7C1EEA425053A9C00866ACC /* NCDataSource.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCDataSource.swift; sourceTree = "<group>"; };
 		F7C40BE221998C050004137E /* PDFGenerator.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PDFGenerator.framework; path = Carthage/Build/iOS/PDFGenerator.framework; sourceTree = "<group>"; };
 		F7C40BE421998D5A0004137E /* MGSwipeTableCell.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = MGSwipeTableCell.framework; path = Carthage/Build/iOS/MGSwipeTableCell.framework; sourceTree = "<group>"; };
@@ -798,6 +800,7 @@
 			isa = PBXGroup;
 			children = (
 				3781B9AF23DB2B7E006B4B1D /* AppDelegate+Menu.swift */,
+				F7C174DC25E509EE004078E4 /* NCChangeUserMenu.swift */,
 				F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */,
 				F7CBC31B24F78E79004D3812 /* NCSortMenu.swift */,
 				F710D2012405826100A6033D /* NCViewer+Menu.swift */,
@@ -2110,6 +2113,7 @@
 				F7725A60251F33BB00D125E0 /* NCFiles.swift in Sources */,
 				F704B5E52430AA8000632F5F /* NCCreateFormUploadConflict.swift in Sources */,
 				F765608F23BF813600765969 /* NCContentPresenter.swift in Sources */,
+				F7C174DD25E509EE004078E4 /* NCChangeUserMenu.swift in Sources */,
 				F70CEF5623E9C7E50007035B /* UIColor+Extensions.swift in Sources */,
 				F75AC2431F1F62450073EC19 /* NCManageAutoUploadFileName.swift in Sources */,
 				F7C7B489245EBA4100D93E60 /* NCViewerQuickLook.swift in Sources */,

+ 11 - 6
iOSClient/Login/NCLoginWeb.swift

@@ -41,12 +41,14 @@ class NCLoginWeb: UIViewController {
     override func viewDidLoad() {
         super.viewDidLoad()
         
-        if (NCBrandOptions.shared.use_login_web_personalized) {
-            if let accountCount = NCManageDatabase.shared.getAccounts()?.count {
-                if(accountCount > 0) {
-                    self.navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .stop, target: self, action: #selector(self.closeView(sender:)))
-                }
-            }
+        let accountCount = NCManageDatabase.shared.getAccounts()?.count ?? 0
+        
+        if NCBrandOptions.shared.use_login_web_personalized  && accountCount > 0 {
+            navigationItem.leftBarButtonItem = UIBarButtonItem.init(barButtonSystemItem: .stop, target: self, action: #selector(self.closeView(sender:)))
+        }
+        
+        if accountCount > 0 {
+            navigationItem.rightBarButtonItem = UIBarButtonItem.init(image: UIImage(named: "users")!.image(color: NCBrandColor.shared.textView, size: 35), style: .plain, target: self, action:  #selector(self.changeUser(sender:)))
         }
         
         let config = WKWebViewConfiguration()
@@ -113,6 +115,9 @@ class NCLoginWeb: UIViewController {
         self.dismiss(animated: true, completion: nil)
     }
     
+    @objc func changeUser(sender: UIBarButtonItem) {
+        
+    }
 }
 
 extension NCLoginWeb: WKNavigationDelegate {

+ 82 - 0
iOSClient/Main/Menu/NCChangeUserMenu.swift

@@ -0,0 +1,82 @@
+//
+//  NCChangeUserMenu.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 23/02/2021.
+//  Copyright © 2020 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import FloatingPanel
+import NCCommunication
+
+class NCChangeUserMenu: NSObject {
+    
+    @objc func toggleMenu(viewController: UIViewController) {
+        
+        let mainMenuViewController = UIStoryboard.init(name: "NCMenu", bundle: nil).instantiateViewController(withIdentifier: "NCMainMenuTableViewController") as! NCMainMenuTableViewController
+        mainMenuViewController.actions = self.initUsersMenu()
+
+        let menuPanelController = NCMenuPanelController()
+        menuPanelController.parentPresenter = viewController
+        menuPanelController.delegate = mainMenuViewController
+        menuPanelController.set(contentViewController: mainMenuViewController)
+        menuPanelController.track(scrollView: mainMenuViewController.tableView)
+
+        viewController.present(menuPanelController, animated: true, completion: nil)
+    }
+    
+    private func initUsersMenu() -> [NCMenuAction] {
+        
+        var actions = [NCMenuAction]()
+        let accounts = NCManageDatabase.shared.getAllAccount()
+        var avatar = UIImage(named: "avatarCredentials")!.image(color: NCBrandColor.shared.icon, size: 50)
+        
+        for account in accounts {
+            
+            var fileNamePath = CCUtility.getDirectoryUserData() + "/" + CCUtility.getStringUser(account.user, urlBase: account.urlBase) + "_" + account.user
+            fileNamePath = fileNamePath + ".png"
+            if var userImage = UIImage(contentsOfFile: fileNamePath) {
+                userImage = userImage.resizeImage(size: CGSize(width: 50, height: 50), isAspectRation: true)!
+                let userImageView = UIImageView(image: userImage)
+                userImageView.avatar(roundness: 2, borderWidth: 1, borderColor: NCBrandColor.shared.avatarBorder, backgroundColor: .clear)
+                UIGraphicsBeginImageContext(userImageView.bounds.size)
+                userImageView.layer.render(in: UIGraphicsGetCurrentContext()!)
+                if let newAvatar = UIGraphicsGetImageFromCurrentImageContext() {
+                    avatar = newAvatar
+                }
+                UIGraphicsEndImageContext()
+            }
+            
+            actions.append(
+                NCMenuAction(
+                    title: account.account,
+                    icon: avatar,
+                    onTitle: account.account,
+                    onIcon: avatar,
+                    selected: account.active == true,
+                    on: account.active == true,
+                    action: { menuAction in
+                        
+                    }
+                )
+            )
+        }
+       
+        return actions
+    }
+}