From 3c74d71ddad806ab029727aedbe4723eb73dde5a Mon Sep 17 00:00:00 2001 From: Pavlo Boiko Date: Thu, 11 Nov 2021 23:30:17 +0200 Subject: [PATCH] Demo for FusioinNotifications --- Notifications/.gitignore | 88 +++++++++++++++ Notifications/Package.swift | 38 +++++++ .../Pages/TimerPage/TimerPage.page.ext.swift | 23 ++++ .../Extensions/Pages/main.page.ext.swift | 19 ++++ .../Notifications/PushPage/PushPage.page | 11 ++ .../Notifications/PushPage/PushPage.page.svg | 7 ++ .../PushPage/PushPage.page.swift | 10 ++ .../Notifications/TimerPage/TimerPage.page | 77 +++++++++++++ .../TimerPage/TimerPage.page.svg | 32 ++++++ .../TimerPage/TimerPage.page.swift | 45 ++++++++ Notifications/Sources/Notifications/main.page | 61 +++++++++++ .../Sources/Notifications/main.page.svg | 24 +++++ .../Sources/Notifications/main.page.swift | 25 +++++ .../Sources/Notifications/start.swift | 12 +++ Notifications/build.yaml | 102 ++++++++++++++++++ 15 files changed, 574 insertions(+) create mode 100644 Notifications/.gitignore create mode 100644 Notifications/Package.swift create mode 100644 Notifications/Sources/Notifications/Extensions/Pages/TimerPage/TimerPage.page.ext.swift create mode 100644 Notifications/Sources/Notifications/Extensions/Pages/main.page.ext.swift create mode 100644 Notifications/Sources/Notifications/PushPage/PushPage.page create mode 100644 Notifications/Sources/Notifications/PushPage/PushPage.page.svg create mode 100644 Notifications/Sources/Notifications/PushPage/PushPage.page.swift create mode 100644 Notifications/Sources/Notifications/TimerPage/TimerPage.page create mode 100644 Notifications/Sources/Notifications/TimerPage/TimerPage.page.svg create mode 100644 Notifications/Sources/Notifications/TimerPage/TimerPage.page.swift create mode 100644 Notifications/Sources/Notifications/main.page create mode 100644 Notifications/Sources/Notifications/main.page.svg create mode 100644 Notifications/Sources/Notifications/main.page.swift create mode 100644 Notifications/Sources/Notifications/start.swift create mode 100644 Notifications/build.yaml diff --git a/Notifications/.gitignore b/Notifications/.gitignore new file mode 100644 index 0000000..ea2b5f9 --- /dev/null +++ b/Notifications/.gitignore @@ -0,0 +1,88 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ +Package.resolved +Product/ + +# CocoaPods +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# Pods/ +# +# Add this line if you want to avoid checking in source code from the Xcode workspace +# *.xcworkspace + +# Carthage +# +# Add this line if you want to avoid checking in source code from Carthage dependencies. +# Carthage/Checkouts + +Carthage/Build/ + +# Accio dependency management +Dependencies/ +.accio/ + +# fastlane +# +# It is recommended to not store the screenshots in the git repo. +# Instead, use fastlane to re-generate the screenshots whenever they are needed. +# For more information about the recommended setup visit: +# https://docs.fastlane.tools/best-practices/source-control/#source-control + +fastlane/report.xml +fastlane/Preview.html +fastlane/screenshots/**/*.png +fastlane/test_output + +# Code Injection +# +# After new code Injection tools there's a generated folder /iOSInjectionProject +# https://github.com/johnno1962/injectionforxcode diff --git a/Notifications/Package.swift b/Notifications/Package.swift new file mode 100644 index 0000000..78ae189 --- /dev/null +++ b/Notifications/Package.swift @@ -0,0 +1,38 @@ +// swift-tools-version:5.3 + +import PackageDescription +import Foundation + +let SCADE_SDK = ProcessInfo.processInfo.environment["SCADE_SDK"] ?? "" + +let package = Package( + name: "Notifications", + platforms: [ + .macOS(.v10_14) + ], + products: [ + .library( + name: "Notifications", + type: .static, + targets: [ + "Notifications" + ] + ) + ], + dependencies: [ + .package(name: "FusionNotifications", url: "https://github.com/scade-platform/FusionNotifications.git", .branch("pavlo")) + ], + targets: [ + .target( + name: "Notifications", + dependencies: [ + .product(name: "FusionNotifications", package: "FusionNotifications") + ], + exclude: ["main.page"], + swiftSettings: [ + .unsafeFlags(["-F", SCADE_SDK], .when(platforms: [.macOS, .iOS])), + .unsafeFlags(["-I", "\(SCADE_SDK)/include"], .when(platforms: [.android])), + ] + ) + ] +) \ No newline at end of file diff --git a/Notifications/Sources/Notifications/Extensions/Pages/TimerPage/TimerPage.page.ext.swift b/Notifications/Sources/Notifications/Extensions/Pages/TimerPage/TimerPage.page.ext.swift new file mode 100644 index 0000000..e80d389 --- /dev/null +++ b/Notifications/Sources/Notifications/Extensions/Pages/TimerPage/TimerPage.page.ext.swift @@ -0,0 +1,23 @@ +import ScadeKit + +extension TimerPagePageAdapter { + var label: SCDWidgetsLabel { + return self.page?.getWidgetByName("label") as! SCDWidgetsLabel + } + + var titleTextfield: SCDWidgetsTextbox { + return self.page?.getWidgetByName("titleTextfield") as! SCDWidgetsTextbox + } + + var label1: SCDWidgetsLabel { + return self.page?.getWidgetByName("label1") as! SCDWidgetsLabel + } + + var bodyTextfield: SCDWidgetsTextbox { + return self.page?.getWidgetByName("bodyTextfield") as! SCDWidgetsTextbox + } + + var sendButton: SCDWidgetsButton { + return self.page?.getWidgetByName("sendButton") as! SCDWidgetsButton + } +} \ No newline at end of file diff --git a/Notifications/Sources/Notifications/Extensions/Pages/main.page.ext.swift b/Notifications/Sources/Notifications/Extensions/Pages/main.page.ext.swift new file mode 100644 index 0000000..4b56fc4 --- /dev/null +++ b/Notifications/Sources/Notifications/Extensions/Pages/main.page.ext.swift @@ -0,0 +1,19 @@ +import ScadeKit + +extension MainPageAdapter { + var pageContainer: SCDLatticePageContainer { + return self.page?.getWidgetByName("pageContainer") as! SCDLatticePageContainer + } + + var toolBar: SCDWidgetsToolBar { + return self.page?.getWidgetByName("toolBar") as! SCDWidgetsToolBar + } + + var timerButton: SCDWidgetsButton { + return self.page?.getWidgetByName("timerButton") as! SCDWidgetsButton + } + + var pushButton: SCDWidgetsButton { + return self.page?.getWidgetByName("pushButton") as! SCDWidgetsButton + } +} \ No newline at end of file diff --git a/Notifications/Sources/Notifications/PushPage/PushPage.page b/Notifications/Sources/Notifications/PushPage/PushPage.page new file mode 100644 index 0000000..52bd847 --- /dev/null +++ b/Notifications/Sources/Notifications/PushPage/PushPage.page @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/Notifications/Sources/Notifications/PushPage/PushPage.page.svg b/Notifications/Sources/Notifications/PushPage/PushPage.page.svg new file mode 100644 index 0000000..4cfe98a --- /dev/null +++ b/Notifications/Sources/Notifications/PushPage/PushPage.page.svg @@ -0,0 +1,7 @@ + + + + + + + diff --git a/Notifications/Sources/Notifications/PushPage/PushPage.page.swift b/Notifications/Sources/Notifications/PushPage/PushPage.page.swift new file mode 100644 index 0000000..7f56834 --- /dev/null +++ b/Notifications/Sources/Notifications/PushPage/PushPage.page.swift @@ -0,0 +1,10 @@ +import ScadeKit + +class PushPagePageAdapter: SCDLatticePageAdapter { + + // page adapter initialization + override func load(_ path: String) { + super.load(path) + + } +} diff --git a/Notifications/Sources/Notifications/TimerPage/TimerPage.page b/Notifications/Sources/Notifications/TimerPage/TimerPage.page new file mode 100644 index 0000000..3bcf92e --- /dev/null +++ b/Notifications/Sources/Notifications/TimerPage/TimerPage.page @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Notifications/Sources/Notifications/TimerPage/TimerPage.page.svg b/Notifications/Sources/Notifications/TimerPage/TimerPage.page.svg new file mode 100644 index 0000000..6751315 --- /dev/null +++ b/Notifications/Sources/Notifications/TimerPage/TimerPage.page.svg @@ -0,0 +1,32 @@ + + + + + + + + + Title + + + + + + Hello World + + + + Body + + + + + + My Local Notification + + + + Send + + + diff --git a/Notifications/Sources/Notifications/TimerPage/TimerPage.page.swift b/Notifications/Sources/Notifications/TimerPage/TimerPage.page.swift new file mode 100644 index 0000000..f200406 --- /dev/null +++ b/Notifications/Sources/Notifications/TimerPage/TimerPage.page.swift @@ -0,0 +1,45 @@ +import ScadeKit +import FusionNotifications + +class TimerPagePageAdapter: SCDLatticePageAdapter { + + // page adapter initialization + override func load(_ path: String) { + super.load(path) + + let actions = [ + NotificationAction(identifier: "acc_Accept", title: "Accept"), + NotificationAction(identifier: "acc_Reject", title: "Reject") + ] + let category = NotificationCategory(identifier: "Notification.Category.Read", actions: actions) + + NotificationManager.shared.delegate = self + NotificationManager.shared.registerNotificationCategory(category: category) + + self.sendButton.onClick{_ in self.send()} + + } + + func send() { + let content = NotificationContent(title: self.titleTextfield.text, body: self.bodyTextfield.text, category: "Notification.Category.Read") + let trigger = TimeNotificationTrigger(timeInterval: 10, repeats: false) + + NotificationManager.shared.add(identifier: "Local notification", content: content, trigger: trigger) + } +} + +extension TimerPagePageAdapter: NotificationDelegate { + func didReceive(notification: FusionNotifications_Common.Notification, userActionIdentifier: String) { + guard let content = notification.content else { return } + if userActionIdentifier == "acc_Accept" { + print("User accepted \(content.body)") + } else if userActionIdentifier == "acc_Reject" { + print("User rejected \(content.body)") + } + } + + func willPresent(notification: FusionNotifications_Common.Notification) { + guard let content = notification.content else { return } + print("Content body = \(content.body)") + } +} \ No newline at end of file diff --git a/Notifications/Sources/Notifications/main.page b/Notifications/Sources/Notifications/main.page new file mode 100644 index 0000000..f1d3f69 --- /dev/null +++ b/Notifications/Sources/Notifications/main.page @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Notifications/Sources/Notifications/main.page.svg b/Notifications/Sources/Notifications/main.page.svg new file mode 100644 index 0000000..2104606 --- /dev/null +++ b/Notifications/Sources/Notifications/main.page.svg @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + Timer + + + + Push + + + + + diff --git a/Notifications/Sources/Notifications/main.page.swift b/Notifications/Sources/Notifications/main.page.swift new file mode 100644 index 0000000..a78488e --- /dev/null +++ b/Notifications/Sources/Notifications/main.page.swift @@ -0,0 +1,25 @@ +import ScadeKit + +class MainPageAdapter: SCDLatticePageAdapter { + + let timer : TimerPagePageAdapter = TimerPagePageAdapter() + let push : PushPagePageAdapter = PushPagePageAdapter() + + // page adapter initialization + override func load(_ path: String) { + super.load(path) + + self.timer.load("TimerPage.page") + self.push.load("PushPage.page") + + self.timerButton.onClick{_ in self.showPage(self.timer)} + self.pushButton.onClick{_ in self.showPage(self.push)} + + // Finally, we use the page container to show page1 + self.timer.show(view: self.pageContainer) + } + + func showPage(_ page:SCDLatticePageAdapter) { + page.show(view: self.pageContainer) + } +} diff --git a/Notifications/Sources/Notifications/start.swift b/Notifications/Sources/Notifications/start.swift new file mode 100644 index 0000000..68116bd --- /dev/null +++ b/Notifications/Sources/Notifications/start.swift @@ -0,0 +1,12 @@ +import ScadeKit + +class Notifications: SCDApplication { + + let window = SCDLatticeWindow() + let mainAdapter = MainPageAdapter() + + override func onFinishLaunching() { + mainAdapter.load("main.page") + mainAdapter.show(view: window) + } +} diff --git a/Notifications/build.yaml b/Notifications/build.yaml new file mode 100644 index 0000000..39a84d4 --- /dev/null +++ b/Notifications/build.yaml @@ -0,0 +1,102 @@ +spm: + - url: + from: + path: + branch: + exact: + revision: + search-paths: [] + linked-libs: [] + +search-paths: [] +linked-libs: [] + +ios: + name: Notifications + id: com.scade.notifications + device-family: iphone # iphone, ipad or universal + supported-interface-orientations: ['portrait'] # portrait, upside_down, landscape_left or landscape_right + supported-interface-orientationsiPad: ['portrait'] + entitlements-file: + app-delegate-file: + export-method: ad-hoc # app-store, enterprise or development + simulator: + os: 12.1 + output: Notifications/.build/ios-simulator + extra-args: + search-paths: [] + linked-libs: [] + device: + os: 12.1 + output: Notifications/.build/ios-device + product-path: Notifications/Product/ios-device + extra-args: + search-paths: [] + linked-libs: [] + mac: + os: 10.11 + output: Notifications/.build/scade-simulator + extra-args: + search-paths: [] + linked-libs: [] + sign: + provision-profile: + certificate: + icons: + iphone: # or ipad, sizes: 20X20, 29X29, 40X40, 60X60, 76X76, 83.5X83.5 + 60X60_2X: + 76X76_2X: + 76X76_3X: + 83.5X83.5_2X: + marketing: + 1024X1024_1X: + plist: + CFBundleShortVersionString: string# 1.0 + CFBundleVersion: string# 1 + NSLocationWhenInUseUsageDescription: + NSCameraUsageDescription: Take pictures from camera + NSPhotoLibraryUsageDescription: Choose a photo from your library + +android: + name: Notifications + id: com.scade.notifications + version-name: 1.0.0 + version-code: 1 + build-type: Debug + key-store-properties: + google-api-key: + manifest-file: + permissions: [] + armeabi-v7a: + output: Notifications/.build/android-armeabi-v7a + product-path: Notifications/Product/android-armeabi-v7a + extra-args: + search-paths: [] + linked-libs: [] + arm64-v8a: + output: Notifications/.build/android-arm64-v8a + product-path: Notifications/Product/android-arm64-v8a + extra-args: + search-paths: [] + linked-libs: [] + x86: + output: Notifications/.build/android-x86 + product-path: Notifications/Product/android-x86 + extra-args: + search-paths: [] + linked-libs: [] + x86_64: + output: Notifications/.build/android-x86_64 + product-path: Notifications/Product/android-x86_64 + extra-args: + search-paths: [] + linked-libs: [] + intent-filters: + - action: + scheme: + categories: [] + icons: + mdpi: + hdpi: + xhdpi: + xxhdpi: