Browse Source

#1702

Signed-off-by: marinofaggiana <marino.faggiana@nextcloud.com>
marinofaggiana 2 years ago
parent
commit
eb08144968

+ 6 - 2
Nextcloud.xcodeproj/project.pbxproj

@@ -476,6 +476,7 @@
 		F7F878AE1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */; };
 		F7F878AF1FB9E3B900599E4F /* NCEndToEndMetadata.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */; };
 		F7F9D1BB25397CE000D9BFF5 /* NCViewer.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */; };
+		F7FAFD3A28BFA948000777FE /* NCNotification+Menu.swift in Sources */ = {isa = PBXBuildFile; fileRef = F7FAFD3928BFA947000777FE /* NCNotification+Menu.swift */; };
 		F7FF2CB12842159500EBB7A1 /* NCSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = F7FF2CB02842159500EBB7A1 /* NCSectionHeader.xib */; };
 /* End PBXBuildFile section */
 
@@ -1036,6 +1037,7 @@
 		F7F67BB81A24D27800EE80DA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
 		F7F878AD1FB9E3B900599E4F /* NCEndToEndMetadata.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCEndToEndMetadata.swift; sourceTree = "<group>"; };
 		F7F9D1BA25397CE000D9BFF5 /* NCViewer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NCViewer.swift; sourceTree = "<group>"; };
+		F7FAFD3928BFA947000777FE /* NCNotification+Menu.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NCNotification+Menu.swift"; sourceTree = "<group>"; };
 		F7FC7D551DC1F93800BB2C6A /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; };
 		F7FF2CB02842159500EBB7A1 /* NCSectionHeader.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NCSectionHeader.xib; sourceTree = "<group>"; };
 /* End PBXFileReference section */
@@ -1161,6 +1163,7 @@
 				3704EB2923D5A58400455C5B /* NCMenu.storyboard */,
 				371B5A2D23D0B04500FAFAE9 /* NCMenu.swift */,
 				AF68326927BE65A90010BF0B /* NCMenuAction.swift */,
+				F7FAFD3928BFA947000777FE /* NCNotification+Menu.swift */,
 				AF935066276B84E700BD078F /* NCMenu+FloatingPanel.swift */,
 				3781B9AF23DB2B7E006B4B1D /* AppDelegate+Menu.swift */,
 				8491B1CC273BBA82001C8C5B /* UIViewController+Menu.swift */,
@@ -2890,6 +2893,7 @@
 				F70CAE3A1F8CF31A008125FD /* NCEndToEndEncryption.m in Sources */,
 				AF93471B27E2361E002537EE /* NCShareAdvancePermission.swift in Sources */,
 				F70753EB2542A99800972D44 /* NCViewerMediaPage.swift in Sources */,
+				F7FAFD3A28BFA948000777FE /* NCNotification+Menu.swift in Sources */,
 				F74C0436253F1CDC009762AB /* NCShares.swift in Sources */,
 				F7AC1CB028AB94490032D99F /* Array+Extensions.swift in Sources */,
 				F7AE00F5230D5F9E007ACF8A /* NCLoginWeb.swift in Sources */,
@@ -3605,8 +3609,8 @@
 			isa = XCRemoteSwiftPackageReference;
 			repositoryURL = "https://github.com/nextcloud/ios-communication-library/";
 			requirement = {
-				kind = exactVersion;
-				version = 0.99.8;
+				branch = Dashboard;
+				kind = branch;
 			};
 		};
 		F788ECC5263AAAF900ADC67F /* XCRemoteSwiftPackageReference "MarkdownKit" */ = {

+ 53 - 0
iOSClient/Menu/NCNotification+Menu.swift

@@ -0,0 +1,53 @@
+//
+//  NCNotification+Menu.swift
+//  Nextcloud
+//
+//  Created by Marino Faggiana on 31/08/2022.
+//  Copyright © 2022 Marino Faggiana. All rights reserved.
+//
+//  Author Marino Faggiana <marino.faggiana@nextcloud.com>
+//
+//  This program is free software: you can redistribute it and/or modify
+//  it under the terms of the GNU General Public License as published by
+//  the Free Software Foundation, either version 3 of the License, or
+//  (at your option) any later version.
+//
+//  This program is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+//  GNU General Public License for more details.
+//
+//  You should have received a copy of the GNU General Public License
+//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+//
+
+import UIKit
+import FloatingPanel
+import SwiftyJSON
+import NCCommunication
+
+extension NCNotification {
+
+    func toggleMenu(notification: NCCommunicationNotifications) {
+
+        var actions = [NCMenuAction]()
+
+        if let notificationActions = notification.actions, let jsonNotificationActionsActions = JSON(notificationActions).array {
+
+            for action in jsonNotificationActionsActions {
+                let label = action["label"].stringValue
+                actions.append(
+                    NCMenuAction(
+                        title: action["label"].stringValue,
+                        icon: UIImage(),
+                        action: { _ in
+                            self.tapAction(with: notification, label: label)
+                        }
+                    )
+                )
+            }
+        }
+
+        presentMenu(with: actions)
+    }
+}

+ 12 - 1
iOSClient/Networking/NCService.swift

@@ -24,6 +24,7 @@
 import UIKit
 import SVGKit
 import NCCommunication
+import SwiftyJSON
 
 class NCService: NSObject {
     @objc static let shared: NCService = {
@@ -242,7 +243,17 @@ class NCService: NSObject {
             }
 
             //TODO: TEST API
-            //NCNetworking.shared.getDashboardWidget(urlBase: self.appDelegate.urlBase, username: self.appDelegate.user, password: self.appDelegate.password) { errorCode, errorDescription in }
+            NCCommunication.shared.getDashboard { request in
+
+            } completion: { dashboardResult, json, errorCode, errorDescription in
+                if let json = json {
+                    for (_, subJson):(String, JSON) in json["ocs"]["data"]["recommendations"] {
+                        print("")
+
+                    }
+                    
+                }
+            }
         }
     }
 

+ 16 - 2
iOSClient/Notification/NCNotification.storyboard

@@ -1,9 +1,9 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="19455" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="c26-Us-IIn">
+<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" colorMatched="YES" initialViewController="c26-Us-IIn">
     <device id="retina4_7" orientation="portrait" appearance="light"/>
     <dependencies>
         <deployment identifier="iOS"/>
-        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="19454"/>
+        <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
         <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
     </dependencies>
     <scenes>
@@ -91,6 +91,17 @@
                                                 <action selector="touchUpInsideSecondary:" destination="R1c-h5-BOp" eventType="touchUpInside" id="Vy9-uI-sth"/>
                                             </connections>
                                         </button>
+                                        <button opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="4Ca-NL-V78" userLabel="More">
+                                            <rect key="frame" x="245" y="142" width="120" height="30"/>
+                                            <constraints>
+                                                <constraint firstAttribute="width" constant="120" id="2cb-3v-up9"/>
+                                                <constraint firstAttribute="height" constant="30" id="w4c-JV-GCL"/>
+                                            </constraints>
+                                            <state key="normal" title="more"/>
+                                            <connections>
+                                                <action selector="touchUpInsideMore:" destination="R1c-h5-BOp" eventType="touchUpInside" id="tzH-nO-8bt"/>
+                                            </connections>
+                                        </button>
                                         <imageView hidden="YES" userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="j3P-Mn-NRk" userLabel="avatar">
                                             <rect key="frame" x="10" y="40" width="25" height="25"/>
                                             <constraints>
@@ -103,11 +114,13 @@
                                     <constraints>
                                         <constraint firstItem="j3P-Mn-NRk" firstAttribute="leading" secondItem="9Bv-1W-yVV" secondAttribute="leading" constant="10" id="05B-JK-v6T"/>
                                         <constraint firstAttribute="trailing" secondItem="sMh-G7-FLo" secondAttribute="trailing" constant="10" id="4W9-Xm-fxY"/>
+                                        <constraint firstAttribute="bottom" secondItem="4Ca-NL-V78" secondAttribute="bottom" constant="15" id="4nu-oj-CtH"/>
                                         <constraint firstItem="9mD-Qe-1wu" firstAttribute="centerY" secondItem="YM1-uH-2Cz" secondAttribute="centerY" id="6VB-EF-GQs"/>
                                         <constraint firstItem="sMh-G7-FLo" firstAttribute="top" secondItem="9fz-sr-8Gv" secondAttribute="bottom" constant="5" id="EOH-W7-TBv"/>
                                         <constraint firstItem="pg1-7p-7Rz" firstAttribute="leading" secondItem="j3P-Mn-NRk" secondAttribute="trailing" constant="15" id="FHX-rf-Z0E"/>
                                         <constraint firstAttribute="trailing" secondItem="9mD-Qe-1wu" secondAttribute="trailing" constant="10" id="L9w-kA-Ypv"/>
                                         <constraint firstItem="sMh-G7-FLo" firstAttribute="leading" secondItem="obR-h7-TUC" secondAttribute="trailing" constant="10" id="MZG-Fc-cbL"/>
+                                        <constraint firstAttribute="trailing" secondItem="4Ca-NL-V78" secondAttribute="trailing" constant="10" id="RD1-Ox-wZH"/>
                                         <constraint firstAttribute="bottom" secondItem="sMh-G7-FLo" secondAttribute="bottom" constant="15" id="RKX-zp-kja"/>
                                         <constraint firstItem="9fz-sr-8Gv" firstAttribute="leading" secondItem="9Bv-1W-yVV" secondAttribute="leading" constant="50" id="ZxC-VD-ZtU"/>
                                         <constraint firstAttribute="trailing" secondItem="pg1-7p-7Rz" secondAttribute="trailing" constant="10" id="bwL-co-8gM"/>
@@ -130,6 +143,7 @@
                                     <outlet property="date" destination="YPu-No-c8x" id="CfW-Pz-jdL"/>
                                     <outlet property="icon" destination="YM1-uH-2Cz" id="MPX-ZL-wVR"/>
                                     <outlet property="message" destination="9fz-sr-8Gv" id="3Zx-pz-gEK"/>
+                                    <outlet property="more" destination="4Ca-NL-V78" id="b8O-Zg-dcf"/>
                                     <outlet property="primary" destination="sMh-G7-FLo" id="oyl-c8-sTP"/>
                                     <outlet property="primaryWidth" destination="tiI-55-Qu5" id="8H6-cf-vtP"/>
                                     <outlet property="remove" destination="9mD-Qe-1wu" id="r1h-mr-5U9"/>

+ 24 - 0
iOSClient/Notification/NCNotification.swift

@@ -161,6 +161,14 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
         cell.primary.layer.backgroundColor = NCBrandColor.shared.brandElement.cgColor
         cell.primary.setTitleColor(NCBrandColor.shared.brandText, for: .normal)
 
+        cell.more.isEnabled = false
+        cell.more.isHidden = true
+        cell.more.titleLabel?.font = .systemFont(ofSize: 15)
+        cell.more.layer.cornerRadius = 15
+        cell.more.layer.masksToBounds = true
+        cell.more.layer.backgroundColor = NCBrandColor.shared.brandElement.cgColor
+        cell.more.setTitleColor(NCBrandColor.shared.brandText, for: .normal)
+
         cell.secondary.isEnabled = false
         cell.secondary.isHidden = true
         cell.secondary.titleLabel?.font = .systemFont(ofSize: 15)
@@ -200,6 +208,11 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
                         cell.secondary.setTitle(label, for: .normal)
                     }
                 }
+            } else if jsonActions.count >= 3 {
+
+                cell.more.isEnabled = true
+                cell.more.isHidden = false
+                cell.more.setTitle("…", for: .normal)
             }
 
             var buttonWidth = max(cell.primary.intrinsicContentSize.width, cell.secondary.intrinsicContentSize.width)
@@ -268,6 +281,10 @@ class NCNotification: UITableViewController, NCNotificationCellDelegate, NCEmpty
         } // else: Action not found
     }
 
+    func tapMore(with notification: NCCommunicationNotifications) {
+       toggleMenu(notification: notification)
+    }
+
     // MARK: - Load notification networking
 
     func getNetwokingNotification() {
@@ -304,6 +321,7 @@ class NCNotificationCell: UITableViewCell, NCCellProtocol {
     @IBOutlet weak var remove: UIButton!
     @IBOutlet weak var primary: UIButton!
     @IBOutlet weak var secondary: UIButton!
+    @IBOutlet weak var more: UIButton!
     @IBOutlet weak var avatarLeadingMargin: NSLayoutConstraint!
     @IBOutlet weak var primaryWidth: NSLayoutConstraint!
     @IBOutlet weak var secondaryWidth: NSLayoutConstraint!
@@ -345,9 +363,15 @@ class NCNotificationCell: UITableViewCell, NCCellProtocol {
         else { return }
         delegate?.tapAction(with: notification, label: label)
     }
+
+    @IBAction func touchUpInsideMore(_ sender: Any) {
+        guard let notification = notification else { return }
+        delegate?.tapMore(with: notification)
+    }
 }
 
 protocol NCNotificationCellDelegate: AnyObject {
     func tapRemove(with notification: NCCommunicationNotifications)
     func tapAction(with notification: NCCommunicationNotifications, label: String)
+    func tapMore(with notification: NCCommunicationNotifications)
 }