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..ff88be8 --- /dev/null +++ b/OCKSample/MainTabs/Care/CustomFeaturedContentView.swift @@ -0,0 +1,45 @@ +// +// 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 { + + func didTapView(_ view: OCKFeaturedContentView) { + // When tapped open a URL. + guard let url = url else { + return + } + DispatchQueue.main.async { + UIApplication.shared.open(url) + } + } +}