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

feat: add CustomFeaturedContentView card #2

Open
wants to merge 2 commits 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
4 changes: 4 additions & 0 deletions OCKSample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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 */; };
Expand Down Expand Up @@ -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 = "<group>"; };
70123068280830A1003F5ECE /* Consent.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Consent.swift; sourceTree = "<group>"; };
701230D5280CCFC4003F5ECE /* CustomFeaturedContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomFeaturedContentView.swift; sourceTree = "<group>"; };
70202EC9280746E900CF73FB /* ResearchKit.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = ResearchKit.xcodeproj; path = ResearchKit/ResearchKit.xcodeproj; sourceTree = "<group>"; };
70202ED52807529900CF73FB /* Surveys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Surveys.swift; sourceTree = "<group>"; };
70308885258273D400FFABB6 /* LoginViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LoginViewModel.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -343,6 +345,7 @@
7036E4C3256E0A48006E9A3C /* CareView.swift */,
70F03ABA2789071400E5AFB4 /* CareViewModel.swift */,
E7C37848228F887800E982D8 /* TipView.swift */,
701230D5280CCFC4003F5ECE /* CustomFeaturedContentView.swift */,
);
path = Care;
sourceTree = "<group>";
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions OCKSample/MainTabs/Care/CareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
45 changes: 45 additions & 0 deletions OCKSample/MainTabs/Care/CustomFeaturedContentView.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}