marinofaggiana 3 years ago
parent
commit
21e15b2ce2

+ 8 - 3
iOSClient/BackgroundImageColor/NCBackgroundImageColor.storyboard

@@ -71,15 +71,18 @@
                                 <subviews>
                                     <switch opaque="NO" contentMode="scaleToFill" horizontalHuggingPriority="750" verticalHuggingPriority="750" contentHorizontalAlignment="center" contentVerticalAlignment="center" on="YES" translatesAutoresizingMaskIntoConstraints="NO" id="qCH-0e-MgJ">
                                         <rect key="frame" x="246" y="5" width="51" height="31"/>
+                                        <connections>
+                                            <action selector="darkmodeAction:" destination="V0q-CP-xMJ" eventType="valueChanged" id="jpD-6b-nRS"/>
+                                        </connections>
                                     </switch>
-                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Label" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AH4-ei-W3C">
+                                    <label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Dark mode" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="AH4-ei-W3C">
                                         <rect key="frame" x="5" y="10" width="231" height="21"/>
                                         <fontDescription key="fontDescription" type="system" pointSize="17"/>
                                         <nil key="textColor"/>
                                         <nil key="highlightedColor"/>
                                     </label>
                                     <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="6Dy-77-TIC">
-                                        <rect key="frame" x="5" y="41" width="290" height="34"/>
+                                        <rect key="frame" x="5" y="51" width="290" height="34"/>
                                         <color key="backgroundColor" systemColor="systemGray2Color"/>
                                         <state key="normal" title="Button"/>
                                         <connections>
@@ -94,7 +97,7 @@
                                     <constraint firstItem="AH4-ei-W3C" firstAttribute="leading" secondItem="Dsj-Of-TI5" secondAttribute="leading" constant="5" id="Afp-ca-hx0"/>
                                     <constraint firstItem="6Dy-77-TIC" firstAttribute="leading" secondItem="Dsj-Of-TI5" secondAttribute="leading" constant="5" id="Bn8-Bi-qOg"/>
                                     <constraint firstAttribute="trailing" secondItem="qCH-0e-MgJ" secondAttribute="trailing" constant="5" id="QVc-0U-Mg8"/>
-                                    <constraint firstItem="6Dy-77-TIC" firstAttribute="top" secondItem="AH4-ei-W3C" secondAttribute="bottom" constant="10" id="YpO-lB-kfU"/>
+                                    <constraint firstItem="6Dy-77-TIC" firstAttribute="top" secondItem="AH4-ei-W3C" secondAttribute="bottom" constant="20" id="YpO-lB-kfU"/>
                                     <constraint firstAttribute="trailing" secondItem="6Dy-77-TIC" secondAttribute="trailing" constant="5" id="jId-wH-r5I"/>
                                     <constraint firstAttribute="height" constant="125" id="uSG-oG-ooi"/>
                                 </constraints>
@@ -132,6 +135,8 @@
                     <connections>
                         <outlet property="cancelButton" destination="W5y-aT-UlI" id="P9l-o1-miU"/>
                         <outlet property="chromaColorPickerView" destination="iU2-DL-ICv" id="iX8-Pq-EFB"/>
+                        <outlet property="darkmodeLabel" destination="AH4-ei-W3C" id="JvO-LN-BUu"/>
+                        <outlet property="darkmodeSwitch" destination="qCH-0e-MgJ" id="rjG-X5-eqA"/>
                         <outlet property="defaultButton" destination="6Dy-77-TIC" id="PxM-tG-Ve7"/>
                         <outlet property="okButton" destination="hcV-V0-eZB" id="1VQ-qp-4Fs"/>
                         <outlet property="titleLabel" destination="nZr-nE-ths" id="UbA-Dl-0Ad"/>

+ 28 - 7
iOSClient/BackgroundImageColor/NCBackgroundImageColor.swift

@@ -29,17 +29,22 @@ class NCBackgroundImageColor: UIViewController {
     @IBOutlet weak var titleLabel: UILabel!
     @IBOutlet weak var chromaColorPickerView: UIView!
     
-    @IBOutlet weak var defaultButton: UIButton!    
+    @IBOutlet weak var darkmodeLabel: UILabel!
+    @IBOutlet weak var darkmodeSwitch: UISwitch!
+
+    @IBOutlet weak var defaultButton: UIButton!
     @IBOutlet weak var cancelButton: UIButton!
     @IBOutlet weak var okButton: UIButton!
     
     private let colorPicker = ChromaColorPicker()
     private let brightnessSlider = ChromaBrightnessSlider()
     private var colorHandle: ChromaColorHandle?
+    private var isDarkMode: Bool = false
     
     private let defaultColorPickerSize = CGSize(width: 200, height: 200)
     private let brightnessSliderWidthHeightRatio: CGFloat = 0.1
-    private var colorHexString = ""
+    private var darkColorHexString = ""
+    private var lightColorHexString = ""
     
     public var collectionViewCommon: NCCollectionViewCommon?
     public var defaultColor: UIColor = NCBrandColor.shared.systemBackground
@@ -57,20 +62,35 @@ class NCBackgroundImageColor: UIViewController {
         setupColorPickerHandles()
         
         titleLabel.text = NSLocalizedString("_background_", comment: "")
+        darkmodeLabel.text = NSLocalizedString("_dark_mode_", comment: "")
         cancelButton.setTitle(NSLocalizedString("_cancel_", comment: ""), for: .normal)
         okButton.setTitle(NSLocalizedString("_ok_", comment: ""), for: .normal)        
     }
     
     override func viewWillAppear(_ animated: Bool) {
         super.viewWillAppear(animated)
+        
+        if traitCollection.userInterfaceStyle == .dark {
+            darkmodeSwitch.isOn = true
+        } else {
+            darkmodeSwitch.isOn = false
+        }
     }
     
     override func viewDidAppear(_ animated: Bool) {
         super.viewDidAppear(animated)
     }
     
+    override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
+        super.traitCollectionDidChange(previousTraitCollection)
+    }
+    
     // MARK: - Action
     
+    @IBAction func darkmodeAction(_ sender: UISwitch) {
+        isDarkMode = sender.isOn
+    }
+    
     @IBAction func defaultAction(_ sender: Any) {
         
         colorHandle?.color = defaultColor
@@ -86,10 +106,6 @@ class NCBackgroundImageColor: UIViewController {
     
     @IBAction func okAction(_ sender: Any) {
         
-        if traitCollection.userInterfaceStyle == .dark {
-            
-        }
-        
         if let collectionViewCommon = collectionViewCommon {
             if colorHandle?.color == defaultColor {
                 NCUtility.shared.setBackgroundColorForView(key: collectionViewCommon.layoutKey, serverUrl: collectionViewCommon.serverUrl, colorBackground: "", colorDarkBackground: "")
@@ -144,7 +160,12 @@ class NCBackgroundImageColor: UIViewController {
 extension NCBackgroundImageColor: ChromaColorPickerDelegate {
     func colorPickerHandleDidChange(_ colorPicker: ChromaColorPicker, handle: ChromaColorHandle, to color: UIColor) {
         
-        colorHexString = color.hexString
+        if darkmodeSwitch.isOn {
+            darkColorHexString = color.hexString
+        } else {
+            lightColorHexString = color.hexString
+        }
+        
         collectionViewCommon?.collectionView.backgroundColor = color
     }
 }

+ 1 - 0
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -175,6 +175,7 @@
 "_account_select_"          = "Select the account";
 "_use_as_background_"       = "Use it as a background";
 "_background_"              = "Background";
+"_dark_mode_"               = "Dark mode";
 
 /* User status */
 "_online_"                  = "Online";