Marino Faggiana 6 жил өмнө
parent
commit
932ee43933

+ 17 - 6
iOSClient/Activity/NCActivity.storyboard

@@ -30,11 +30,12 @@
                                             <autoresizingMask key="autoresizingMask"/>
                                             <subviews>
                                                 <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="xNG-sf-PnA">
-                                                    <rect key="frame" x="0.0" y="0.0" width="50" height="50"/>
+                                                    <rect key="frame" x="5" y="0.0" width="25" height="25"/>
                                                     <constraints>
-                                                        <constraint firstAttribute="width" constant="50" id="Lbv-yi-vAh"/>
-                                                        <constraint firstAttribute="height" constant="50" id="TML-VJ-2i3"/>
+                                                        <constraint firstAttribute="width" constant="25" id="Lbv-yi-vAh"/>
+                                                        <constraint firstAttribute="height" constant="25" id="TML-VJ-2i3"/>
                                                     </constraints>
+                                                    <directionalEdgeInsets key="directionalLayoutMargins" top="8" leading="8" bottom="8" trailing="8"/>
                                                 </imageView>
                                                 <collectionView clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="scaleToFill" dataMode="prototypes" translatesAutoresizingMaskIntoConstraints="NO" id="KpO-no-BMl">
                                                     <rect key="frame" x="0.0" y="50.000000000000007" width="375" height="69.666666666666686"/>
@@ -54,7 +55,7 @@
                                                                 <autoresizingMask key="autoresizingMask"/>
                                                                 <subviews>
                                                                     <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="J5b-2X-AsF">
-                                                                        <rect key="frame" x="0.0" y="37" width="50" height="50"/>
+                                                                        <rect key="frame" x="0.0" y="34.999999999999993" width="50" height="50"/>
                                                                         <autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
                                                                     </imageView>
                                                                 </subviews>
@@ -65,20 +66,30 @@
                                                         </collectionViewCell>
                                                     </cells>
                                                 </collectionView>
+                                                <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="wordWrap" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="fcO-YL-MuT">
+                                                    <rect key="frame" x="38" y="0.0" width="332" height="20.333333333333332"/>
+                                                    <fontDescription key="fontDescription" type="system" pointSize="17"/>
+                                                    <nil key="textColor"/>
+                                                    <nil key="highlightedColor"/>
+                                                </label>
                                             </subviews>
                                             <constraints>
-                                                <constraint firstItem="xNG-sf-PnA" firstAttribute="leading" secondItem="i35-U4-bEk" secondAttribute="leading" id="CRN-18-SeU"/>
+                                                <constraint firstAttribute="trailing" secondItem="fcO-YL-MuT" secondAttribute="trailing" constant="5" id="1pG-qk-inI"/>
+                                                <constraint firstItem="xNG-sf-PnA" firstAttribute="leading" secondItem="i35-U4-bEk" secondAttribute="leading" constant="5" id="CRN-18-SeU"/>
                                                 <constraint firstItem="KpO-no-BMl" firstAttribute="top" secondItem="i35-U4-bEk" secondAttribute="top" constant="50" id="Geo-dG-qcV"/>
+                                                <constraint firstItem="fcO-YL-MuT" firstAttribute="leading" secondItem="xNG-sf-PnA" secondAttribute="trailing" constant="8" id="Q2v-si-0w5"/>
                                                 <constraint firstAttribute="bottom" secondItem="KpO-no-BMl" secondAttribute="bottom" id="ULe-Tt-dBj"/>
+                                                <constraint firstItem="fcO-YL-MuT" firstAttribute="top" secondItem="i35-U4-bEk" secondAttribute="top" id="faC-by-km5"/>
                                                 <constraint firstItem="KpO-no-BMl" firstAttribute="leading" secondItem="i35-U4-bEk" secondAttribute="leading" id="l0Y-89-eTm"/>
                                                 <constraint firstAttribute="trailing" secondItem="KpO-no-BMl" secondAttribute="trailing" id="vWj-9H-JLc"/>
                                                 <constraint firstItem="xNG-sf-PnA" firstAttribute="top" secondItem="i35-U4-bEk" secondAttribute="top" id="zo1-7W-YZr"/>
                                             </constraints>
                                         </tableViewCellContentView>
-                                        <color key="backgroundColor" red="1" green="0.5" blue="0.0" alpha="1" colorSpace="custom" customColorSpace="sRGB"/>
+                                        <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
                                         <connections>
                                             <outlet property="collectionView" destination="KpO-no-BMl" id="xvR-CA-cZx"/>
                                             <outlet property="icon" destination="xNG-sf-PnA" id="hxb-Vr-oQX"/>
+                                            <outlet property="subject" destination="fcO-YL-MuT" id="L4q-rj-l04"/>
                                         </connections>
                                     </tableViewCell>
                                 </prototypes>

+ 65 - 4
iOSClient/Activity/NCActivity.swift

@@ -88,12 +88,45 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
         tableView.reloadData()
     }
     
+    // MARK: TableView
+
     func numberOfSections(in tableView: UITableView) -> Int {
         return sectionDate.count
     }
-        
+    
     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
-        return datasource.count
+        let startDate = sectionDate[section]
+        let endDate: Date = {
+            let components = DateComponents(day: 1, second: -1)
+            return Calendar.current.date(byAdding: components, to: startDate)!
+        }()
+        
+        let results = NCManageDatabase.sharedInstance.getActivity(predicate: NSPredicate(format: "account == %@ && date BETWEEN %@", appDelegate.activeAccount, [startDate, endDate]))
+        return results.count
+    }
+    
+    func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
+        return 30
+    }
+    
+    func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
+        
+        let view = UIView(frame: CGRect(x: 0, y: 0, width: tableView.bounds.width, height: 30))
+        view.backgroundColor = UIColor.white
+        let label = UILabel(frame: CGRect(x: 5, y: 0, width: tableView.bounds.width - 30, height: 30))
+        label.font = UIFont.boldSystemFont(ofSize: 18)
+        label.textColor = UIColor.black
+        label.text = CCUtility.getTitleSectionDate(sectionDate[section])
+        view.addSubview(label)
+        return view
+    }
+    
+    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
+        return 100
+    }
+    
+    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
+        return UITableView.automaticDimension
     }
     
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
@@ -112,6 +145,19 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
                     }
                 }
             }
+            if tableActivity.subjectRich.count > 0 {
+                
+                var subject = tableActivity.subjectRich
+                
+                let keys = subject.keyTags()
+                for key in keys {
+                    if let result = NCManageDatabase.sharedInstance.getActivitySubjectRich(account: appDelegate.activeAccount, idActivity: tableActivity.idActivity, key: key) {
+                        subject = subject.replacingOccurrences(of: "{\(key)}", with: result.name)
+                    }
+                }
+                
+                cell.subject.text = subject
+            }
             
             return cell
         }
@@ -120,12 +166,12 @@ class NCActivity: UIViewController, UITableViewDataSource, UITableViewDelegate,
     }
 }
 
-
 class activityTableViewCell: UITableViewCell, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
     
     @IBOutlet weak var collectionView: UICollectionView!
     @IBOutlet weak var icon: UIImageView!
-    
+    @IBOutlet weak var subject: UILabel!
+
     var imageArray = [String] ()
     
     override func awakeFromNib() {
@@ -173,3 +219,18 @@ class activityCollectionViewCell: UICollectionViewCell {
     }
     
 }
+
+// MARK: Extension
+
+extension String
+{
+    func keyTags() -> [String] {
+        if let regex = try? NSRegularExpression(pattern: "\\{[a-z0-9]+\\}", options: .caseInsensitive) {
+            let string = self as NSString
+            return regex.matches(in: self, options: [], range: NSRange(location: 0, length: string.length)).map {
+                string.substring(with: $0.range).replacingOccurrences(of: "[\\{\\}]", with: "", options: .regularExpression)
+            }
+        }
+        return []
+    }
+}

+ 1 - 0
iOSClient/Database/NCDatabase.swift

@@ -74,6 +74,7 @@ class tableActivity: Object {
     let subjectRichItem = List<tableActivitySubjectRich>()
     @objc dynamic var icon = ""
     @objc dynamic var link = ""
+    @objc dynamic var message = ""
     @objc dynamic var objectType = ""
     @objc dynamic var objectID: Double = 0
     @objc dynamic var objectName = ""

+ 13 - 1
iOSClient/Database/NCManageDatabase.swift

@@ -64,7 +64,7 @@ class NCManageDatabase: NSObject {
         var config = Realm.Configuration(
         
             fileURL: dirGroup?.appendingPathComponent("\(k_appDatabaseNextcloud)/\(k_databaseDefault)"),
-            schemaVersion: 41,
+            schemaVersion: 42,
             
             // 10 : Version 2.18.0
             // 11 : Version 2.18.2
@@ -98,6 +98,7 @@ class NCManageDatabase: NSObject {
             // 39 : Version 2.22.9.1
             // 40 : Version 2.22.9.3
             // 41 : Version 2.22.9.4
+            // 42 : Version 2.22.9.5
 
             migrationBlock: { migration, oldSchemaVersion in
                 // We haven’t migrated anything yet, so oldSchemaVersion == 0
@@ -638,6 +639,7 @@ class NCManageDatabase: NSObject {
                     
                     addObjectActivity.icon = activity.icon
                     addObjectActivity.link = activity.link
+                    addObjectActivity.message = activity.message
                     addObjectActivity.objectType = activity.object_type
                     addObjectActivity.objectID = Double(activity.object_id)
                     addObjectActivity.objectName = activity.object_name
@@ -650,6 +652,16 @@ class NCManageDatabase: NSObject {
         }
     }
     
+    @objc func getActivitySubjectRich(account: String, idActivity: Double, key: String) -> tableActivitySubjectRich? {
+        
+        let realm = try! Realm()
+        realm.refresh()
+        
+        let results = realm.objects(tableActivitySubjectRich.self).filter("account = %@ && idActivity == %d && key = %@", account, idActivity, key).first
+        
+        return results.map { tableActivitySubjectRich.init(value:$0) }
+    }
+    
     @objc func addActivityClient(_ file: String, fileID: String, action: String, selector: String, note: String, type: String, verbose: Bool, activeUrl: String?) {
 
         /*