Эх сурвалжийг харах

Fix linting issues

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 жил өмнө
parent
commit
b1ec2922b1

+ 0 - 2
.swiftlint.yml

@@ -3,7 +3,6 @@ opt_in_rules: # some rules are turned off by default, so you need to opt-in
   - empty_count
   - empty_count
   - empty_string
   - empty_string
   - explicit_init
   - explicit_init
-  - file_types_order
   - unneeded_parentheses_in_closure_argument
   - unneeded_parentheses_in_closure_argument
 
 
 empty_count:
 empty_count:
@@ -81,7 +80,6 @@ excluded:
   - iOSClient/Menu/NCCollectionViewCommon+Menu.swift
   - iOSClient/Menu/NCCollectionViewCommon+Menu.swift
   - iOSClient/Menu/NCLoginWeb+Menu.swift
   - iOSClient/Menu/NCLoginWeb+Menu.swift
   - iOSClient/Menu/NCMedia+Menu.swift
   - iOSClient/Menu/NCMedia+Menu.swift
-  - iOSClient/Menu/NCMenu.swift
   - iOSClient/Menu/NCSortMenu.swift
   - iOSClient/Menu/NCSortMenu.swift
   - iOSClient/Menu/NCViewer+Menu.swift
   - iOSClient/Menu/NCViewer+Menu.swift
   - iOSClient/More/NCMore.swift
   - iOSClient/More/NCMore.swift

+ 6 - 3
Nextcloud.xcodeproj/project.pbxproj

@@ -36,9 +36,10 @@
 		AF817EF2274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF2274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF3274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF3274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF4274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
 		AF817EF4274BC781009ED85B /* NCUserBaseUrl.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */; };
-		AFD33240276A02C100F5AE02 /* UIApplication+Orientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFD3323F276A02C000F5AE02 /* UIApplication+Orientation.swift */; };
 		AF8ED1FC2757821000B8DBC4 /* NextcloudTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8ED1FB2757821000B8DBC4 /* NextcloudTests.swift */; };
 		AF8ED1FC2757821000B8DBC4 /* NextcloudTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8ED1FB2757821000B8DBC4 /* NextcloudTests.swift */; };
 		AF8ED2032757822700B8DBC4 /* NCGlobalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8ED2022757822700B8DBC4 /* NCGlobalTests.swift */; };
 		AF8ED2032757822700B8DBC4 /* NCGlobalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF8ED2022757822700B8DBC4 /* NCGlobalTests.swift */; };
+		AF935067276B84E700BD078F /* NCMenu+FloatingPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */; };
+		AFD33240276A02C100F5AE02 /* UIApplication+Orientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = AFD3323F276A02C000F5AE02 /* UIApplication+Orientation.swift */; };
 		D575039F27146F93008DC9DC /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
 		D575039F27146F93008DC9DC /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7A0D1342591FBC5008F8A13 /* String+Extensions.swift */; };
 		D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
 		D5B6AA7827200C7200D49C24 /* NCActivityTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */; };
 		F700222C1EC479840080073F /* Custom.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F700222B1EC479840080073F /* Custom.xcassets */; };
 		F700222C1EC479840080073F /* Custom.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = F700222B1EC479840080073F /* Custom.xcassets */; };
@@ -462,10 +463,11 @@
 		AF4BF61827562A4B0081CEEF /* NCManageDatabse+Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabse+Metadata.swift"; sourceTree = "<group>"; };
 		AF4BF61827562A4B0081CEEF /* NCManageDatabse+Metadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabse+Metadata.swift"; sourceTree = "<group>"; };
 		AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Activity.swift"; sourceTree = "<group>"; };
 		AF4BF61D27562B3F0081CEEF /* NCManageDatabase+Activity.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCManageDatabase+Activity.swift"; sourceTree = "<group>"; };
 		AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCUserBaseUrl.swift; sourceTree = "<group>"; };
 		AF817EF0274BC781009ED85B /* NCUserBaseUrl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCUserBaseUrl.swift; sourceTree = "<group>"; };
-		AFD3323F276A02C000F5AE02 /* UIApplication+Orientation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+Orientation.swift"; sourceTree = "<group>"; };
 		AF8ED1F92757821000B8DBC4 /* NextcloudTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		AF8ED1F92757821000B8DBC4 /* NextcloudTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = NextcloudTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
 		AF8ED1FB2757821000B8DBC4 /* NextcloudTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudTests.swift; sourceTree = "<group>"; };
 		AF8ED1FB2757821000B8DBC4 /* NextcloudTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NextcloudTests.swift; sourceTree = "<group>"; };
 		AF8ED2022757822700B8DBC4 /* NCGlobalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCGlobalTests.swift; sourceTree = "<group>"; };
 		AF8ED2022757822700B8DBC4 /* NCGlobalTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCGlobalTests.swift; sourceTree = "<group>"; };
+		AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NCMenu+FloatingPanel.swift"; sourceTree = "<group>"; };
+		AFD3323F276A02C000F5AE02 /* UIApplication+Orientation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+Orientation.swift"; sourceTree = "<group>"; };
 		D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
 		D5B6AA7727200C7200D49C24 /* NCActivityTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCActivityTableViewCell.swift; sourceTree = "<group>"; };
 		F700222B1EC479840080073F /* Custom.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Custom.xcassets; sourceTree = "<group>"; };
 		F700222B1EC479840080073F /* Custom.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Custom.xcassets; sourceTree = "<group>"; };
 		F700510022DF63AC003A3356 /* NCShare.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCShare.storyboard; sourceTree = "<group>"; };
 		F700510022DF63AC003A3356 /* NCShare.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCShare.storyboard; sourceTree = "<group>"; };
@@ -912,6 +914,7 @@
 			children = (
 			children = (
 				3704EB2923D5A58400455C5B /* NCMenu.storyboard */,
 				3704EB2923D5A58400455C5B /* NCMenu.storyboard */,
 				371B5A2D23D0B04500FAFAE9 /* NCMenu.swift */,
 				371B5A2D23D0B04500FAFAE9 /* NCMenu.swift */,
+				AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */,
 				3781B9AF23DB2B7E006B4B1D /* AppDelegate+Menu.swift */,
 				3781B9AF23DB2B7E006B4B1D /* AppDelegate+Menu.swift */,
 				8491B1CC273BBA82001C8C5B /* UIViewController+Menu.swift */,
 				8491B1CC273BBA82001C8C5B /* UIViewController+Menu.swift */,
 				F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */,
 				F77A697C250A0FBC00FF1708 /* NCCollectionViewCommon+Menu.swift */,
@@ -2278,6 +2281,7 @@
 				F70B866E2642A21300ED5349 /* NCBackgroundImageColor.swift in Sources */,
 				F70B866E2642A21300ED5349 /* NCBackgroundImageColor.swift in Sources */,
 				F78ACD4021903CC20088454D /* NCGridCell.swift in Sources */,
 				F78ACD4021903CC20088454D /* NCGridCell.swift in Sources */,
 				F75B0ABD244C4DBB00E58DCA /* NCFunctionCenter.swift in Sources */,
 				F75B0ABD244C4DBB00E58DCA /* NCFunctionCenter.swift in Sources */,
+				AF935067276B84E700BD078F /* NCMenu+FloatingPanel.swift in Sources */,
 				F702F2CD25EE5B4F008F8E80 /* AppDelegate.swift in Sources */,
 				F702F2CD25EE5B4F008F8E80 /* AppDelegate.swift in Sources */,
 				F769454022E9F077000A798A /* NCSharePaging.swift in Sources */,
 				F769454022E9F077000A798A /* NCSharePaging.swift in Sources */,
 				F78ACD4221903CE00088454D /* NCListCell.swift in Sources */,
 				F78ACD4221903CE00088454D /* NCListCell.swift in Sources */,
@@ -2369,7 +2373,6 @@
 				F70D7C3725FFBF82002B9E34 /* NCCollectionViewCommon.swift in Sources */,
 				F70D7C3725FFBF82002B9E34 /* NCCollectionViewCommon.swift in Sources */,
 				F7020FCE2233D7F700B7297D /* NCCreateFormUploadVoiceNote.swift in Sources */,
 				F7020FCE2233D7F700B7297D /* NCCreateFormUploadVoiceNote.swift in Sources */,
 				F7134186259747BA00768D21 /* NCPushNotification.m in Sources */,
 				F7134186259747BA00768D21 /* NCPushNotification.m in Sources */,
-				AF70F8AC2769FF0000093456 /* (null) in Sources */,
 				F726EEEC1FED1C820030B9C8 /* NCEndToEndInitialize.swift in Sources */,
 				F726EEEC1FED1C820030B9C8 /* NCEndToEndInitialize.swift in Sources */,
 				F79A65C62191D95E00FF6DCC /* NCSelect.swift in Sources */,
 				F79A65C62191D95E00FF6DCC /* NCSelect.swift in Sources */,
 				F75D19E325EFE09000D74598 /* NCTrash+Menu.swift in Sources */,
 				F75D19E325EFE09000D74598 /* NCTrash+Menu.swift in Sources */,

+ 2 - 2
Nextcloud.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved

@@ -51,8 +51,8 @@
         "repositoryURL": "https://github.com/scenee/FloatingPanel",
         "repositoryURL": "https://github.com/scenee/FloatingPanel",
         "state": {
         "state": {
           "branch": null,
           "branch": null,
-          "revision": "ca7596e1cae161415f54059a8c44b82c95724160",
-          "version": "1.7.6"
+          "revision": "0fbbbc8d99b4dfe58bb1dd704d14b45f35b46584",
+          "version": "2.5.1"
         }
         }
       },
       },
       {
       {

+ 79 - 0
iOSClient/Menu/NCMenu+FloatingPanel.swift

@@ -0,0 +1,79 @@
+//
+//  NCMenu+FloatingPanel.swift
+//  Nextcloud
+//
+//  Created by Philippe Weidmann on 16.12.21.
+//  Copyright © 2021 Henrik Storch All rights reserved.
+//
+//  Author Henrik Storch <henrik.storch@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 Foundation
+import FloatingPanel
+
+class NCMenuFloatingPanelLayout: FloatingPanelLayout {
+    var position: FloatingPanelPosition = .bottom
+
+    var initialState: FloatingPanelState = .full
+
+    var anchors: [FloatingPanelState: FloatingPanelLayoutAnchoring] {
+        [
+            .full: FloatingPanelLayoutAnchor(absoluteInset: topInset, edge: .top, referenceGuide: .superview)
+        ]
+    }
+
+    let topInset: CGFloat
+
+    init(numberOfActions: Int) {
+        // sometimes UIScreen.main.bounds.size.height is not updated correctly
+        // this ensures we use the correct height value
+        // can't use `layoutFor size` since menu is dieplayed on top of the whole screen not just the VC
+        let screenHeight = UIApplication.shared.isLandscape
+        ? min(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)
+        : max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)
+        let bottomInset = UIApplication.shared.keyWindow?.rootViewController?.view.safeAreaInsets.bottom ?? 0
+        let panelHeight = CGFloat(numberOfActions * 60) + bottomInset
+
+        topInset = max(48, screenHeight - panelHeight)
+    }
+
+    func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] {
+        return [
+            surfaceView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
+            surfaceView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0)
+        ]
+    }
+
+    func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
+        return 0.2
+    }
+}
+
+class NCMenuPanelController: FloatingPanelController {
+
+    var parentPresenter: UIViewController?
+
+    // MARK: - View Life Cycle
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+
+        self.surfaceView.backgroundColor = NCBrandColor.shared.systemBackground
+        self.isRemovalInteractionEnabled = true
+        self.backdropView.dismissalTapGestureRecognizer.isEnabled = true
+        self.surfaceView.layer.cornerRadius = 16
+    }
+}

+ 9 - 63
iOSClient/Menu/NCMenu.swift

@@ -32,9 +32,9 @@ class NCMenu: UITableViewController {
 
 
     var actions = [NCMenuAction]()
     var actions = [NCMenuAction]()
 
 
-    static func makeNCMenu(with actions: [NCMenuAction]) -> NCMenu {
-        let menuViewController = UIStoryboard(name: "NCMenu", bundle: nil).instantiateInitialViewController() as! NCMenu
-        menuViewController.actions = actions
+    static func makeNCMenu(with actions: [NCMenuAction]) -> NCMenu? {
+        let menuViewController = UIStoryboard(name: "NCMenu", bundle: nil).instantiateInitialViewController() as? NCMenu
+        menuViewController?.actions = actions
         return menuViewController
         return menuViewController
     }
     }
 
 
@@ -66,19 +66,19 @@ class NCMenu: UITableViewController {
         let cell = tableView.dequeueReusableCell(withIdentifier: "menuActionCell", for: indexPath)
         let cell = tableView.dequeueReusableCell(withIdentifier: "menuActionCell", for: indexPath)
         cell.tintColor = NCBrandColor.shared.customer
         cell.tintColor = NCBrandColor.shared.customer
         let action = actions[indexPath.row]
         let action = actions[indexPath.row]
-        let actionIconView = cell.viewWithTag(1) as! UIImageView
-        let actionNameLabel = cell.viewWithTag(2) as! UILabel
+        let actionIconView = cell.viewWithTag(1) as? UIImageView
+        let actionNameLabel = cell.viewWithTag(2) as? UILabel
 
 
         if action.action == nil {
         if action.action == nil {
             cell.selectionStyle = .none
             cell.selectionStyle = .none
         }
         }
 
 
         if action.isOn {
         if action.isOn {
-            actionIconView.image = action.onIcon
-            actionNameLabel.text = action.onTitle
+            actionIconView?.image = action.onIcon
+            actionNameLabel?.text = action.onTitle
         } else {
         } else {
-            actionIconView.image = action.icon
-            actionNameLabel.text = action.title
+            actionIconView?.image = action.icon
+            actionNameLabel?.text = action.title
         }
         }
 
 
         cell.accessoryType = action.selectable && action.selected ? .checkmark : .none
         cell.accessoryType = action.selectable && action.selected ? .checkmark : .none
@@ -116,60 +116,6 @@ extension NCMenu: FloatingPanelControllerDelegate {
     }
     }
 }
 }
 
 
-class NCMenuFloatingPanelLayout: FloatingPanelLayout {
-    var position: FloatingPanelPosition = .bottom
-
-    var initialState: FloatingPanelState = .full
-
-    var anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] {
-        [
-            .full: FloatingPanelLayoutAnchor(absoluteInset: topInset, edge: .top, referenceGuide: .superview)
-        ]
-    }
-
-    let topInset: CGFloat
-
-    init(numberOfActions: Int) {
-        // sometimes UIScreen.main.bounds.size.height is not updated correctly
-        // this ensures we use the correct height value
-        // can't use `layoutFor size` since menu is dieplayed on top of the whole screen not just the VC
-        let screenHeight = UIApplication.shared.isLandscape
-        ? min(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)
-        : max(UIScreen.main.bounds.size.width, UIScreen.main.bounds.size.height)
-        let bottomInset = UIApplication.shared.keyWindow?.rootViewController?.view.safeAreaInsets.bottom ?? 0
-        let panelHeight = CGFloat(numberOfActions * 60) + bottomInset
-
-        topInset = max(48, screenHeight - panelHeight)
-    }
-
-    func prepareLayout(surfaceView: UIView, in view: UIView) -> [NSLayoutConstraint] {
-        return [
-            surfaceView.leftAnchor.constraint(equalTo: view.leftAnchor, constant: 0),
-            surfaceView.rightAnchor.constraint(equalTo: view.rightAnchor, constant: 0)
-        ]
-    }
-
-    func backdropAlpha(for state: FloatingPanelState) -> CGFloat {
-        return 0.2
-    }
-}
-
-class NCMenuPanelController: FloatingPanelController {
-
-    var parentPresenter: UIViewController?
-
-    // MARK: - View Life Cycle
-
-    override func viewDidLoad() {
-        super.viewDidLoad()
-
-        self.surfaceView.backgroundColor = NCBrandColor.shared.systemBackground
-        self.isRemovalInteractionEnabled = true
-        self.backdropView.dismissalTapGestureRecognizer.isEnabled = true
-        self.surfaceView.layer.cornerRadius = 16
-    }
-}
-
 class NCMenuAction {
 class NCMenuAction {
 
 
     let title: String
     let title: String

+ 4 - 1
iOSClient/Menu/UIViewController+Menu.swift

@@ -106,7 +106,10 @@ extension UIViewController {
     }
     }
 
 
     func presentMenu(with actions: [NCMenuAction]) {
     func presentMenu(with actions: [NCMenuAction]) {
-        let menuViewController = NCMenu.makeNCMenu(with: actions)
+        guard let menuViewController = NCMenu.makeNCMenu(with: actions) else {
+            NCContentPresenter.shared.showGenericError(description: "_internal_generic_error_")
+            return
+        }
 
 
         let menuPanelController = NCMenuPanelController()
         let menuPanelController = NCMenuPanelController()
         menuPanelController.parentPresenter = self
         menuPanelController.parentPresenter = self