marinofaggiana 4 年之前
父节点
当前提交
4bfe99ed93
共有 3 个文件被更改,包括 110 次插入145 次删除
  1. 0 3
      iOSClient/AppDelegate.h
  2. 1 112
      iOSClient/AppDelegate.m
  3. 109 30
      iOSClient/Main/NCMainTabBar.swift

+ 0 - 3
iOSClient/AppDelegate.h

@@ -142,9 +142,6 @@
 - (void)configDynamicShortcutItems;
 - (BOOL)handleShortCutItem:(UIApplicationShortcutItem *)shortcutItem;
 
-// TabBarController
-- (void)createTabBarController:(UITabBarController *)tabBarController;
-
 // Push Notification
 - (void)pushNotification;
 

+ 1 - 112
iOSClient/AppDelegate.m

@@ -163,10 +163,7 @@
     }
     
     // TabBar Controller
-    UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
-    if ([tabBarController isKindOfClass:[UITabBarController class]]) {
-        [self createTabBarController:tabBarController];
-    }
+    //[self createTabBarController];
     
     if ([NCBrandOptions sharedInstance].disable_intro) {
         [CCUtility setIntro:YES];
@@ -826,114 +823,6 @@
     }
 }
 
-#pragma --------------------------------------------------------------------------------------------
-#pragma mark ===== TabBarController =====
-#pragma --------------------------------------------------------------------------------------------
-
-- (void)createTabBarController:(UITabBarController *)tabBarController
-{
-    UITabBarItem *item;
-    NSLayoutConstraint *constraint;
-    CGFloat safeAreaBottom = safeAreaBottom = [UIApplication sharedApplication].delegate.window.safeAreaInsets.bottom;
-   
-    // File
-    item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFile];
-    [item setTitle:NSLocalizedString(@"_home_", nil)];
-    item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarFiles"] width:50 height:50 color:NCBrandColor.sharedInstance.brandElement];
-    item.selectedImage = item.image;
-    
-    // Favorites
-    item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexFavorite];
-    [item setTitle:NSLocalizedString(@"_favorites_", nil)];
-    item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"favorite"] width:50 height:50 color:NCBrandColor.sharedInstance.brandElement];
-    item.selectedImage = item.image;
-    
-    // (PLUS INVISIBLE)
-    item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexPlusHide];
-    item.title = @"";
-    item.image = nil;
-    item.enabled = false;
-    
-    // Media
-    item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexMedia];
-    [item setTitle:NSLocalizedString(@"_media_", nil)];
-    item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"media"] width:50 height:50 color:NCBrandColor.sharedInstance.brandElement];
-    item.selectedImage = item.image;
-    
-    // More
-    item = [tabBarController.tabBar.items objectAtIndex: k_tabBarApplicationIndexMore];
-    [item setTitle:NSLocalizedString(@"_more_", nil)];
-    item.image = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarMore"] width:50 height:50 color:NCBrandColor.sharedInstance.brandElement];
-    item.selectedImage = item.image;
-    
-    // Plus Button
-    int buttonSize = 57;
-    UIImage *buttonImage = [CCGraphics changeThemingColorImage:[UIImage imageNamed:@"tabBarPlus"] width:120 height:120 color:UIColor.whiteColor];
-    UIButton *buttonPlus = [UIButton buttonWithType:UIButtonTypeCustom];
-    buttonPlus.tag = 99;
-    buttonPlus.accessibilityLabel = NSLocalizedString(@"_accessibility_add_upload_", nil);
-    [buttonPlus setImage:buttonImage forState:UIControlStateNormal];
-    buttonPlus.backgroundColor = NCBrandColor.sharedInstance.brandElement;
-    buttonPlus.layer.cornerRadius = buttonSize / 2;
-    buttonPlus.layer.masksToBounds = NO;
-    buttonPlus.layer.shadowOffset = CGSizeMake(0, 0);
-    buttonPlus.layer.shadowRadius = 3.0f;
-    buttonPlus.layer.shadowOpacity = 0.5;
-    
-
-    [buttonPlus addTarget:self action:@selector(handleTouchTabbarCenter:) forControlEvents:UIControlEventTouchUpInside];
-    
-    [buttonPlus setTranslatesAutoresizingMaskIntoConstraints:NO];
-    [tabBarController.tabBar addSubview:buttonPlus];
-    
-
-    if (safeAreaBottom > 0) {
-        
-        // X
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
-        [tabBarController.view addConstraint:constraint];
-        // Y
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeTop multiplier:1.0 constant:-(buttonSize / 2)];
-        [tabBarController.view addConstraint:constraint];
-        // Width
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0 constant:buttonSize];
-        [tabBarController.view addConstraint:constraint];
-        // Height
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0 constant:buttonSize];
-        [tabBarController.view addConstraint:constraint];
-        
-    } else {
-        
-        // X
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0];
-        [tabBarController.view addConstraint:constraint];
-        // Y
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:tabBarController.tabBar attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:-(buttonSize / 2)];
-        [tabBarController.view addConstraint:constraint];
-        // Width
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0 constant:buttonSize];
-        [tabBarController.view addConstraint:constraint];
-        // Height
-        constraint = [NSLayoutConstraint constraintWithItem:buttonPlus attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:0 multiplier:1.0 constant:buttonSize];
-        [tabBarController.view addConstraint:constraint];
-    }
-}
-
-- (void)handleTouchTabbarCenter:(id)sender
-{
-    // Test Maintenance
-    if (self.maintenanceMode)
-        return;
-    
-    tableDirectory *tableDirectory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", self.account, self.activeServerUrl]];
-    
-    if ([tableDirectory.permissions containsString:@"CK"]) {
-        [self showMenuInViewController:self.window.rootViewController];
-    } else {
-        [[NCContentPresenter shared] messageNotification:@"_warning_" description:@"_no_permission_add_file_" delay:k_dismissAfterSecond type:messageTypeInfo errorCode:k_CCErrorInternalError forced:false];
-    }
-}
-
 #pragma --------------------------------------------------------------------------------------------
 #pragma mark ===== Theming Color =====
 #pragma --------------------------------------------------------------------------------------------

+ 109 - 30
iOSClient/Main/NCMainTabBar.swift

@@ -25,6 +25,10 @@ import Foundation
 
 @IBDesignable class NCMainTabBar: UITabBar {
 
+    private var fillColor: UIColor!
+    private var shapeLayer: CALayer?
+    private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    
     override var traitCollection: UITraitCollection {
         return UITraitCollection(horizontalSizeClass: .compact)
     }
@@ -38,16 +42,36 @@ import Foundation
             self.setNeedsDisplay()
         }
     }
-    
-    private var fillColor: UIColor!
-    private var shapeLayer: CALayer?
+        
+    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
+        let button = self.viewWithTag(99)
+        if self.bounds.contains(point) || (button != nil && button!.frame.contains(point)) {
+            return true
+        } else {
+            return false
+        }
+    }
+
+    override func layoutSubviews() {
+        
+        super.layoutSubviews()
+        layer.shadowPath = createPath()
+        layer.shadowRadius = 5
+        layer.shadowOffset = .zero
+        layer.shadowOpacity = 0.25
+    }
+
+    override func draw(_ rect: CGRect) {
+        addShape()
+        createButtons()
+    }
 
     private func addShape() {
+        
         let shapeLayer = CAShapeLayer()
         shapeLayer.path = createPath()
         shapeLayer.fillColor = backgroundColor?.cgColor
 
-
         if let oldShapeLayer = self.shapeLayer {
             self.layer.replaceSublayer(oldShapeLayer, with: shapeLayer)
         } else {
@@ -56,20 +80,8 @@ import Foundation
 
         self.shapeLayer = shapeLayer
     }
-
-    override func layoutSubviews() {
-        super.layoutSubviews()
-        self.layer.shadowPath = createPath()
-        self.layer.shadowRadius = 5
-        self.layer.shadowOffset = .zero
-        self.layer.shadowOpacity = 0.25
-    }
-
-    override func draw(_ rect: CGRect) {
-        self.addShape()
-    }
-
-    func createPath() -> CGPath {
+    
+    private func createPath() -> CGPath {
         let height: CGFloat = 28
         let margin: CGFloat = 8
         let path = UIBezierPath()
@@ -87,19 +99,86 @@ import Foundation
 
         return path.cgPath
     }
-
-    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
-        let button = self.viewWithTag(99)
-        if self.bounds.contains(point) || (button != nil && button!.frame.contains(point)) {
-            return true
-        } else {
-            return false
+    
+    private func createButtons() {
+       
+        // File
+        if let item = items?[Int(k_tabBarApplicationIndexFile)] {
+            item.title = NSLocalizedString("_home_", comment: "")
+            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "tabBarFiles"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement)
+            item.selectedImage = item.image
+        }
+        
+        // Favorite
+        if let item = items?[Int(k_tabBarApplicationIndexFavorite)] {
+            item.title = NSLocalizedString("_favorites_", comment: "")
+            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "favorite"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement)
+            item.selectedImage = item.image
+        }
+        
+        // +
+        if let item = items?[Int(k_tabBarApplicationIndexPlusHide)] {
+            item.title = ""
+            item.image = nil
+            item.isEnabled = false
+        }
+        
+        // Media
+        if let item = items?[Int(k_tabBarApplicationIndexMedia)] {
+            item.title = NSLocalizedString("_media_", comment: "")
+            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "media"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement)
+            item.selectedImage = item.image
+        }
+        
+        // More
+        if let item = items?[Int(k_tabBarApplicationIndexMore)] {
+            item.title = NSLocalizedString("_more_", comment: "")
+            item.image = CCGraphics.changeThemingColorImage(UIImage(named: "tabBarMore"), width: 50, height: 50, color: NCBrandColor.sharedInstance.brandElement)
+            item.selectedImage = item.image
+        }
+        
+        // Center button
+        
+        if let centerButton = self.viewWithTag(99) {
+            centerButton.removeFromSuperview()
+        }
+        let centerButtonHeight: CGFloat = 57
+        let centerButtonY: CGFloat = -28
+        
+        let centerButton = UIButton(frame: CGRect(x: (self.bounds.width / 2)-(centerButtonHeight/2), y: centerButtonY, width: centerButtonHeight, height: centerButtonHeight))
+        
+        centerButton.setTitle("", for: .normal)
+        centerButton.setImage(CCGraphics.changeThemingColorImage(UIImage(named: "tabBarPlus"), width: 100, height: 100, color: .white), for: .normal)
+        centerButton.backgroundColor = NCBrandColor.sharedInstance.brandElement
+        centerButton.tintColor = UIColor.white
+        centerButton.tag = 99
+        centerButton.accessibilityLabel = NSLocalizedString("_accessibility_add_upload_", comment: "")
+        centerButton.layer.cornerRadius = centerButton.frame.size.width / 2.0
+        centerButton.layer.masksToBounds = false
+        centerButton.layer.shadowOffset = CGSize(width: 0, height: 0)
+        centerButton.layer.shadowRadius = 3.0
+        centerButton.layer.shadowOpacity = 0.5
+        
+        centerButton.addTarget(self, action: #selector(self.centerButtonAction), for: .touchUpInside)
+        
+        self.addSubview(centerButton)
+    }
+    
+    // Menu Button Touch Action
+    @objc func centerButtonAction(sender: UIButton) {
+        
+        if appDelegate.maintenanceMode { return }
+        if let directory = NCManageDatabase.sharedInstance.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", appDelegate.account, appDelegate.activeServerUrl)) {
+            
+            if !directory.permissions.contains("CK") {
+                NCContentPresenter.shared.messageNotification("_warning_", description: "_no_permission_add_file_", delay: TimeInterval(k_dismissAfterSecond), type: NCContentPresenter.messageType.info, errorCode: Int(k_CCErrorInternalError))
+                return
+            }
+        }
+        
+        if let viewController = self.window?.rootViewController {
+            appDelegate.showMenuIn(viewController: viewController)
         }
     }
-
 }
 
-extension CGFloat {
-    var degreesToRadians: CGFloat { return self * .pi / 180 }
-    var radiansToDegrees: CGFloat { return self * 180 / .pi }
-}