Browse Source

coding

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

+ 8 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -144,6 +144,8 @@
 		F717402D24F699A5000C87D5 /* NCFavorite.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F717402B24F699A5000C87D5 /* NCFavorite.storyboard */; };
 		F717402E24F699A5000C87D5 /* NCFavorite.swift in Sources */ = {isa = PBXBuildFile; fileRef = F717402C24F699A5000C87D5 /* NCFavorite.swift */; };
 		F718C24E254D507B00C5C256 /* NCViewerMediaDetailView.swift in Sources */ = {isa = PBXBuildFile; fileRef = F718C24D254D507B00C5C256 /* NCViewerMediaDetailView.swift */; };
+		F719D9E0288D37A300762E33 /* NCColorPicker.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F719D9DF288D37A300762E33 /* NCColorPicker.storyboard */; };
+		F719D9E2288D396100762E33 /* NCColorPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = F719D9E1288D396100762E33 /* NCColorPicker.swift */; };
 		F7226EDC1EE4089300EBECB1 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F7226EDB1EE4089300EBECB1 /* Main.storyboard */; };
 		F7233B3A27835FA400F40A43 /* ChromaColorPicker in Frameworks */ = {isa = PBXBuildFile; productRef = F7233B3927835FA400F40A43 /* ChromaColorPicker */; };
 		F723985C253C95CE00257F49 /* NCViewerRichdocument.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = F723985B253C95CE00257F49 /* NCViewerRichdocument.storyboard */; };
@@ -637,6 +639,8 @@
 		F7176DB9256672640017E83C /* FIRAnalyticsConnector.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = FIRAnalyticsConnector.framework; path = Carthage/Build/iOS/FIRAnalyticsConnector.framework; sourceTree = "<group>"; };
 		F7176DDA256672D90017E83C /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
 		F718C24D254D507B00C5C256 /* NCViewerMediaDetailView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewerMediaDetailView.swift; sourceTree = "<group>"; };
+		F719D9DF288D37A300762E33 /* NCColorPicker.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCColorPicker.storyboard; sourceTree = "<group>"; };
+		F719D9E1288D396100762E33 /* NCColorPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCColorPicker.swift; sourceTree = "<group>"; };
 		F7226EDB1EE4089300EBECB1 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = "<group>"; };
 		F723985B253C95CE00257F49 /* NCViewerRichdocument.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = NCViewerRichdocument.storyboard; sourceTree = "<group>"; };
 		F7239870253D86B600257F49 /* NCEmptyDataSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEmptyDataSet.swift; sourceTree = "<group>"; };
@@ -1136,6 +1140,8 @@
 			children = (
 				F70B866B2642A21300ED5349 /* NCBackgroundImageColor.storyboard */,
 				F70B866C2642A21300ED5349 /* NCBackgroundImageColor.swift */,
+				F719D9DF288D37A300762E33 /* NCColorPicker.storyboard */,
+				F719D9E1288D396100762E33 /* NCColorPicker.swift */,
 			);
 			path = Color;
 			sourceTree = "<group>";
@@ -2314,6 +2320,7 @@
 				F749C10D23C4A5340027D966 /* NCIntro.storyboard in Resources */,
 				F7239877253D86D300257F49 /* NCEmptyView.xib in Resources */,
 				F747BA1F22354D2000971601 /* NCCreateFormUploadVoiceNote.storyboard in Resources */,
+				F719D9E0288D37A300762E33 /* NCColorPicker.storyboard in Resources */,
 				F7651A8A23A2A3F2001403D2 /* NCCreateFormUploadDocuments.storyboard in Resources */,
 				F7F4F10A27ECDBDB008676F9 /* Inconsolata-ExtraBold.ttf in Resources */,
 				F704B5E72430C06700632F5F /* NCCreateFormUploadConflictCell.xib in Resources */,
@@ -2614,6 +2621,7 @@
 				AFCE353527E4ED5900FEA6C2 /* DateFormatter+Extension.swift in Sources */,
 				F718C24E254D507B00C5C256 /* NCViewerMediaDetailView.swift in Sources */,
 				F7381EE1218218C9000B1560 /* NCOffline.swift in Sources */,
+				F719D9E2288D396100762E33 /* NCColorPicker.swift in Sources */,
 				F78071091EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */,
 				F79B646026CA661600838ACA /* UIControl+Extensions.swift in Sources */,
 				F7CA212D25F1333300826ABB /* NCAccountRequest.swift in Sources */,

+ 51 - 0
iOSClient/Color/NCColorPicker.storyboard

@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
+    <device id="retina4_0" orientation="portrait" appearance="light"/>
+    <dependencies>
+        <deployment identifier="iOS"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
+        <capability name="Safe area layout guides" minToolsVersion="9.0"/>
+        <capability name="System colors in document resources" minToolsVersion="11.0"/>
+        <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
+    </dependencies>
+    <scenes>
+        <!--Color Picker-->
+        <scene sceneID="s0d-6b-0kx">
+            <objects>
+                <viewController id="Y6W-OH-hqX" customClass="NCColorPicker" customModule="Nextcloud" customModuleProvider="target" sceneMemberID="viewController">
+                    <view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
+                        <rect key="frame" x="0.0" y="0.0" width="320" height="568"/>
+                        <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
+                        <subviews>
+                            <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="Zr2-rF-YUt">
+                                <rect key="frame" x="10" y="10" width="40" height="40"/>
+                                <constraints>
+                                    <constraint firstAttribute="height" constant="40" id="krX-Ql-hLX"/>
+                                    <constraint firstAttribute="width" constant="40" id="pBq-i1-K9T"/>
+                                </constraints>
+                                <state key="normal" title="Button"/>
+                                <buttonConfiguration key="configuration" style="plain"/>
+                            </button>
+                        </subviews>
+                        <viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
+                        <color key="backgroundColor" systemColor="systemBackgroundColor"/>
+                        <constraints>
+                            <constraint firstItem="Zr2-rF-YUt" firstAttribute="top" secondItem="vDu-zF-Fre" secondAttribute="top" constant="10" id="adH-I3-HO4"/>
+                            <constraint firstItem="Zr2-rF-YUt" firstAttribute="leading" secondItem="vDu-zF-Fre" secondAttribute="leading" constant="10" id="zBA-2T-5J8"/>
+                        </constraints>
+                    </view>
+                    <connections>
+                        <outlet property="redButton" destination="Zr2-rF-YUt" id="jib-wX-2Of"/>
+                    </connections>
+                </viewController>
+                <placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
+            </objects>
+            <point key="canvasLocation" x="0.0" y="51"/>
+        </scene>
+    </scenes>
+    <resources>
+        <systemColor name="systemBackgroundColor">
+            <color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
+        </systemColor>
+    </resources>
+</document>

+ 45 - 0
iOSClient/Color/NCColorPicker.swift

@@ -0,0 +1,45 @@
+//
+//  NCColorPicker.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 24/07/22.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
+//
+
+import Foundation
+import UIKit
+
+public protocol NCColorPickerDelegate: AnyObject {
+    func colorPickerCancel()
+    func colorPickerWillChange(color: UIColor)
+    func colorPickerDidChange(color: UIColor)
+}
+
+// optional func
+public extension NCColorPickerDelegate {
+    func colorPickerCancel() {}
+    func colorPickerWillChange(color: UIColor) { }
+    func colorPickerDidChange(color: UIColor) { }
+}
+
+class NCColorPicker: UIViewController, NCColorPickerDelegate {
+
+    @IBOutlet weak var redButton: UIButton!
+
+    weak var delegate: NCColorPickerDelegate?
+    var selectedColor: UIColor?
+    var defaultColor: UIColor?
+
+    // MARK: - View Life Cycle
+
+    override func viewDidLoad() {
+        super.viewDidLoad()
+
+        redButton.backgroundColor = .red
+        redButton.layer.cornerRadius = 5
+        redButton.layer.borderWidth = 0.5
+        redButton.layer.borderColor = NCBrandColor.shared.label.cgColor
+        redButton.layer.masksToBounds = true
+    }
+
+}

+ 4 - 3
iOSClient/Main/Collection Common/NCCollectionViewCommon.swift

@@ -1920,9 +1920,10 @@ extension NCCollectionViewCommon: EasyTipViewDelegate {
     }
 }
 
-@available(iOS 14.0, *)
-extension NCCollectionViewCommon: UIColorPickerViewControllerDelegate {
+//@available(iOS 15.0, *)
+extension NCCollectionViewCommon: NCColorPickerDelegate {
 
+    /*
     func colorPickerViewControllerDidFinish(_ viewController: UIColorPickerViewController) {
 
         if let metadata = menuMetadata {
@@ -1932,7 +1933,7 @@ extension NCCollectionViewCommon: UIColorPickerViewControllerDelegate {
                 reloadDataSource()
             }
         }
-        
     }
+    */
 }
 

+ 24 - 12
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -303,6 +303,28 @@ extension NCCollectionViewCommon {
             let serverUrl = metadata.serverUrl + "/" + metadata.fileName
             let tableDirectory = NCManageDatabase.shared.getTableDirectory(predicate: NSPredicate(format: "account == %@ AND serverUrl == %@", metadata.account, serverUrl))
 
+            actions.append(
+                NCMenuAction(
+                    title: NSLocalizedString("_change_color_", comment: ""),
+                    icon: NCUtility.shared.loadImage(named: "palette"),
+                    action: { _ in
+                        if let picker = UIStoryboard(name: "NCColorPicker", bundle: nil).instantiateInitialViewController() as? NCColorPicker {
+
+                            picker.delegate = self
+                            if let colorFolderHex = tableDirectory?.colorFolder {
+                                picker.selectedColor = UIColor.init(hex: colorFolderHex)
+                            }
+                            picker.defaultColor = NCBrandColor.shared.brandElement
+
+                            let popup = NCPopupViewController(contentController: picker, popupWidth: 400, popupHeight: 400)
+                            popup.backgroundAlpha = 0
+
+                            self.present(popup, animated: true)
+                        }
+                    }
+                )
+            )
+            /*
             if tableDirectory?.colorFolder != nil {
                 actions.append(
                     NCMenuAction(
@@ -315,19 +337,9 @@ extension NCCollectionViewCommon {
                     )
                 )
             } else {
-                actions.append(
-                    NCMenuAction(
-                        title: NSLocalizedString("_change_color_", comment: ""),
-                        icon: NCUtility.shared.loadImage(named: "palette"),
-                        action: { _ in
-                            let picker = UIColorPickerViewController()
-                            picker.delegate = self
-                            picker.supportsAlpha = false
-                            self.present(picker, animated: true, completion: nil)
-                        }
-                    )
-                )
+
             }
+            */
         }
         
         //