Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Demo for FusioinNotifications #5

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions Notifications/.gitignore
Original file line number Diff line number Diff line change
@@ -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
38 changes: 38 additions & 0 deletions Notifications/Package.swift
Original file line number Diff line number Diff line change
@@ -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])),
]
)
]
)
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
11 changes: 11 additions & 0 deletions Notifications/Sources/Notifications/PushPage/PushPage.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xmi:XMI xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:version="2.0" xmlns:binding="http://scade.com/sdk/data/binding" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:graphics="http://scade.com/sdk/view/graphics" xmlns:layout="http://scade.com/sdk/layout" xmlns:navigation="http://scade.com/lattice/navigation" xmlns:widgets="http://scade.com/sdk/view/widgets">
<widgets:Page name="PushPage">
<backgroundColor Red="248" Green="248" Blue="248"/>
<layout xsi:type="layout:AutoLayout"/>
<location/>
<size width="414" height="736"/>
</widgets:Page>
<binding:BindingModel/>
<navigation:Navigation page="/0"/>
</xmi:XMI>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions Notifications/Sources/Notifications/PushPage/PushPage.page.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import ScadeKit

class PushPagePageAdapter: SCDLatticePageAdapter {

// page adapter initialization
override func load(_ path: String) {
super.load(path)

}
}
77 changes: 77 additions & 0 deletions Notifications/Sources/Notifications/TimerPage/TimerPage.page
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<xmi:XMI xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:version="2.0" xmlns:binding="http://scade.com/sdk/data/binding" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:graphics="http://scade.com/sdk/view/graphics" xmlns:layout="http://scade.com/sdk/layout" xmlns:navigation="http://scade.com/lattice/navigation" xmlns:widgets="http://scade.com/sdk/view/widgets">
<widgets:Page name="TimerPage">
<minArea width="414" height="736"/>
<location/>
<backgroundColor Red="248" Green="248" Blue="248"/>
<children xsi:type="widgets:Label" text="Title" name="label">
<font fontFamily="ArialMT" size="15">
<color Red="70" Green="70" Blue="70"/>
</font>
<layoutData xsi:type="layout:AutoLayoutData">
<constraints sourceAnchor="TOP" targetAnchor="TOP" constant="50" source="/0/@children.0" target="/0"/>
<constraints constant="30" source="/0/@children.0" target="/0"/>
</layoutData>
<location x="30" y="50"/>
<size width="44" height="22"/>
<contentSize width="28" height="18"/>
</children>
<children xsi:type="widgets:Textbox" placeholder="Input the title of notification" text="Hello World" name="titleTextfield">
<font fontFamily="ArialMT" size="17">
<color Red="191" Green="191" Blue="191"/>
</font>
<location x="30" y="92"/>
<size width="354" height="22"/>
<contentSize width="354" height="19"/>
<layoutData xsi:type="layout:AutoLayoutData">
<constraints sourceAnchor="TOP" targetAnchor="BOTTOM" constant="20" source="/0/@children.1" target="/0/@children.0"/>
<constraints constant="30" source="/0/@children.1" target="/0"/>
<constraints sourceAnchor="RIGHT" targetAnchor="RIGHT" constant="-30" source="/0/@children.1" target="/0"/>
</layoutData>
<backgroundColor Red="238" Green="238" Blue="238" Alpha="204"/>
</children>
<children xsi:type="widgets:Label" text="Body" name="label1">
<font fontFamily="ArialMT" size="17">
<color Red="70" Green="70" Blue="70"/>
</font>
<layoutData xsi:type="layout:AutoLayoutData">
<constraints sourceAnchor="TOP" targetAnchor="BOTTOM" constant="30" source="/0/@children.2" target="/0/@children.1"/>
<constraints constant="30" source="/0/@children.2" target="/0"/>
<constraints sourceAnchor="RIGHT" targetAnchor="RIGHT" constant="-30" source="/0/@children.2" target="/0"/>
</layoutData>
<location x="30" y="144"/>
<size width="354" height="22"/>
<contentSize width="39" height="19"/>
</children>
<children xsi:type="widgets:Textbox" placeholder="Input the body of notification" text="My Local Notification" name="bodyTextfield">
<font fontFamily="ArialMT" size="17">
<color Red="191" Green="191" Blue="191"/>
</font>
<location x="30" y="186"/>
<size width="354" height="22"/>
<contentSize width="354" height="19"/>
<layoutData xsi:type="layout:AutoLayoutData">
<constraints sourceAnchor="TOP" targetAnchor="BOTTOM" constant="20" source="/0/@children.3" target="/0/@children.2"/>
<constraints constant="30" source="/0/@children.3" target="/0"/>
<constraints sourceAnchor="RIGHT" targetAnchor="RIGHT" constant="-30" source="/0/@children.3" target="/0"/>
</layoutData>
<backgroundColor Red="238" Green="238" Blue="238" Alpha="204"/>
</children>
<children xsi:type="widgets:Button" text="Send" name="sendButton" horizontalAlignment="CENTER">
<font fontFamily="ArialMT" size="17">
<color/>
</font>
<layoutData xsi:type="layout:AutoLayoutData">
<constraints sourceAnchor="TOP" targetAnchor="BOTTOM" constant="50" source="/0/@children.4" target="/0/@children.3"/>
</layoutData>
<location x="152" y="258"/>
<size width="86" height="23"/>
<contentSize width="40" height="19"/>
</children>
<layout xsi:type="layout:AutoLayout"/>
<maxArea width="414" height="736"/>
<size width="414" height="736"/>
</widgets:Page>
<binding:BindingModel/>
<navigation:Navigation page="/0"/>
</xmi:XMI>
32 changes: 32 additions & 0 deletions Notifications/Sources/Notifications/TimerPage/TimerPage.page.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions Notifications/Sources/Notifications/TimerPage/TimerPage.page.swift
Original file line number Diff line number Diff line change
@@ -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)")
}
}
Loading