Quellcode durchsuchen

create new class NCActivityIndicator

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana vor 2 Jahren
Ursprung
Commit
3a8f984ace

+ 6 - 3
iOSClient/Activity/NCActivity.swift

@@ -286,6 +286,7 @@ extension NCActivity: UITableViewDataSource {
         }
 
         // subject
+        cell.subject.text = activity.subject
         if activity.subjectRich.count > 0 {
 
             var subject = activity.subjectRich
@@ -351,10 +352,12 @@ extension NCActivity {
         guard !isFetchingActivity else { return }
         self.isFetchingActivity = true
 
-        if let height = self.tabBarController?.tabBar.frame.height {
-            NCActivityIndicator.shared.start(backgroundView: self.view, bottom: -height-20, style: .gray)
+        var bottom: CGFloat = 0
+        if let mainTabBar = self.tabBarController?.tabBar as? NCMainTabBar {
+            bottom = -mainTabBar.getHight() - 10
         }
-        
+        NCActivityIndicator.shared.start(backgroundView: self.view, bottom: bottom, style: .gray)
+
         let dispatchGroup = DispatchGroup()
         loadComments(disptachGroup: dispatchGroup)
 

+ 4 - 1
iOSClient/Activity/NCActivityTableViewCell.swift

@@ -23,6 +23,7 @@
 
 import Foundation
 import NCCommunication
+import FloatingPanel
 
 class NCActivityCollectionViewCell: UICollectionViewCell {
 
@@ -143,7 +144,9 @@ extension NCActivityTableViewCell: UICollectionViewDelegate {
 
             let fileNameLocalPath = CCUtility.getDirectoryProviderStorageOcId(activitySubjectRich.id, fileNameView: activitySubjectRich.name)!
 
-            NCActivityIndicator.shared.start(backgroundView: (appDelegate.window?.rootViewController?.view)!, blurEffect: true)
+            if let backgroundView = appDelegate.window?.rootViewController?.view {
+                NCActivityIndicator.shared.start(backgroundView: backgroundView, blurEffect: true)
+            }
 
             NCCommunication.shared.download(serverUrlFileName: serverUrlFileName, fileNameLocalPath: fileNameLocalPath, requestHandler: { _ in
 

+ 6 - 2
iOSClient/Main/NCMainTabBar.swift

@@ -28,6 +28,7 @@ class NCMainTabBar: UITabBar {
     private var fillColor: UIColor!
     private var shapeLayer: CALayer?
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
+    private let centerButtonY: CGFloat = -28
 
     public var menuRect: CGRect {
         get {
@@ -173,9 +174,8 @@ class NCMainTabBar: UITabBar {
         if let centerButton = self.viewWithTag(99) {
             centerButton.removeFromSuperview()
         }
-        let centerButtonHeight: CGFloat = 57
-        let centerButtonY: CGFloat = -28
 
+        let centerButtonHeight: CGFloat = 57
         let centerButton = UIButton(frame: CGRect(x: (self.bounds.width / 2)-(centerButtonHeight/2), y: centerButtonY, width: centerButtonHeight, height: centerButtonHeight))
 
         centerButton.setTitle("", for: .normal)
@@ -230,4 +230,8 @@ class NCMainTabBar: UITabBar {
             return nil
         }
     }
+
+    func getHight() -> CGFloat {
+        return (frame.size.height - centerButtonY)
+    }
 }

+ 1 - 1
iOSClient/Settings/CCAdvanced.m

@@ -416,7 +416,7 @@
     UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"" message:NSLocalizedString(@"_want_delete_cache_", nil) preferredStyle:UIAlertControllerStyleActionSheet];
     
     [alertController addAction: [UIAlertAction actionWithTitle:NSLocalizedString(@"_yes_", nil) style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
-        [[NCActivityIndicator shared] startWithBackgroundView:nil blurEffect:true bottom:0 top:0 style: UIActivityIndicatorViewStyleWhiteLarge];
+        [[NCActivityIndicator shared] startActivityWithBackgroundView:nil blurEffect:true style: UIActivityIndicatorViewStyleWhiteLarge];
         dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^(void) {
             [self clearCache];
         });

+ 16 - 20
iOSClient/Utility/NCActivityIndicator.swift

@@ -34,21 +34,27 @@ class NCActivityIndicator: NSObject {
     private var viewActivityIndicator: UIView?
     private var viewBackgroundActivityIndicator: UIView?
 
-    @objc func start(backgroundView: UIView? = nil, blurEffect: Bool = false, bottom: CGFloat = 0, top: CGFloat = 0, style: UIActivityIndicatorView.Style = .whiteLarge) {
+    @objc func startActivity(backgroundView: UIView?, blurEffect: Bool, style: UIActivityIndicatorView.Style) {
+        start(backgroundView: backgroundView, blurEffect: blurEffect, style: style)
+    }
+
+    func start(backgroundView: UIView? = nil, blurEffect: Bool = false, bottom: CGFloat? = nil, top: CGFloat? = nil, style: UIActivityIndicatorView.Style = .whiteLarge) {
 
         if self.activityIndicator != nil { stop() }
 
         DispatchQueue.main.async {
 
             self.activityIndicator = UIActivityIndicatorView(style: style)
-            guard let activityIndicator = self.activityIndicator else { return }
-            if self.viewBackgroundActivityIndicator != nil { return }
+            guard let activityIndicator = self.activityIndicator, self.viewBackgroundActivityIndicator == nil else { return }
 
             activityIndicator.color = NCBrandColor.shared.label
             activityIndicator.hidesWhenStopped = true
             activityIndicator.translatesAutoresizingMaskIntoConstraints = false
 
-            let sizeActivityIndicator = activityIndicator.frame.height + 50
+            var sizeActivityIndicator = activityIndicator.frame.height
+            if blurEffect {
+                sizeActivityIndicator += 50
+            }
 
             self.viewActivityIndicator = UIView(frame: CGRect(x: 0, y: 0, width: sizeActivityIndicator, height: sizeActivityIndicator))
             self.viewActivityIndicator?.translatesAutoresizingMaskIntoConstraints = false
@@ -96,23 +102,14 @@ class NCActivityIndicator: NSObject {
             guard let viewBackgroundActivityIndicator = self.viewBackgroundActivityIndicator else { return }
             viewBackgroundActivityIndicator.addSubview(viewActivityIndicator)
 
-            if bottom < 0 {
-                NSLayoutConstraint.activate([
-                    viewActivityIndicator.bottomAnchor.constraint(equalTo: viewBackgroundActivityIndicator.bottomAnchor, constant: bottom)
-                ])
-            } else if top > 0 {
-                NSLayoutConstraint.activate([
-                    viewActivityIndicator.topAnchor.constraint(equalTo: viewBackgroundActivityIndicator.topAnchor, constant: top)
-                ])
+            if let constant = bottom {
+                viewActivityIndicator.bottomAnchor.constraint(equalTo: viewBackgroundActivityIndicator.bottomAnchor, constant: constant).isActive = true
+            } else if let constant = top {
+                viewActivityIndicator.topAnchor.constraint(equalTo: viewBackgroundActivityIndicator.topAnchor, constant: constant).isActive = true
             } else {
-                NSLayoutConstraint.activate([
-                    viewActivityIndicator.centerYAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerYAnchor)
-                ])
+                viewActivityIndicator.centerYAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerYAnchor).isActive = true
             }
-
-            NSLayoutConstraint.activate([
-                viewActivityIndicator.centerXAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerXAnchor)
-            ])
+            viewActivityIndicator.centerXAnchor.constraint(equalTo: viewBackgroundActivityIndicator.centerXAnchor).isActive = true
 
             activityIndicator.startAnimating()
         }
@@ -149,4 +146,3 @@ class NCViewActivityIndicator: UIView {
         fatalError("init(coder:) has not been implemented")
     }
 }
-