Browse Source

coding

Signed-off-by: marinofaggiana <ios@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
247d4ed1d7

+ 2 - 3
iOSClient/Color/NCColorPicker.storyboard

@@ -204,14 +204,13 @@
                             </button>
                             <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="iB2-gu-3IO">
                                 <rect key="frame" x="145" y="210" width="40" height="40"/>
-                                <color key="backgroundColor" systemColor="labelColor"/>
                                 <constraints>
                                     <constraint firstAttribute="width" constant="40" id="62A-PY-UZr"/>
                                     <constraint firstAttribute="height" constant="40" id="P8F-Uh-nef"/>
                                 </constraints>
                                 <inset key="imageEdgeInsets" minX="0.0" minY="0.0" maxX="2.2250738585072014e-308" maxY="0.0"/>
                                 <connections>
-                                    <action selector="systemTealButtonAction:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="2ye-Wz-wur"/>
+                                    <action selector="customButtonAction:" destination="Y6W-OH-hqX" eventType="touchUpInside" id="sST-c5-Zap"/>
                                 </connections>
                             </button>
                         </subviews>
@@ -260,6 +259,7 @@
                         <outlet property="blueButton" destination="C2a-jB-FVB" id="lIY-Ag-Nkv"/>
                         <outlet property="brownButton" destination="I9w-cx-QlY" id="b8T-np-0mw"/>
                         <outlet property="closeButton" destination="kwJ-4R-6nM" id="woU-Kz-IXU"/>
+                        <outlet property="customButton" destination="iB2-gu-3IO" id="Vtm-VH-D0l"/>
                         <outlet property="cyanButton" destination="OlH-Ak-sRA" id="26d-bc-OiU"/>
                         <outlet property="defaultButton" destination="Uaq-hC-U4a" id="t6X-aV-hPF"/>
                         <outlet property="grayButton" destination="LwF-26-oss" id="lzV-jY-LNd"/>
@@ -271,7 +271,6 @@
                         <outlet property="systemIndigoButton" destination="tt7-sI-TfL" id="tUi-Th-IDf"/>
                         <outlet property="systemMintButton" destination="Arw-up-GyD" id="gqG-tN-WiJ"/>
                         <outlet property="systemPinkButton" destination="I7I-Ed-32n" id="YzP-1f-nkJ"/>
-                        <outlet property="systemTealButton" destination="iB2-gu-3IO" id="S2F-rL-O44"/>
                         <outlet property="titleLabel" destination="8DH-gC-coa" id="k2U-jx-f6R"/>
                         <outlet property="yellowButton" destination="FU6-q8-9Iw" id="oAa-NT-Qhd"/>
                     </connections>

+ 43 - 6
iOSClient/Color/NCColorPicker.swift

@@ -27,13 +27,14 @@ class NCColorPicker: UIViewController {
     @IBOutlet weak var systemIndigoButton: UIButton!
     @IBOutlet weak var systemMintButton: UIButton!
     @IBOutlet weak var systemPinkButton: UIButton!
-    @IBOutlet weak var systemTealButton: UIButton!
     @IBOutlet weak var systemBlueButton: UIButton!
 
+    @IBOutlet weak var customButton: UIButton!
     @IBOutlet weak var defaultButton: UIButton!
 
     var metadata: tableMetadata?
     var tapAction: UITapGestureRecognizer?
+    var selectedColor: UIColor?
 
     // MARK: - View Life Cycle
 
@@ -42,6 +43,13 @@ class NCColorPicker: UIViewController {
 
         view.backgroundColor = NCBrandColor.shared.secondarySystemBackground
 
+        if let metadata = metadata {
+            let serverUrl = metadata.serverUrl + "/" + metadata.fileName
+            if let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, serverUrl)), let hex = tableDirectory.colorFolder, let color = UIColor(hex: hex) {
+                selectedColor = color
+            }
+        }
+
         closeButton.setImage(NCUtility.shared.loadImage(named: "xmark", color: NCBrandColor.shared.label), for: .normal)
         titleLabel.text = NSLocalizedString("_select_color_", comment: "")
 
@@ -93,9 +101,18 @@ class NCColorPicker: UIViewController {
         systemPinkButton.layer.cornerRadius = 5
         systemPinkButton.layer.masksToBounds = true
 
-        systemTealButton.backgroundColor = NCBrandColor.shared.systemTeal
-        systemTealButton.layer.cornerRadius = 5
-        systemTealButton.layer.masksToBounds = true
+        if #available(iOS 14.0, *) {
+            customButton.setImage(UIImage(named: "rgb"), for: .normal)
+            if let selectedColor = selectedColor {
+                customButton.backgroundColor = selectedColor
+            } else {
+                customButton.backgroundColor = NCBrandColor.shared.systemBackground
+            }
+        } else {
+            customButton.backgroundColor = NCBrandColor.shared.systemTeal
+        }
+        customButton.layer.cornerRadius = 5
+        customButton.layer.masksToBounds = true
 
         systemIndigoButton.backgroundColor = NCBrandColor.shared.systemIndigo
         systemIndigoButton.layer.cornerRadius = 5
@@ -160,8 +177,19 @@ class NCColorPicker: UIViewController {
         updateColor(hexColor: NCBrandColor.shared.systemPink.hexString)
     }
 
-    @IBAction func systemTealButtonAction(_ sender: AnyObject) {
-        updateColor(hexColor: NCBrandColor.shared.systemTeal.hexString)
+    @IBAction func customButtonAction(_ sender: AnyObject) {
+
+        if #available(iOS 14.0, *) {
+            let picker = UIColorPickerViewController()
+            picker.delegate = self
+            picker.supportsAlpha = false
+            if let selectedColor = selectedColor {
+                picker.selectedColor = selectedColor
+            }
+            self.present(picker, animated: true, completion: nil)
+        } else {
+            updateColor(hexColor: NCBrandColor.shared.systemTeal.hexString)
+        }
     }
 
     @IBAction func systemBlueButtonAction(_ sender: AnyObject) {
@@ -183,3 +211,12 @@ class NCColorPicker: UIViewController {
         self.dismiss(animated: true)
     }
 }
+
+@available(iOS 14.0, *)
+extension NCColorPicker: UIColorPickerViewControllerDelegate {
+
+    func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
+        let hexColor = viewController.selectedColor.hexString
+        updateColor(hexColor: hexColor)
+    }
+}

+ 12 - 0
iOSClient/Images.xcassets/rgb.imageset/Contents.json

@@ -0,0 +1,12 @@
+{
+  "images" : [
+    {
+      "filename" : "rgb.svg",
+      "idiom" : "universal"
+    }
+  ],
+  "info" : {
+    "author" : "xcode",
+    "version" : 1
+  }
+}

File diff suppressed because it is too large
+ 0 - 0
iOSClient/Images.xcassets/rgb.imageset/rgb.svg


Some files were not shown because too many files changed in this diff