Skip to content

Commit

Permalink
[Main] - New Updates ✨
Browse files Browse the repository at this point in the history
  • Loading branch information
MaatheusGois committed Feb 3, 2024
1 parent f14502b commit 08832c4
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 27 deletions.
Binary file not shown.
6 changes: 2 additions & 4 deletions DuoDemoApp/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,10 @@ extension ContentView {
}

func activityView(_ activity: Activity<DuoDemoAppAttributes>) -> some View {
let courierName = activity.contentState.courierName
let deliveryTime = activity.contentState.percentage

return HStack(alignment: .center) {
Text(courierName)
Text(verbatim: "Update")
Text("\(activity.contentState.progressString)% -")
Text(activity.contentState.initialTime, style: .timer)
Text("update")
.font(.headline)
.foregroundColor(.green)
Expand Down
14 changes: 10 additions & 4 deletions DuoDemoApp/Helpers/Activity/ActivityManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,20 @@ import SwiftUI

class ActivityManager: ObservableObject {
@Published var activities = Activity<DuoDemoAppAttributes>.activities
private var initalDate = Date()

func createActivity() {
guard NotificationManager.status == .enable else {
// Handle error
return
}

let attributes = DuoDemoAppAttributes(numberOfGroceyItems: 12)
let contentState = DuoDemoAppAttributes.LiveDeliveryData(courierName: "", percentage: 0.3)
let attributes = DuoDemoAppAttributes()
let contentState = DuoDemoAppAttributes.LiveDeliveryData(
currentLesson: 3,
numberOfLessons: 12,
initialTime: initalDate
)
do {
_ = try Activity<DuoDemoAppAttributes>.request(
attributes: attributes,
Expand All @@ -33,8 +38,9 @@ class ActivityManager: ObservableObject {
func update(activity: Activity<DuoDemoAppAttributes>) {
Task {
let updatedStatus = DuoDemoAppAttributes.LiveDeliveryData(
courierName: "",
percentage: 0.5
currentLesson: 6,
numberOfLessons: 12,
initialTime: initalDate
)
await activity.update(using: updatedStatus)
}
Expand Down
22 changes: 19 additions & 3 deletions DuoDemoApp/Helpers/Model/DuoDemoAppAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,26 @@ struct DuoDemoAppAttributes: ActivityAttributes, Identifiable {
public typealias LiveDeliveryData = ContentState

public struct ContentState: Codable, Hashable {
var courierName: String
var percentage: CGFloat
var currentLesson: CGFloat
var numberOfLessons: CGFloat
var initialTime: Date

var progress: CGFloat {
currentLesson / numberOfLessons
}

var progressString: String {
String(Int(currentLesson / numberOfLessons * 100))
}

var currentLessonString: String {
String(Int(currentLesson))
}

var numberOfLessonsString: String {
String(Int(numberOfLessons))
}
}

var numberOfGroceyItems: Int
var id = UUID()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"images" : [
{
"filename" : "duo-icon-.pdf",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
},
"properties" : {
"preserves-vector-representation" : true
}
}
Binary file not shown.
32 changes: 16 additions & 16 deletions DuoTrackWidget/DuoTrackWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,35 +58,36 @@ struct DuoDemoApp: Widget {
func dynamicIslandExpandedLeadingView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
VStack {
Label {
Text("\(context.attributes.numberOfGroceyItems)")
Text("\(context.state.numberOfLessonsString)")
.font(.title2)
} icon: {
Image("duo-icon")
Image("duo-icon-full")
}
Text("items")
Text("steps")
.font(.title2)
}
}

func dynamicIslandExpandedTrailingView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
Label {
Text(verbatim: "Text")
Text(context.state.initialTime, style: .timer)
.multilineTextAlignment(.trailing)
.frame(width: 50)
.monospacedDigit()
} icon: {
Image(systemName: "timer")
.foregroundColor(.green)
Image("duo-icon-full")
.resizable()
.scaledToFit()
}
.font(.title2)
}

func dynamicIslandExpandedBottomView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
Label("Call courier", systemImage: "phone")
Label("", systemImage: "")
}

func dynamicIslandExpandedCenterView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
Text("\(context.state.courierName) is on the way!")
Text("")
.lineLimit(1)
.font(.caption)
}
Expand All @@ -96,9 +97,9 @@ struct DuoDemoApp: Widget {
func compactLeadingView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
VStack {
Label {
Text("\(context.attributes.numberOfGroceyItems) items")
Text("\(context.state.currentLessonString)/\(context.state.numberOfLessonsString)")
} icon: {
Image("duo-icon")
Image("duo-icon-full")
.resizable()
.scaledToFit()
}
Expand All @@ -107,16 +108,15 @@ struct DuoDemoApp: Widget {
}

func compactTrailingView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
Text(verbatim: "Trailing")
Text(context.state.initialTime, style: .timer)
.multilineTextAlignment(.center)
.frame(width: 40)
.font(.caption2)
}

func minimalView(context: ActivityViewContext<DuoDemoAppAttributes>) -> some View {
VStack(alignment: .center) {
Image(systemName: "timer")
Text(verbatim: "MinimalView")
Text(context.state.initialTime, style: .timer)
.multilineTextAlignment(.center)
.monospacedDigit()
.font(.caption2)
Expand All @@ -135,7 +135,7 @@ struct LockScreenView: View {
HStack {
VStack(alignment: .leading) {
HStack {
ProgressBar(progress: context.state.percentage)
ProgressBar(progress: context.state.progress)
.frame(minHeight: 16)
.padding(.bottom, 6)
}
Expand All @@ -146,8 +146,8 @@ struct LockScreenView: View {
.font(.title3)
.fontWeight(.bold)

Text("It's been \(context.attributes.numberOfGroceyItems) since you started.")
.font(.headline)
Text("It's been \(context.state.initialTime, style: .timer) since you started.")
.font(.subheadline)
.fontWeight(.thin)
}
Spacer()
Expand Down

0 comments on commit 08832c4

Please sign in to comment.