marinofaggiana 5 éve
szülő
commit
dc349559e3

+ 1 - 1
iOSClient/Main/CCMain.h

@@ -56,7 +56,7 @@
 
 @property (nonatomic, strong) NSString *serverUrl;
 @property (nonatomic, strong) NSString *titleMain;
-@property (nonatomic, strong) NSString *richWorkspace;
+@property (nonatomic, strong) NSString *richWorkspaceText;
 @property (nonatomic, weak) CCDetail *detailViewController;
 @property (nonatomic, strong) UISearchController *searchController;
 @property (nonatomic, strong) UIView *reMenuBackgroundView;

+ 10 - 9
iOSClient/Main/CCMain.m

@@ -219,7 +219,7 @@
     
     // Get RichWorkspace
     tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, self.serverUrl]];
-    self.richWorkspace = directory.richWorkspace;
+    self.richWorkspaceText = directory.richWorkspace;
     
     // Query data source
     if (self.searchController.isActive == false) {
@@ -340,6 +340,9 @@
         searchTextView.textColor = NCBrandColor.sharedInstance.textView;
     }
     
+    // Rich Workspace
+    [self.viewRichWorkspace loadWithRichWorkspaceText:self.richWorkspaceText];
+    
     // Title
     [self setTitle];
     
@@ -1141,7 +1144,7 @@
     
     // RichWorkspace
     tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", appDelegate.activeAccount, self.serverUrl]];
-    self.richWorkspace = directory.richWorkspace;
+    self.richWorkspaceText = directory.richWorkspace;
     [self setTableViewHeader];
     
     // Load Datasource
@@ -1158,7 +1161,7 @@
             
             // Rich Workspace
             [[NCManageDatabase sharedInstance] setDirectoryWithOcId:metadataFolder.ocId serverUrl:self.serverUrl richWorkspace:metadataFolder.richWorkspace account:account];
-            self.richWorkspace = metadataFolder.richWorkspace;
+            self.richWorkspaceText = metadataFolder.richWorkspace;
             [self setTableViewHeader];
             
             tableDirectory *directory = [[NCManageDatabase sharedInstance] getTableDirectoryWithPredicate:[NSPredicate predicateWithFormat:@"account == %@ AND serverUrl == %@", account, metadataFolder.serverUrl]];
@@ -1944,7 +1947,7 @@
         
         UINavigationController *navigationController = [[UIStoryboard storyboardWithName:@"NCViewerRichWorkspace" bundle:nil] instantiateInitialViewController];
         NCViewerRichWorkspace *viewerRichWorkspace = (NCViewerRichWorkspace *)[navigationController topViewController];
-        viewerRichWorkspace.richWorkspace = self.richWorkspace;
+        viewerRichWorkspace.richWorkspaceText = self.richWorkspaceText;
         viewerRichWorkspace.serverUrl = self.serverUrl;
         
         navigationController.modalPresentationStyle = UIModalPresentationFullScreen;
@@ -2309,7 +2312,7 @@
                                  
     // REMENU --------------------------------------------------------------------------------------------------------------
 
-    if (capabilities.versionMajor >= k_nextcloud_version_18_0 && self.richWorkspace.length == 0) {
+    if (capabilities.versionMajor >= k_nextcloud_version_18_0 && self.richWorkspaceText.length == 0) {
         appDelegate.reMainMenu = [[REMenu alloc] initWithItems:@[appDelegate.selezionaItem, appDelegate.sortFileNameAZItem, appDelegate.sortFileNameZAItem, appDelegate.sortDateMoreRecentItem, appDelegate.sortDateLessRecentItem, appDelegate.sortSmallestItem, appDelegate.sortLargestItem, appDelegate.directoryOnTopItem, appDelegate.addFolderInfo]];
     } else {
         appDelegate.reMainMenu = [[REMenu alloc] initWithItems:@[appDelegate.selezionaItem, appDelegate.sortFileNameAZItem, appDelegate.sortFileNameZAItem, appDelegate.sortDateMoreRecentItem, appDelegate.sortDateLessRecentItem, appDelegate.sortSmallestItem, appDelegate.sortLargestItem, appDelegate.directoryOnTopItem]];
@@ -3871,19 +3874,17 @@
 - (void)setTableViewHeader
 {
     tableCapabilities *capabilities = [[NCManageDatabase sharedInstance] getCapabilitesWithAccount:appDelegate.activeAccount];
-    NCRichWorkspaceCommon *richWorkspaceCommon = [NCRichWorkspaceCommon new];
   
-    if (capabilities.versionMajor < k_nextcloud_version_18_0 || self.richWorkspace.length == 0 || self.searchController.isActive) {
+    if (capabilities.versionMajor < k_nextcloud_version_18_0 || self.richWorkspaceText.length == 0 || self.searchController.isActive) {
                 
-        [richWorkspaceCommon setRichWorkspaceText:@"" userInteractionEnabled:false textView:self.viewRichWorkspace.textView];
         [self.tableView.tableHeaderView setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, heightSearchBar)];
         
     } else {
         
-        [richWorkspaceCommon setRichWorkspaceText:self.richWorkspace userInteractionEnabled:false textView:self.viewRichWorkspace.textView];
         [self.viewRichWorkspace setFrame:CGRectMake(self.tableView.tableHeaderView.frame.origin.x, self.tableView.tableHeaderView.frame.origin.y, self.tableView.frame.size.width, heightRichWorkspace)];
     }
     
+    [self.viewRichWorkspace loadWithRichWorkspaceText:self.richWorkspaceText];
     self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.tableView.frame.size.width, heightSearchBar);
     [self.tableView reloadData];
 }

+ 22 - 71
iOSClient/RichWorkspace/NCRichWorkspace.swift

@@ -32,79 +32,30 @@ import SwiftRichString
 
     let gradientLayer: CAGradientLayer = CAGradientLayer()
 
-    /*
-    @objc func setRichWorkspaceText(_ richWorkspace: String, gradient: Bool, userInteractionEnabled: Bool) {
+    required init?(coder: NSCoder) {
+        super.init(coder: coder)
         
-        let h1 = Style {
-            $0.font = UIFont.systemFont(ofSize: 25, weight: .bold)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-        let h2 = Style {
-            $0.font = UIFont.systemFont(ofSize: 23, weight: .bold)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-        let h3 = Style {
-            $0.font = UIFont.systemFont(ofSize: 21, weight: .bold)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-        let h4 = Style {
-            $0.font = UIFont.systemFont(ofSize: 19, weight: .bold)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-        let h5 = Style {
-            $0.font = UIFont.systemFont(ofSize: 17, weight: .bold)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-        let h6 = Style {
-            $0.font = UIFont.systemFont(ofSize: 15, weight: .bold)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-        let normal = Style {
-            $0.font = UIFont.systemFont(ofSize: 15)
-            $0.color = NCBrandColor.sharedInstance.textView
-        }
-       
-        var richWorkspaceStyling = ""
-        let richWorkspaceArray = richWorkspace.components(separatedBy: "\n")
-        for string in richWorkspaceArray {
-            if string.hasPrefix("# ") {
-                richWorkspaceStyling = richWorkspaceStyling + "<h1>" + string.replacingOccurrences(of: "# ", with: "") + "</h1>\r\n"
-            } else if string.hasPrefix("## ") {
-                richWorkspaceStyling = richWorkspaceStyling + "<h2>" + string.replacingOccurrences(of: "## ", with: "") + "</h2>\r\n"
-            } else if string.hasPrefix("### ") {
-                richWorkspaceStyling = richWorkspaceStyling + "<h3>" + string.replacingOccurrences(of: "### ", with: "") + "</h3>\r\n"
-            } else if string.hasPrefix("#### ") {
-                richWorkspaceStyling = richWorkspaceStyling + "<h4>" + string.replacingOccurrences(of: "#### ", with: "") + "</h4>\r\n"
-            } else if string.hasPrefix("##### ") {
-                richWorkspaceStyling = richWorkspaceStyling + "<h5>" + string.replacingOccurrences(of: "##### ", with: "") + "</h5>\r\n"
-            } else if string.hasPrefix("###### ") {
-                richWorkspaceStyling = richWorkspaceStyling + "<h6>" + string.replacingOccurrences(of: "###### ", with: "") + "</h6>\r\n"
-            } else {
-                richWorkspaceStyling = richWorkspaceStyling + string + "\r\n"
-            }
-        }
-        
-        textView.attributedText = richWorkspaceStyling.set(style: StyleGroup(base: normal, ["h1": h1, "h2": h2, "h3": h3, "h4": h4, "h5": h5, "h6": h6]))
-        textView.isUserInteractionEnabled = userInteractionEnabled
-        textView.sizeToFit()
+        backgroundColor = NCBrandColor.sharedInstance.backgroundView;
+    }
+
+    @objc func load(richWorkspaceText: String) {
+        let richWorkspaceCommon = NCRichWorkspaceCommon()
         
-        if gradient {
-            
-            gradientLayer.removeFromSuperlayer()
-            gradientLayer.frame = CGRect(x: 0.0, y: 0.0, width: self.frame.width, height: self.frame.height)
-            if CCUtility.getDarkMode() {
-                gradientLayer.colors = [UIColor.init(white: 0, alpha: 0).cgColor, UIColor.black.cgColor]
-            } else {
-                gradientLayer.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]
-            }
-            gradientLayer.startPoint = CGPoint(x: 0, y: 0.50)
-            gradientLayer.endPoint = CGPoint(x: 0, y: 1)
-            textView.layer.addSublayer(gradientLayer)
-        }
+        richWorkspaceCommon.setRichWorkspaceText(richWorkspaceText, textView: textView)
+        setGradient()
+    }
+    
+    @objc func setGradient() {
         
-        self.richWorkspace = richWorkspace
-        self.gradient = gradient
-        self._userInteractionEnabled = userInteractionEnabled
+        gradientLayer.removeFromSuperlayer()
+        gradientLayer.frame = CGRect(x: 0.0, y: 0.0, width: self.frame.width, height: self.frame.height)
+        if CCUtility.getDarkMode() {
+            gradientLayer.colors = [UIColor.init(white: 0, alpha: 0).cgColor, UIColor.black.cgColor]
+        } else {
+            gradientLayer.colors = [UIColor.init(white: 1, alpha: 0).cgColor, UIColor.white.cgColor]
+        }
+        gradientLayer.startPoint = CGPoint(x: 0, y: 0.50)
+        gradientLayer.endPoint = CGPoint(x: 0, y: 1)
+        textView.layer.addSublayer(gradientLayer)
     }
-    */
 }

+ 1 - 1
iOSClient/RichWorkspace/NCRichWorkspace.xib

@@ -14,7 +14,7 @@
             <rect key="frame" x="0.0" y="0.0" width="320" height="480"/>
             <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
             <subviews>
-                <textView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="wri-16-tQY">
+                <textView clipsSubviews="YES" multipleTouchEnabled="YES" userInteractionEnabled="NO" contentMode="scaleToFill" editable="NO" textAlignment="natural" translatesAutoresizingMaskIntoConstraints="NO" id="wri-16-tQY">
                     <rect key="frame" x="15" y="50" width="295" height="425"/>
                     <color key="backgroundColor" white="0.0" alpha="0.0" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                     <color key="textColor" systemColor="labelColor" cocoaTouchSystemColor="darkTextColor"/>

+ 2 - 3
iOSClient/RichWorkspace/NCRichWorkspaceCommon.swift

@@ -109,7 +109,7 @@ import SwiftRichString
         }
     }
     
-    @objc func setRichWorkspaceText(_ richWorkspace: String, userInteractionEnabled: Bool, textView: UITextView) {
+    @objc func setRichWorkspaceText(_ richWorkspaceText: String, textView: UITextView) {
            
            let h1 = Style {
                $0.font = UIFont.systemFont(ofSize: 25, weight: .bold)
@@ -141,7 +141,7 @@ import SwiftRichString
            }
           
            var richWorkspaceStyling = ""
-           let richWorkspaceArray = richWorkspace.components(separatedBy: "\n")
+           let richWorkspaceArray = richWorkspaceText.components(separatedBy: "\n")
            for string in richWorkspaceArray {
                if string.hasPrefix("# ") {
                    richWorkspaceStyling = richWorkspaceStyling + "<h1>" + string.replacingOccurrences(of: "# ", with: "") + "</h1>\r\n"
@@ -161,6 +161,5 @@ import SwiftRichString
            }
            
            textView.attributedText = richWorkspaceStyling.set(style: StyleGroup(base: normal, ["h1": h1, "h2": h2, "h3": h3, "h4": h4, "h5": h5, "h6": h6]))
-           textView.isUserInteractionEnabled = userInteractionEnabled
        }
 }

+ 5 - 5
iOSClient/RichWorkspace/NCViewerRichWorkspace.swift

@@ -30,7 +30,7 @@ import NCCommunication
     
     private let appDelegate = UIApplication.shared.delegate as! AppDelegate
     private let richWorkspaceCommon = NCRichWorkspaceCommon()
-    @objc public var richWorkspace: String = ""
+    @objc public var richWorkspaceText: String = ""
     @objc public var serverUrl: String = ""
    
     override func viewDidLoad() {
@@ -44,7 +44,7 @@ import NCCommunication
         let editItem = UIBarButtonItem(image: UIImage(named: "actionSheetModify"), style: UIBarButtonItem.Style.plain, target: self, action: #selector(editItemAction(_:)))
         self.navigationItem.rightBarButtonItem = editItem
 
-        richWorkspaceCommon.setRichWorkspaceText(richWorkspace, userInteractionEnabled: true, textView: textView)
+        richWorkspaceCommon.setRichWorkspaceText(richWorkspaceText, textView: textView)
         
         NotificationCenter.default.addObserver(self, selector: #selector(self.changeTheming), name: NSNotification.Name(rawValue: "changeTheming"), object: nil)
         changeTheming()
@@ -60,9 +60,9 @@ import NCCommunication
                 var metadataFolder = tableMetadata()
                 _ = NCNetworking.sharedInstance.convertFiles(files!, urlString: self.appDelegate.activeUrl, serverUrl: self.serverUrl, user: self.appDelegate.activeUser, metadataFolder: &metadataFolder)
                 NCManageDatabase.sharedInstance.setDirectory(ocId: metadataFolder.ocId, serverUrl: metadataFolder.serverUrl, richWorkspace: metadataFolder.richWorkspace, account: account)
-                self.richWorkspace = metadataFolder.richWorkspace
-                self.appDelegate.activeMain.richWorkspace = self.richWorkspace
-                self.richWorkspaceCommon.setRichWorkspaceText(self.richWorkspace, userInteractionEnabled: true, textView: self.textView)
+                self.richWorkspaceText = metadataFolder.richWorkspace
+                self.appDelegate.activeMain.richWorkspaceText = self.richWorkspaceText
+                self.richWorkspaceCommon.setRichWorkspaceText(self.richWorkspaceText, textView: self.textView)
             }
         }
     }