From e22d716b3abcff4c70b67bddecceda371bdf5241 Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Sun, 17 Apr 2022 19:04:36 -0400 Subject: [PATCH 1/2] feat: add CustomFeaturedContentView card --- OCKSample.xcodeproj/project.pbxproj | 4 ++ .../MainTabs/Care/CareViewController.swift | 17 +++---- .../Care/CustomFeaturedContentView.swift | 44 +++++++++++++++++++ 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 OCKSample/MainTabs/Care/CustomFeaturedContentView.swift diff --git a/OCKSample.xcodeproj/project.pbxproj b/OCKSample.xcodeproj/project.pbxproj index fd26558..df1aee5 100644 --- a/OCKSample.xcodeproj/project.pbxproj +++ b/OCKSample.xcodeproj/project.pbxproj @@ -12,6 +12,7 @@ 70077597252228E900EC0EDA /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70077596252228E900EC0EDA /* User.swift */; }; 7007759B252229C900EC0EDA /* User.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70077596252228E900EC0EDA /* User.swift */; }; 70123069280830A1003F5ECE /* Consent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 70123068280830A1003F5ECE /* Consent.swift */; }; + 701230D6280CCFC4003F5ECE /* CustomFeaturedContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 701230D5280CCFC4003F5ECE /* CustomFeaturedContentView.swift */; }; 70202EC12807333900CF73FB /* CareKit in Frameworks */ = {isa = PBXBuildFile; productRef = 70202EC02807333900CF73FB /* CareKit */; }; 70202EC32807333900CF73FB /* CareKitFHIR in Frameworks */ = {isa = PBXBuildFile; productRef = 70202EC22807333900CF73FB /* CareKitFHIR */; }; 70202EC52807333A00CF73FB /* CareKitUI in Frameworks */ = {isa = PBXBuildFile; productRef = 70202EC42807333A00CF73FB /* CareKitUI */; }; @@ -189,6 +190,7 @@ 51F6343923D2877B00FE576E /* HealthKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = HealthKit.framework; path = System/Library/Frameworks/HealthKit.framework; sourceTree = SDKROOT; }; 70077596252228E900EC0EDA /* User.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = User.swift; sourceTree = ""; }; 70123068280830A1003F5ECE /* Consent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Consent.swift; sourceTree = ""; }; + 701230D5280CCFC4003F5ECE /* CustomFeaturedContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomFeaturedContentView.swift; sourceTree = ""; }; 70202EC9280746E900CF73FB /* ResearchKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ResearchKit.xcodeproj; path = ResearchKit/ResearchKit.xcodeproj; sourceTree = ""; }; 70202ED52807529900CF73FB /* Surveys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Surveys.swift; sourceTree = ""; }; 70308885258273D400FFABB6 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = ""; }; @@ -343,6 +345,7 @@ 7036E4C3256E0A48006E9A3C /* CareView.swift */, 70F03ABA2789071400E5AFB4 /* CareViewModel.swift */, E7C37848228F887800E982D8 /* TipView.swift */, + 701230D5280CCFC4003F5ECE /* CustomFeaturedContentView.swift */, ); path = Care; sourceTree = ""; @@ -885,6 +888,7 @@ 70F921AE27CABE7700368CEC /* RemoteSessionDelegate.swift in Sources */, 70F03A952786093B00E5AFB4 /* OCKHealthKitPassthroughStore+Default.swift in Sources */, 7036E4BF256DA089006E9A3C /* LoginViewModel.swift in Sources */, + 701230D6280CCFC4003F5ECE /* CustomFeaturedContentView.swift in Sources */, 7036E517256F2413006E9A3C /* ProfileViewModel.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; diff --git a/OCKSample/MainTabs/Care/CareViewController.swift b/OCKSample/MainTabs/Care/CareViewController.swift index a65ad05..36a0748 100644 --- a/OCKSample/MainTabs/Care/CareViewController.swift +++ b/OCKSample/MainTabs/Care/CareViewController.swift @@ -187,15 +187,16 @@ class CareViewController: OCKDailyPageViewController { // Only show the tip view on the current date if isCurrentDay { if Calendar.current.isDate(date, inSameDayAs: Date()) { - // Add a non-CareKit view into the list + // TODO: 2 - Replace with text that represents your app let tipTitle = "Benefits of exercising" - let tipText = "Learn how activity can promote a healthy pregnancy." - let tipView = TipView() - tipView.headerView.titleLabel.text = tipTitle - tipView.headerView.detailLabel.text = tipText - tipView.imageView.image = UIImage(named: "exercise.jpg") - tipView.customStyle = CustomStyleKey.defaultValue - listViewController.appendView(tipView, animated: false) + // TODO: 3 - Replace with an URL that reflects your app. Should be different than the original. + // swiftlint:disable:next line_length + let featuredContent = CustomFeaturedContentView(url: "https://uknowledge.uky.edu/cgi/viewcontent.cgi?article=1008&context=nutrisci_etds") + // TODO: 4 - Replace with an image that reflects your app. Should be different than the original. + featuredContent.imageView.image = UIImage(named: "exercise.jpg") + featuredContent.label.text = tipTitle + featuredContent.label.textColor = .white + listViewController.appendView(featuredContent, animated: false) } } diff --git a/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift b/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift new file mode 100644 index 0000000..314603a --- /dev/null +++ b/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift @@ -0,0 +1,44 @@ +// +// CustomFeaturedContentView.swift +// OCKSample +// +// Created by Corey Baker on 4/17/22. +// Copyright © 2022 Network Reconnaissance Lab. All rights reserved. +// + +import UIKit +import CareKit +import CareKitUI + +/// A simple subclass to take control of what CareKit already gives us. +class CustomFeaturedContentView: OCKFeaturedContentView { + var url: URL? + + // Need to override so we can become delegate when the user taps on card + override init(imageOverlayStyle: UIUserInterfaceStyle = .unspecified) { + super.init(imageOverlayStyle: imageOverlayStyle) + // Need to become a delegate so we know when view is tapped. + self.delegate = self + } + + convenience init(url: String, imageOverlayStyle: UIUserInterfaceStyle = .unspecified) { + self.init(imageOverlayStyle: imageOverlayStyle) // This calls your local init + // TODO: 1 - Need to turn the url string into a real URL using URL(string: String) + + // Need to become a delegate so we know when view is tapped. + self.delegate = self + } +} + +/// Need to conform to delegate in order to be delegated to. +extension CustomFeaturedContentView: OCKFeaturedContentViewDelegate { + + @MainActor + func didTapView(_ view: OCKFeaturedContentView) { + // When tapped open a URL. + guard let url = url else { + return + } + UIApplication.shared.open(url) + } +} From a60e60d826a601675676904a8f0cd48663b21aea Mon Sep 17 00:00:00 2001 From: Corey Baker Date: Sat, 30 Apr 2022 13:31:07 -0400 Subject: [PATCH 2/2] Use DispatchQueue instead of MainActor --- OCKSample/MainTabs/Care/CustomFeaturedContentView.swift | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift b/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift index 314603a..ff88be8 100644 --- a/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift +++ b/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift @@ -33,12 +33,13 @@ class CustomFeaturedContentView: OCKFeaturedContentView { /// Need to conform to delegate in order to be delegated to. extension CustomFeaturedContentView: OCKFeaturedContentViewDelegate { - @MainActor func didTapView(_ view: OCKFeaturedContentView) { // When tapped open a URL. guard let url = url else { return } - UIApplication.shared.open(url) + DispatchQueue.main.async { + UIApplication.shared.open(url) + } } }