From 6901a01427b2563039f6db7abe9470a0518fed00 Mon Sep 17 00:00:00 2001 From: Emerson Carpes Date: Sun, 11 Sep 2022 19:52:55 -0300 Subject: [PATCH] Siri and shortcuts support --- Podfile | 8 ++ Podfile.lock | 2 +- Sabbath School.xcodeproj/project.pbxproj | 36 +++++++- Sabbath School/Application/AppDelegate.swift | 4 +- .../Lesson/Interactor/LessonInteractor.swift | 5 +- .../Lesson/Presenter/LessonPresenter.swift | 2 +- .../Lesson/Protocols/LessonProtocols.swift | 2 +- .../Controller/QuarterlyController.swift | 3 +- .../WireFrame/QuarterlyWireFrame.swift | 1 + .../ListenTodaySabbathSchoolIntent.swift | 89 +++++++++++++++++++ .../ReadTodaySabbathSchoolIntent.swift | 39 ++++++++ .../Siri/SabbathSchoolShortcuts.swift | 49 ++++++++++ 12 files changed, 229 insertions(+), 11 deletions(-) create mode 100644 Sabbath School/Siri/Intents/ListenTodaySabbathSchoolIntent.swift create mode 100644 Sabbath School/Siri/Intents/ReadTodaySabbathSchoolIntent.swift create mode 100644 Sabbath School/Siri/SabbathSchoolShortcuts.swift diff --git a/Podfile b/Podfile index 65040d5e..b16413f2 100644 --- a/Podfile +++ b/Podfile @@ -29,9 +29,17 @@ target 'WidgetExtension' do pod 'Cache' end +def fix_config(config) + # https://github.com/CocoaPods/CocoaPods/issues/8891 + if config.build_settings['DEVELOPMENT_TEAM'].nil? + config.build_settings['DEVELOPMENT_TEAM'] = 'XVGX5G4YQ9' + end +end + post_install do |installer| installer.pods_project.targets.each do |target| target.build_configurations.each do |config| + fix_config(config) config.build_settings['IPHONEOS_DEPLOYMENT_TARGET'] = '12.1' end diff --git a/Podfile.lock b/Podfile.lock index ae4bc165..fccd1820 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -156,6 +156,6 @@ SPEC CHECKSUMS: Wormholy: 3252bc3e55a1847ef9a0976c1377bd77bf3635fa Zip: 414f59909701fda9a84ab774ebe0f5449b1082cc -PODFILE CHECKSUM: bf33aea4066de337002d0c9bdadd340cb5f88d21 +PODFILE CHECKSUM: ddc27f5f1365b037934bb831febe8711c8156ea1 COCOAPODS: 1.11.3 diff --git a/Sabbath School.xcodeproj/project.pbxproj b/Sabbath School.xcodeproj/project.pbxproj index 781ff827..da7ea9a7 100644 --- a/Sabbath School.xcodeproj/project.pbxproj +++ b/Sabbath School.xcodeproj/project.pbxproj @@ -70,11 +70,14 @@ 4E2882CA280CCB7000AB8C31 /* PublishingInfoData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2882C9280CCB7000AB8C31 /* PublishingInfoData.swift */; }; 4E2882CC280CCBB600AB8C31 /* PublishingInfo.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2882CB280CCBB600AB8C31 /* PublishingInfo.swift */; }; 4E2882CE280CE46100AB8C31 /* PublishingInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E2882CD280CE46000AB8C31 /* PublishingInfoView.swift */; }; + 4E562ACB28C8C390006841F7 /* SabbathSchoolShortcuts.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E562ACA28C8C390006841F7 /* SabbathSchoolShortcuts.swift */; }; + 4E562ACE28C8C448006841F7 /* ReadTodaySabbathSchoolIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E562ACD28C8C448006841F7 /* ReadTodaySabbathSchoolIntent.swift */; }; 4E6409F527C5593B00A43D89 /* ScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E6409F427C5593A00A43D89 /* ScrollView.swift */; }; 4E7B09892814CA3D00687C33 /* Encodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E7B09882814CA3D00687C33 /* Encodable.swift */; }; 4E7B098C2814CA8A00687C33 /* Comparable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E7B098B2814CA8A00687C33 /* Comparable.swift */; }; 4EE2DF0827DA7AFC00812552 /* Array.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE2DF0727DA7AFC00812552 /* Array.swift */; }; 4EE8B6F5284D1FAA003C1A46 /* NotificationCenter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EE8B6F4284D1FAA003C1A46 /* NotificationCenter.swift */; }; + 4EFBFB9328C9EE56009FBD21 /* ListenTodaySabbathSchoolIntent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4EFBFB9228C9EE56009FBD21 /* ListenTodaySabbathSchoolIntent.swift */; }; 7A280F781ED7CF05003C7458 /* LoginWireFrame.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A280F771ED7CF05003C7458 /* LoginWireFrame.swift */; }; 7A280F7A1ED7CF2C003C7458 /* LoginView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7A280F791ED7CF2C003C7458 /* LoginView.swift */; }; 7A280F851ED7D6B6003C7458 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 7A280F841ED7D6B6003C7458 /* Assets.xcassets */; }; @@ -322,11 +325,14 @@ 4E2882C9280CCB7000AB8C31 /* PublishingInfoData.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishingInfoData.swift; sourceTree = ""; }; 4E2882CB280CCBB600AB8C31 /* PublishingInfo.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishingInfo.swift; sourceTree = ""; }; 4E2882CD280CE46000AB8C31 /* PublishingInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishingInfoView.swift; sourceTree = ""; }; + 4E562ACA28C8C390006841F7 /* SabbathSchoolShortcuts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SabbathSchoolShortcuts.swift; sourceTree = ""; }; + 4E562ACD28C8C448006841F7 /* ReadTodaySabbathSchoolIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadTodaySabbathSchoolIntent.swift; sourceTree = ""; }; 4E6409F427C5593A00A43D89 /* ScrollView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ScrollView.swift; sourceTree = ""; }; 4E7B09882814CA3D00687C33 /* Encodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Encodable.swift; sourceTree = ""; }; 4E7B098B2814CA8A00687C33 /* Comparable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Comparable.swift; sourceTree = ""; }; 4EE2DF0727DA7AFC00812552 /* Array.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Array.swift; sourceTree = ""; }; 4EE8B6F4284D1FAA003C1A46 /* NotificationCenter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationCenter.swift; sourceTree = ""; }; + 4EFBFB9228C9EE56009FBD21 /* ListenTodaySabbathSchoolIntent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListenTodaySabbathSchoolIntent.swift; sourceTree = ""; }; 523C8C93B698954EDD53FD14 /* Pods-SnapshotUITests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-SnapshotUITests.release.xcconfig"; path = "Pods/Target Support Files/Pods-SnapshotUITests/Pods-SnapshotUITests.release.xcconfig"; sourceTree = ""; }; 7A280F771ED7CF05003C7458 /* LoginWireFrame.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginWireFrame.swift; sourceTree = ""; }; 7A280F791ED7CF2C003C7458 /* LoginView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LoginView.swift; sourceTree = ""; }; @@ -720,6 +726,24 @@ path = API; sourceTree = ""; }; + 4E562AC928C8C21E006841F7 /* Siri */ = { + isa = PBXGroup; + children = ( + 4E562ACC28C8C404006841F7 /* Intents */, + 4E562ACA28C8C390006841F7 /* SabbathSchoolShortcuts.swift */, + ); + path = Siri; + sourceTree = ""; + }; + 4E562ACC28C8C404006841F7 /* Intents */ = { + isa = PBXGroup; + children = ( + 4E562ACD28C8C448006841F7 /* ReadTodaySabbathSchoolIntent.swift */, + 4EFBFB9228C9EE56009FBD21 /* ListenTodaySabbathSchoolIntent.swift */, + ); + path = Intents; + sourceTree = ""; + }; 4E7B098A2814CA7400687C33 /* Protocols */ = { isa = PBXGroup; children = ( @@ -1308,6 +1332,7 @@ 7AF191AA1ED7B89B000CCF0C /* Sabbath School */ = { isa = PBXGroup; children = ( + 4E562AC928C8C21E006841F7 /* Siri */, 2FC6F69927A8E0EA00BBC4A9 /* API */, 7A280F981EDA015D003C7458 /* Application */, 2F96FF4826C7186D0045DC6D /* Audio */, @@ -1844,6 +1869,7 @@ FE0A0FD8264E0A4300BF945A /* GCPopupView.swift in Sources */, 7A3BCE321EE27717003EC12B /* BibleWireFrame.swift in Sources */, 7A280F9B1EDA015D003C7458 /* AppDelegate.swift in Sources */, + 4E562ACE28C8C448006841F7 /* ReadTodaySabbathSchoolIntent.swift in Sources */, 2FA1FFE826F6BA6700E80868 /* Downloader.swift in Sources */, 7A280FC71EDA06F9003C7458 /* LoginButton.swift in Sources */, 2F96FF4C26C718A40045DC6D /* AudioPlaylistItemEmptyView.swift in Sources */, @@ -1905,6 +1931,7 @@ FE611ABA267501F9003CDDB5 /* Constants.swift in Sources */, FE1E34F326731A5F00DAC2D6 /* Spotlight.swift in Sources */, FE5CC73B268914F000B9F061 /* QuarterlyController.swift in Sources */, + 4EFBFB9328C9EE56009FBD21 /* ListenTodaySabbathSchoolIntent.swift in Sources */, 2F96FF6826CC9BBA0045DC6D /* Video.swift in Sources */, 7AF326181EFF92C700A04568 /* ReadEmptyView.swift in Sources */, 7A280FFE1EDD039C003C7458 /* LanguageItemView.swift in Sources */, @@ -1931,6 +1958,7 @@ 2F96FF7326CFF44F0045DC6D /* VideoView.swift in Sources */, 7A2810201EDDCEC9003C7458 /* LessonInteractor.swift in Sources */, 7A2810081EDD0C51003C7458 /* Navigation.swift in Sources */, + 4E562ACB28C8C390006841F7 /* SabbathSchoolShortcuts.swift in Sources */, 7A3BCE2E1EE2753C003EC12B /* BibleController.swift in Sources */, 7A2810041EDD0675003C7458 /* LanguageInteractor.swift in Sources */, 7A2810291EDDE41F003C7458 /* ShimmeringNode.swift in Sources */, @@ -2295,7 +2323,7 @@ CURRENT_PROJECT_VERSION = 1002; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = XVGX5G4YQ9; - ENABLE_BITCODE = YES; + ENABLE_BITCODE = NO; INFOPLIST_FILE = "Sabbath School/Application/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2435,7 +2463,7 @@ "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Distribution"; CURRENT_PROJECT_VERSION = 1002; DEVELOPMENT_TEAM = XVGX5G4YQ9; - ENABLE_BITCODE = YES; + ENABLE_BITCODE = NO; INFOPLIST_FILE = "Sabbath School/Application/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 12.1; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -2580,7 +2608,7 @@ CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1002; DEVELOPMENT_TEAM = XVGX5G4YQ9; - ENABLE_BITCODE = YES; + ENABLE_BITCODE = NO; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = Widget/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; @@ -2627,7 +2655,7 @@ CODE_SIGN_STYLE = Manual; CURRENT_PROJECT_VERSION = 1002; DEVELOPMENT_TEAM = XVGX5G4YQ9; - ENABLE_BITCODE = YES; + ENABLE_BITCODE = NO; GCC_C_LANGUAGE_STANDARD = gnu11; INFOPLIST_FILE = Widget/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 14.1; diff --git a/Sabbath School/Application/AppDelegate.swift b/Sabbath School/Application/AppDelegate.swift index 0cb50288..83898a79 100644 --- a/Sabbath School/Application/AppDelegate.swift +++ b/Sabbath School/Application/AppDelegate.swift @@ -157,8 +157,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate { return true } - func launchQuarterlies() { - let quarterlyController = QuarterlyWireFrame.createQuarterlyModule() + func launchQuarterlies(initiateOpen: Bool = false) { + let quarterlyController = QuarterlyWireFrame.createQuarterlyModule(initiateOpen: initiateOpen) Configuration.window?.rootViewController = quarterlyController Configuration.window?.makeKeyAndVisible() } diff --git a/Sabbath School/Lesson/Interactor/LessonInteractor.swift b/Sabbath School/Lesson/Interactor/LessonInteractor.swift index a2e80ccc..a0c16e89 100644 --- a/Sabbath School/Lesson/Interactor/LessonInteractor.swift +++ b/Sabbath School/Lesson/Interactor/LessonInteractor.swift @@ -38,7 +38,7 @@ class LessonInteractor: LessonInteractorInputProtocol { self.publishingInfoStorage = APICache.storage?.transformCodable(ofType: PublishingInfoData.self) } - func retrieveQuarterlyInfo(quarterlyIndex: String) { + func retrieveQuarterlyInfo(quarterlyIndex: String, completion: @escaping (QuarterlyInfo?) -> Void) { let parsedIndex = Helper.parseIndex(index: quarterlyIndex) let url = "\(Constants.API.URL)/\(parsedIndex.lang)/quarterlies/\(parsedIndex.quarter)/index.json" @@ -47,12 +47,14 @@ class LessonInteractor: LessonInteractorInputProtocol { if (try? self.storage?.existsObject(forKey: url)) != nil { if let quarterlyInfo = try? self.storage?.entry(forKey: url) { cachedObject = quarterlyInfo.object + completion(quarterlyInfo.object) self.presenter?.didRetrieveQuarterlyInfo(quarterlyInfo: quarterlyInfo.object) } } API.session.request(url).responseDecodable(of: QuarterlyInfo.self, decoder: Helper.SSJSONDecoder()) { response in guard let quarterlyInfo = response.value else { + completion(nil) self.presenter?.onError(response.error) return } @@ -61,6 +63,7 @@ class LessonInteractor: LessonInteractorInputProtocol { return } + completion(quarterlyInfo) self.presenter?.didRetrieveQuarterlyInfo(quarterlyInfo: quarterlyInfo) try? self.storage?.setObject(quarterlyInfo, forKey: url) } diff --git a/Sabbath School/Lesson/Presenter/LessonPresenter.swift b/Sabbath School/Lesson/Presenter/LessonPresenter.swift index 3521d4f7..c9d18c7c 100644 --- a/Sabbath School/Lesson/Presenter/LessonPresenter.swift +++ b/Sabbath School/Lesson/Presenter/LessonPresenter.swift @@ -30,7 +30,7 @@ class LessonPresenter: LessonPresenterProtocol { func configure() { interactor?.configure() - interactor?.retrieveQuarterlyInfo(quarterlyIndex: quarterlyIndex!) + interactor?.retrieveQuarterlyInfo(quarterlyIndex: quarterlyIndex!, completion: { _ in }) interactor?.retrievePublishingInfo() } diff --git a/Sabbath School/Lesson/Protocols/LessonProtocols.swift b/Sabbath School/Lesson/Protocols/LessonProtocols.swift index 35f388bd..49e6cf1b 100644 --- a/Sabbath School/Lesson/Protocols/LessonProtocols.swift +++ b/Sabbath School/Lesson/Protocols/LessonProtocols.swift @@ -62,6 +62,6 @@ protocol LessonInteractorInputProtocol: AnyObject { var presenter: LessonInteractorOutputProtocol? { get set } func configure() - func retrieveQuarterlyInfo(quarterlyIndex: String) + func retrieveQuarterlyInfo(quarterlyIndex: String, completion: @escaping (QuarterlyInfo?) -> Void) func retrievePublishingInfo() } diff --git a/Sabbath School/Quarterly/Controller/QuarterlyController.swift b/Sabbath School/Quarterly/Controller/QuarterlyController.swift index 242d4012..77804e31 100644 --- a/Sabbath School/Quarterly/Controller/QuarterlyController.swift +++ b/Sabbath School/Quarterly/Controller/QuarterlyController.swift @@ -40,7 +40,8 @@ class QuarterlyController: QuarterlyControllerCommon { let lastQuarterlyIndex = Preferences.currentQuarterly() let languageCode = lastQuarterlyIndex.components(separatedBy: "-") if let code = languageCode.first, Preferences.currentLanguage().code == code { - presenter?.presentLessonScreen(quarterlyIndex: lastQuarterlyIndex, initiateOpenToday: false) + presenter?.presentLessonScreen(quarterlyIndex: lastQuarterlyIndex, initiateOpenToday: initiateOpen ?? false + ) } } setupNavigationBar() diff --git a/Sabbath School/Quarterly/WireFrame/QuarterlyWireFrame.swift b/Sabbath School/Quarterly/WireFrame/QuarterlyWireFrame.swift index 3aa55997..bbe184e9 100644 --- a/Sabbath School/Quarterly/WireFrame/QuarterlyWireFrame.swift +++ b/Sabbath School/Quarterly/WireFrame/QuarterlyWireFrame.swift @@ -57,6 +57,7 @@ class SplitVc : UISplitViewController, UISplitViewControllerDelegate { class QuarterlyWireFrame: QuarterlyWireFrameProtocol { class func createQuarterlyModule(initiateOpen: Bool = false) -> ASNavigationController { let controller: QuarterlyControllerProtocol = QuarterlyController() + controller.initiateOpen = initiateOpen let presenter: QuarterlyPresenterProtocol & QuarterlyInteractorOutputProtocol = QuarterlyPresenter() let wireFrame: QuarterlyWireFrameProtocol = QuarterlyWireFrame() let interactor: QuarterlyInteractorInputProtocol = QuarterlyInteractor() diff --git a/Sabbath School/Siri/Intents/ListenTodaySabbathSchoolIntent.swift b/Sabbath School/Siri/Intents/ListenTodaySabbathSchoolIntent.swift new file mode 100644 index 00000000..5af4dce5 --- /dev/null +++ b/Sabbath School/Siri/Intents/ListenTodaySabbathSchoolIntent.swift @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2021 Adventech + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import AppIntents +import UIKit +import SwiftAudio + +@available(iOS 16.0, *) +struct ListenTodaySabbathSchoolIntent: AudioStartingIntent { + + static var title: LocalizedStringResource = "Starting Sabbath School" + static var openAppWhenRun: Bool = false + + @MainActor + func perform() async throws -> some IntentResult { + let lastQuarterlyIndex = Preferences.currentQuarterly() + retrieveAudio(quarterlyIndex: lastQuarterlyIndex) + + return .result(value: true) + } + + func retrieveAudio(quarterlyIndex: String) { + let audioInteractor = AudioInteractor() + let lessonInteractor = LessonInteractor() + + lessonInteractor.retrieveQuarterlyInfo(quarterlyIndex: quarterlyIndex) { quarterlyInfo in + audioInteractor.retrieveAudio(quarterlyIndex: quarterlyIndex) { audio in + let finalAudio = audio.filter { $0.targetIndex.starts(with: getTodaysLessonIndex(dataSource: quarterlyInfo)) } + + let audioItems: [AudioItem] = finalAudio.map { $0.audioItem() } + + AudioPlayback.configure() + try? AudioPlayback.shared.add(items: audioItems, playWhenReady: false) + try? AudioPlayback.shared.jumpToItem(atIndex: 1, playWhenReady: true) + + AudioPlayback.play() + } + } + } + + + func getTodaysLessonIndex(dataSource: QuarterlyInfo?) -> String { + guard let lessons = dataSource?.lessons else { return "" } + let today = Date() + let weekday = Calendar.current.component(.weekday, from: today) + let hour = Calendar.current.component(.hour, from: today) + var prevLessonIndex: String? = nil + + for lesson in lessons { + let start = Calendar.current.compare(lesson.startDate, to: today, toGranularity: .day) + let end = Calendar.current.compare(lesson.endDate, to: today, toGranularity: .day) + let fallsBetween = ((start == .orderedAscending) || (start == .orderedSame)) && ((end == .orderedDescending) || (end == .orderedSame)) + + if fallsBetween { + if (weekday == 7 && hour < 12 && prevLessonIndex != nil) { + return prevLessonIndex! + } else { + return lesson.index + } + } + prevLessonIndex = lesson.index + } + + if let firstLesson = lessons.first { + return firstLesson.index + } + + return "" + } +} diff --git a/Sabbath School/Siri/Intents/ReadTodaySabbathSchoolIntent.swift b/Sabbath School/Siri/Intents/ReadTodaySabbathSchoolIntent.swift new file mode 100644 index 00000000..d2d1ea95 --- /dev/null +++ b/Sabbath School/Siri/Intents/ReadTodaySabbathSchoolIntent.swift @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2021 Adventech + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import AppIntents +import UIKit + +@available(iOS 16.0, *) +struct ReadTodaySabbathSchoolIntent: AppIntent { + + static var title: LocalizedStringResource = "Starting Sabbath School" + static var openAppWhenRun: Bool = true + + @MainActor + func perform() async throws -> some IntentResult { + let appDelegate = UIApplication.shared.delegate as? AppDelegate + appDelegate?.launchQuarterlies(initiateOpen: true) + + return .result(value: true) + } +} diff --git a/Sabbath School/Siri/SabbathSchoolShortcuts.swift b/Sabbath School/Siri/SabbathSchoolShortcuts.swift new file mode 100644 index 00000000..b43e4ffd --- /dev/null +++ b/Sabbath School/Siri/SabbathSchoolShortcuts.swift @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2021 Adventech + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +import Intents +import AppIntents + +@available(iOS 16.0, *) +struct SabbathSchoolShortcuts: AppShortcutsProvider { + static var appShortcuts: [AppShortcut] { + AppShortcut( + intent: ListenTodaySabbathSchoolIntent(), + phrases: [ + "Listen \(.applicationName)", + "Play \(.applicationName)" + ] + ) + } +} + +//@available(iOS 16.0, *) +//struct SabbathSchoolShortcuts1: AppShortcutsProvider { +// static var appShortcuts: [AppShortcut] { +// AppShortcut( +// intent: ReadTodaySabbathSchoolIntent(), +// phrases: [ +// "Read \(.applicationName)" +// ] +// ) +// } +//}