Browse Source

user status

marinofaggiana 3 years ago
parent
commit
7fa61f00a8

+ 1 - 1
Nextcloud.xcodeproj/project.pbxproj

@@ -2897,7 +2897,7 @@
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
 				kind = revision;
-				revision = e28ad7040cab1a51158ab38d7f97473fe263923e;
+				revision = 7b48d164b1a403833de1ba5c8d1c5e6738e2befb;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

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

@@ -105,7 +105,7 @@
         "repositoryURL": "https://github.com/nextcloud/ios-communication-library/",
         "state": {
           "branch": null,
-          "revision": "e28ad7040cab1a51158ab38d7f97473fe263923e",
+          "revision": "7b48d164b1a403833de1ba5c8d1c5e6738e2befb",
           "version": null
         }
       },

+ 5 - 5
iOSClient/UserStatus/NCUserStatus.storyboard

@@ -227,7 +227,7 @@
                                 <textInputTraits key="textInputTraits"/>
                             </textField>
                             <tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" translatesAutoresizingMaskIntoConstraints="NO" id="P09-kU-gUI">
-                                <rect key="frame" x="10" y="373" width="355" height="305"/>
+                                <rect key="frame" x="10" y="373" width="355" height="288"/>
                                 <color key="backgroundColor" systemColor="systemBackgroundColor"/>
                                 <prototypes>
                                     <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="Cell" rowHeight="45" id="laP-fj-qDh">
@@ -269,7 +269,7 @@
                                 </connections>
                             </tableView>
                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="clear status message after" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="rha-b0-jMR">
-                                <rect key="frame" x="10" y="701" width="175" height="17"/>
+                                <rect key="frame" x="10" y="691" width="175" height="17"/>
                                 <constraints>
                                     <constraint firstAttribute="width" constant="175" id="YE8-7b-aAT"/>
                                 </constraints>
@@ -278,7 +278,7 @@
                                 <nil key="highlightedColor"/>
                             </label>
                             <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="today" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="isA-Km-19L">
-                                <rect key="frame" x="190" y="694.66666666666663" width="175" height="30"/>
+                                <rect key="frame" x="190" y="684.66666666666663" width="175" height="30"/>
                                 <constraints>
                                     <constraint firstAttribute="height" constant="30" id="c5F-cg-TMn"/>
                                 </constraints>
@@ -325,7 +325,7 @@
                             <constraint firstItem="P09-kU-gUI" firstAttribute="top" secondItem="qXf-nl-3Li" secondAttribute="bottom" constant="20" id="HtI-LZ-wPJ"/>
                             <constraint firstItem="ldK-hD-vsJ" firstAttribute="top" secondItem="Hed-Bz-0g1" secondAttribute="bottom" constant="40" id="K8i-hZ-ic0"/>
                             <constraint firstItem="isA-Km-19L" firstAttribute="centerY" secondItem="rha-b0-jMR" secondAttribute="centerY" id="KLC-hn-HTt"/>
-                            <constraint firstItem="3CT-dJ-sEj" firstAttribute="top" secondItem="rha-b0-jMR" secondAttribute="bottom" constant="20" id="KlN-Ud-r2X"/>
+                            <constraint firstItem="3CT-dJ-sEj" firstAttribute="top" secondItem="rha-b0-jMR" secondAttribute="bottom" constant="30" id="KlN-Ud-r2X"/>
                             <constraint firstItem="Hed-Bz-0g1" firstAttribute="top" secondItem="ukn-PZ-9sx" secondAttribute="bottom" constant="30" id="LJ2-Qn-qbJ"/>
                             <constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="qXf-nl-3Li" secondAttribute="trailing" constant="10" id="MLs-tH-cbf"/>
                             <constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="P09-kU-gUI" secondAttribute="trailing" constant="10" id="Qm6-Nb-VLH"/>
@@ -341,7 +341,7 @@
                             <constraint firstItem="qXf-nl-3Li" firstAttribute="top" secondItem="ldK-hD-vsJ" secondAttribute="bottom" constant="20" id="jPk-b5-RCo"/>
                             <constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="3xN-e7-N0L" secondAttribute="trailing" constant="10" id="n76-Wo-n2b"/>
                             <constraint firstItem="vDu-zF-Fre" firstAttribute="bottom" secondItem="3xN-e7-N0L" secondAttribute="bottom" constant="10" id="r6F-XX-ATR"/>
-                            <constraint firstItem="rha-b0-jMR" firstAttribute="top" secondItem="P09-kU-gUI" secondAttribute="bottom" constant="23" id="rJR-kN-VR7"/>
+                            <constraint firstItem="rha-b0-jMR" firstAttribute="top" secondItem="P09-kU-gUI" secondAttribute="bottom" constant="30" id="rJR-kN-VR7"/>
                             <constraint firstItem="ukn-PZ-9sx" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="20" id="vBm-Uq-cEs"/>
                             <constraint firstItem="vDu-zF-Fre" firstAttribute="trailing" secondItem="ldK-hD-vsJ" secondAttribute="trailing" constant="5" id="yZf-48-jHR"/>
                         </constraints>

+ 35 - 51
iOSClient/UserStatus/NCUserStatus.swift

@@ -67,15 +67,6 @@ class NCUserStatus: UIViewController {
     
     private var statusPredefinedStatuses: [NCCommunicationUserStatus] = []
     
-    private var clearAt: NSDate?
-    private var icon: String?
-    private var message: String?
-    private var messageId: String?
-    private var messageIsPredefined: Bool?
-    private var status: String?
-    private var statusIsUserDefined: Bool?
-    private var userId: String?
-    
     private var clearAtTimestamp: Double = 0     // Unix Timestamp representing the time to clear the status
     
     private let borderWidthButton: CGFloat = 1.5
@@ -309,35 +300,7 @@ class NCUserStatus: UIViewController {
         
         dropDown.selectionAction = { (index, item) in
             
-            let now = Date()
-            let calendar = Calendar.current
-            let gregorian = Calendar(identifier: .gregorian)
-            let midnight = calendar.startOfDay(for: now)
-            
-            guard let tomorrow = calendar.date(byAdding: .day, value: 1, to: midnight) else { return }
-            guard let startweek = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: now)) else { return }
-            guard let endweek = gregorian.date(byAdding: .day, value: 6, to: startweek) else { return }
-            
-            switch item {
-            case NSLocalizedString("_dont_clear_", comment: ""):
-                self.clearAtTimestamp = 0
-            case NSLocalizedString("_30_minutes_", comment: ""):
-                let date = now.addingTimeInterval(1800)
-                self.clearAtTimestamp = date.timeIntervalSince1970
-            case NSLocalizedString("_1_hour_", comment: ""):
-                let date = now.addingTimeInterval(3600)
-                self.clearAtTimestamp = date.timeIntervalSince1970
-            case NSLocalizedString("_4_hours_", comment: ""):
-                let date = now.addingTimeInterval(14400)
-                self.clearAtTimestamp = date.timeIntervalSince1970
-            case NSLocalizedString("day", comment: ""):
-                self.clearAtTimestamp = tomorrow.timeIntervalSince1970
-            case NSLocalizedString("_this_week_", comment: ""):
-                self.clearAtTimestamp = endweek.timeIntervalSince1970
-            default:
-                self.clearAtTimestamp = 0
-            }
-            
+            self.clearAtTimestamp = self.getClearAt(item)
             self.clearStatusMessageAfterText.text = " " + item
         }
         
@@ -384,15 +347,6 @@ class NCUserStatus: UIViewController {
             
             if errorCode == 0 {
                 
-                self.clearAt = clearAt
-                self.icon = icon
-                self.message = message
-                self.messageId = messageId
-                self.messageIsPredefined = messageIsPredefined
-                self.status = status
-                self.statusIsUserDefined = statusIsUserDefined
-                self.userId = userId
-                
                 if icon != nil {
                     self.statusMessageEmojiTextField.text = icon
                 }
@@ -444,9 +398,36 @@ class NCUserStatus: UIViewController {
     
     // MARK: - Algorithms
 
-    func getSecondxxx(clearAtString: String) -> Int {
-        
-        return 0
+    func getClearAt(_ clearAtString: String) -> Double {
+        
+        let now = Date()
+        let calendar = Calendar.current
+        let gregorian = Calendar(identifier: .gregorian)
+        let midnight = calendar.startOfDay(for: now)
+        
+        guard let tomorrow = calendar.date(byAdding: .day, value: 1, to: midnight) else { return 0 }
+        guard let startweek = gregorian.date(from: gregorian.dateComponents([.yearForWeekOfYear, .weekOfYear], from: now)) else { return 0 }
+        guard let endweek = gregorian.date(byAdding: .day, value: 6, to: startweek) else { return 0 }
+        
+        switch clearAtString {
+        case NSLocalizedString("_dont_clear_", comment: ""):
+            return 0
+        case NSLocalizedString("_30_minutes_", comment: ""):
+            let date = now.addingTimeInterval(1800)
+            return date.timeIntervalSince1970
+        case NSLocalizedString("_1_hour_", comment: ""), NSLocalizedString("_an_hour_", comment: ""):
+            let date = now.addingTimeInterval(3600)
+            return date.timeIntervalSince1970
+        case NSLocalizedString("_4_hours_", comment: ""):
+            let date = now.addingTimeInterval(14400)
+            return date.timeIntervalSince1970
+        case NSLocalizedString("day", comment: ""):
+            return tomorrow.timeIntervalSince1970
+        case NSLocalizedString("_this_week_", comment: ""):
+            return endweek.timeIntervalSince1970
+        default:
+            return 0
+        }
     }
     
     func getPredefinedClearStatusText(clearAt: NSDate?, clearAtTime: String?, clearAtType: String?) -> String {
@@ -589,9 +570,12 @@ extension NCUserStatus: UITableViewDelegate {
                 
                 if errorCode == 0 {
                     
+                    let clearAtTimestampString = self.getPredefinedClearStatusText(clearAt: status.clearAt, clearAtTime: status.clearAtTime, clearAtType: status.clearAtType)
+                    
                     self.statusMessageEmojiTextField.text = status.icon
                     self.statusMessageTextField.text = status.message
-                    self.clearStatusMessageAfterText.text = " " + self.getPredefinedClearStatusText(clearAt: status.clearAt, clearAtTime: status.clearAtTime, clearAtType: status.clearAtType)
+                    self.clearStatusMessageAfterText.text = " " + clearAtTimestampString
+                    self.clearAtTimestamp = self.getClearAt(clearAtTimestampString)
                 }
                 
                 self.dismissIfError(errorCode, errorDescription: errorDescription)