Parcourir la source

improved widget

Signed-off-by: Marino Faggiana <marino@marinofaggiana.com>
Marino Faggiana il y a 2 ans
Parent
commit
c10384473a

+ 4 - 0
Nextcloud.xcodeproj/project.pbxproj

@@ -310,6 +310,7 @@
 		F77BB746289984CA0090FC19 /* UIViewController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77BB745289984CA0090FC19 /* UIViewController+Extension.swift */; };
 		F77BB748289985270090FC19 /* UITabBarController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77BB747289985270090FC19 /* UITabBarController+Extension.swift */; };
 		F77BB74A2899857B0090FC19 /* UINavigationController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = F77BB7492899857B0090FC19 /* UINavigationController+Extension.swift */; };
+		F77ED58F28C9CAD000E24ED0 /* Toolbar in Resources */ = {isa = PBXBuildFile; fileRef = F77ED58E28C9CAD000E24ED0 /* Toolbar */; };
 		F78071091EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */; };
 		F780710A1EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m in Sources */ = {isa = PBXBuildFile; fileRef = F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */; };
 		F78295311F962EFA00A572F5 /* NCEndToEndEncryption.m in Sources */ = {isa = PBXBuildFile; fileRef = F70CAE391F8CF31A008125FD /* NCEndToEndEncryption.m */; };
@@ -855,6 +856,7 @@
 		F77BB745289984CA0090FC19 /* UIViewController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIViewController+Extension.swift"; sourceTree = "<group>"; };
 		F77BB747289985270090FC19 /* UITabBarController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UITabBarController+Extension.swift"; sourceTree = "<group>"; };
 		F77BB7492899857B0090FC19 /* UINavigationController+Extension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UINavigationController+Extension.swift"; sourceTree = "<group>"; };
+		F77ED58E28C9CAD000E24ED0 /* Toolbar */ = {isa = PBXFileReference; lastKnownFileType = folder; path = Toolbar; sourceTree = "<group>"; };
 		F78071071EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSNotificationCenter+MainThread.h"; sourceTree = "<group>"; };
 		F78071081EDAB65800EAFFF6 /* NSNotificationCenter+MainThread.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSNotificationCenter+MainThread.m"; sourceTree = "<group>"; };
 		F783030E28B4C83F00B84583 /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; };
@@ -1377,6 +1379,7 @@
 			isa = PBXGroup;
 			children = (
 				F7346E2228B0FEBA006CE2D2 /* Assets.xcassets */,
+				F77ED58E28C9CAD000E24ED0 /* Toolbar */,
 				F72EA95528B7BAD100C88F0C /* Dashboard */,
 				F72EA95628B7BAE700C88F0C /* Nextcloud */,
 				F7346E2028B0FA3A006CE2D2 /* Widget-Brinding-header.h */,
@@ -2429,6 +2432,7 @@
 			files = (
 				F7C7B25128B8B0C400E7115D /* Images.xcassets in Resources */,
 				F7C7B25028B8AD4500E7115D /* Localizable.strings in Resources */,
+				F77ED58F28C9CAD000E24ED0 /* Toolbar in Resources */,
 				F7346E2328B0FEBA006CE2D2 /* Assets.xcassets in Resources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;

+ 48 - 0
Widget/Toolbar/ToolbarData.swift

@@ -0,0 +1,48 @@
+//
+//  ToolbarData.swift
+//  Widget
+//
+//  Created by Marino Faggiana on 25/08/22.
+//  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 WidgetKit
+
+let imageSize:CGFloat = 30
+let spacingImageUpload:CGFloat = 10
+
+struct ToolbarDataEntry: TimelineEntry {
+    let date: Date
+    let isPlaceholder: Bool
+    let footerImage: String
+    let footerText: String
+}
+
+func getToolbarDataEntry(isPreview: Bool, completion: @escaping (_ entry: ToolbarDataEntry) -> Void) {
+    
+    if isPreview {
+        return completion(ToolbarDataEntry(date: Date(), isPlaceholder: true, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar"))
+    }
+
+    guard let account = NCManageDatabase.shared.getActiveAccount() else {
+        return completion(ToolbarDataEntry(date: Date(), isPlaceholder: true, footerImage: "xmark.icloud", footerText: NSLocalizedString("_no_active_account_", value: "No account found", comment: "")))
+    }
+
+    completion(ToolbarDataEntry(date: Date(), isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar"))
+}
+

+ 47 - 0
Widget/Toolbar/ToolbarWidgetProvider.swift

@@ -0,0 +1,47 @@
+//
+//  ToolbarWidgetProvider.swift
+//  Widget
+//
+//  Created by Marino Faggiana on 25/08/22.
+//  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 WidgetKit
+import SwiftUI
+
+struct ToolbarWidgetProvider: TimelineProvider {
+
+    typealias Entry = ToolbarDataEntry
+
+    func placeholder(in context: Context) -> Entry {
+        return Entry(date: Date(), isPlaceholder: true, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
+    }
+
+    func getSnapshot(in context: Context, completion: @escaping (Entry) -> Void) {
+        getToolbarDataEntry(isPreview: false) { entry in
+            completion(entry)
+        }
+    }
+
+    func getTimeline(in context: Context, completion: @escaping (Timeline<Entry>) -> Void) {
+        getToolbarDataEntry(isPreview: context.isPreview) { entry in
+            let timeLine = Timeline(entries: [entry], policy: .atEnd)
+            completion(timeLine)
+        }
+    }
+}

+ 113 - 0
Widget/Toolbar/ToolbarWidgetView.swift

@@ -0,0 +1,113 @@
+//
+//  ToolbarWidgetView.swift
+//  Widget
+//
+//  Created by Marino Faggiana on 25/08/22.
+//  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 SwiftUI
+import WidgetKit
+
+struct ToolbarWidgetView: View {
+    
+    var entry: ToolbarDataEntry
+    
+    var body: some View {
+        
+        GeometryReader { geo in
+            
+            ZStack(alignment: .topLeading) {
+                
+                HStack(spacing: 0) {
+
+                    Link(destination: URL(string: "nextcloud://open-action?action=upload-asset")!, label: {
+                        Image("buttonAddImage")
+                            .resizable()
+                            .renderingMode(.template)
+                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .padding(10)
+                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .clipShape(Circle())
+                            .scaledToFit()
+                            .frame(width: geo.size.width / 4, height: 50)
+                    })
+
+                    Link(destination: URL(string: "nextcloud://open-action?action=add-scan-document")!, label: {
+                        Image("buttonAddScan")
+                            .resizable()
+                            .renderingMode(.template)
+                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .padding(10)
+                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .clipShape(Circle())
+                            .scaledToFit()
+                            .frame(width: geo.size.width / 4, height: 50)
+                    })
+
+                    Link(destination: URL(string: "nextcloud://open-action?action=create-text-document")!, label: {
+                        Image("note.text")
+                            .resizable()
+                            .renderingMode(.template)
+                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .padding(10)
+                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .clipShape(Circle())
+                            .scaledToFit()
+                            .frame(width: geo.size.width / 4, height: 50)
+                    })
+
+                    Link(destination: URL(string: "nextcloud://open-action?action=create-voice-memo")!, label: {
+                        Image("microphone")
+                            .resizable()
+                            .renderingMode(.template)
+                            .foregroundColor(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brandText))
+                            .padding(10)
+                            .background(entry.isPlaceholder ? Color(white: 0.8) : Color(NCBrandColor.shared.brand))
+                            .clipShape(Circle())
+                            .scaledToFit()
+                            .frame(width: geo.size.width / 4, height: 50)
+                    })
+                }
+                .frame(width: geo.size.width, height: geo.size.height - 35, alignment: .bottomTrailing)
+                .redacted(reason: entry.isPlaceholder ? .placeholder : [])
+
+                HStack {
+
+                    Image(systemName: entry.footerImage)
+                        .resizable()
+                        .scaledToFit()
+                        .frame(width: 15, height: 15)
+                        .foregroundColor(entry.isPlaceholder ? Color(white: 0.2) : Color(NCBrandColor.shared.brand))
+                    
+                    Text(entry.footerText)
+                        .font(.caption2)
+                        .padding(.trailing, 13.0)
+                }
+                .frame(maxWidth: geo.size.width - 5, maxHeight: geo.size.height - 2, alignment: .bottomTrailing)
+            }
+        }
+    }
+}
+
+struct ToolbarWidget_Previews: PreviewProvider {
+    static var previews: some View {
+        let entry = ToolbarDataEntry(date: Date(), isPlaceholder: false, footerImage: "checkmark.icloud", footerText: NCBrandOptions.shared.brand + " toolbar")
+        NextcloudWidgetView(entry: entry).previewContext(WidgetPreviewContext(family: .systemSmall))
+    }
+}