Skip to content

Commit

Permalink
synced up the widget code with the code from Arc App
Browse files Browse the repository at this point in the history
  • Loading branch information
sobri909 committed Dec 14, 2023
1 parent 77426ab commit b51113b
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 40 deletions.
34 changes: 19 additions & 15 deletions Arc Mini.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
objects = {

/* Begin PBXBuildFile section */
C901630D2B2AC502009609BE /* Icons.swift in Sources */ = {isa = PBXBuildFile; fileRef = C901630C2B2AC502009609BE /* Icons.swift */; };
C901630E2B2AC502009609BE /* Icons.swift in Sources */ = {isa = PBXBuildFile; fileRef = C901630C2B2AC502009609BE /* Icons.swift */; };
C901630F2B2AC502009609BE /* Icons.swift in Sources */ = {isa = PBXBuildFile; fileRef = C901630C2B2AC502009609BE /* Icons.swift */; };
C90163102B2AC551009609BE /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = C95E0E20241797D8008418A1 /* Colors.swift */; };
C90163112B2AC551009609BE /* Colors.swift in Sources */ = {isa = PBXBuildFile; fileRef = C95E0E20241797D8008418A1 /* Colors.swift */; };
C90C27372439DCCC00A36251 /* NavBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90C27362439DCCC00A36251 /* NavBar.swift */; };
C90D78542428FBA2004ABFD0 /* PathEditView.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90D78532428FBA2004ABFD0 /* PathEditView.swift */; };
C90D78682428FFCE004ABFD0 /* PlaceCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = C90D78632428FFCE004ABFD0 /* PlaceCache.swift */; };
Expand Down Expand Up @@ -147,6 +152,7 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
C901630C2B2AC502009609BE /* Icons.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Icons.swift; sourceTree = "<group>"; };
C90C27362439DCCC00A36251 /* NavBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NavBar.swift; sourceTree = "<group>"; };
C90D78532428FBA2004ABFD0 /* PathEditView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PathEditView.swift; sourceTree = "<group>"; };
C90D78632428FFCE004ABFD0 /* PlaceCache.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaceCache.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -326,9 +332,11 @@
C9120BD4250BBDD80063A2B7 /* CurrentItemWidget */ = {
isa = PBXGroup;
children = (
C9B38CF92512620000C997F8 /* Bits */,
C9E072E8251115B2006C6BFC /* CurrentItemWidgetExtension.entitlements */,
C9120BD5250BBDD80063A2B7 /* CurrentItemWidget.swift */,
C9E072E62510F181006C6BFC /* MiniStore.swift */,
C9120BD8250BBDDA0063A2B7 /* Assets.xcassets */,
C9120BDA250BBDDA0063A2B7 /* Info.plist */,
);
path = CurrentItemWidget;
sourceTree = "<group>";
Expand Down Expand Up @@ -443,6 +451,7 @@
children = (
C9822A88240CF8D8006B70F4 /* Assets.xcassets */,
C95E0E20241797D8008418A1 /* Colors.swift */,
C901630C2B2AC502009609BE /* Icons.swift */,
);
path = Design;
sourceTree = "<group>";
Expand Down Expand Up @@ -523,16 +532,6 @@
path = Foursquare;
sourceTree = "<group>";
};
C9B38CF92512620000C997F8 /* Bits */ = {
isa = PBXGroup;
children = (
C9E072E8251115B2006C6BFC /* CurrentItemWidgetExtension.entitlements */,
C9120BDA250BBDDA0063A2B7 /* Info.plist */,
C9120BD8250BBDDA0063A2B7 /* Assets.xcassets */,
);
path = Bits;
sourceTree = "<group>";
};
C9B38CFD2512621400C997F8 /* Bits */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -782,7 +781,9 @@
buildActionMask = 2147483647;
files = (
C9E072E72510F181006C6BFC /* MiniStore.swift in Sources */,
C90163102B2AC551009609BE /* Colors.swift in Sources */,
C9120BD6250BBDD80063A2B7 /* CurrentItemWidget.swift in Sources */,
C901630F2B2AC502009609BE /* Icons.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -830,6 +831,7 @@
C937EE2F24546A2A009D1593 /* ShareSheet.swift in Sources */,
C983603024969AFE007940F6 /* HeadlessView.swift in Sources */,
C953392B24127CF30005E98F /* TimelineDayView.swift in Sources */,
C901630D2B2AC502009609BE /* Icons.swift in Sources */,
C99F5EBF242A371C00E172AE /* Scraps.swift in Sources */,
C9C827AF243C830500F3199B /* DispatchQueue.swift in Sources */,
C99F5EC9242A4EFA00E172AE /* Settings.swift in Sources */,
Expand Down Expand Up @@ -876,6 +878,8 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
C901630E2B2AC502009609BE /* Icons.swift in Sources */,
C90163112B2AC551009609BE /* Colors.swift in Sources */,
C9C045CD24A891B300C1A99C /* RecordersWidget.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -912,11 +916,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = CurrentItemWidget/Bits/CurrentItemWidgetExtension.entitlements;
CODE_SIGN_ENTITLEMENTS = CurrentItemWidget/CurrentItemWidgetExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = U5N7VG8DUG;
INFOPLIST_FILE = CurrentItemWidget/Bits/Info.plist;
INFOPLIST_FILE = CurrentItemWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.5;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand All @@ -937,11 +941,11 @@
buildSettings = {
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground;
CODE_SIGN_ENTITLEMENTS = CurrentItemWidget/Bits/CurrentItemWidgetExtension.entitlements;
CODE_SIGN_ENTITLEMENTS = CurrentItemWidget/CurrentItemWidgetExtension.entitlements;
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 32;
DEVELOPMENT_TEAM = U5N7VG8DUG;
INFOPLIST_FILE = CurrentItemWidget/Bits/Info.plist;
INFOPLIST_FILE = CurrentItemWidget/Info.plist;
IPHONEOS_DEPLOYMENT_TARGET = 16.5;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
Expand Down
93 changes: 93 additions & 0 deletions Arc Mini/Design/Icons.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
//
// Icons.swift
// Arc
//
// Created by Matt Greenfield on 4/2/19.
// Copyright © 2019 Big Paua. All rights reserved.
//

import UIKit
import LocoKit
import SwiftUI

extension Image {
static func icon(for activityType: ActivityTypeName, size: Int) -> Image {
let filename = activityType.iconFilename + String(size)
return Image(filename).renderingMode(.template)
}
}

extension UIImage {
static func icon(for activityType: ActivityTypeName, size: Int) -> UIImage {
let filename = activityType.iconFilename + String(size)
return UIImage(named: filename)!.withRenderingMode(.alwaysTemplate)
}
}

extension UIImageView {
static func icon(for activityType: ActivityTypeName, size: Int, tintColor: UIColor? = nil) -> UIImageView {
let image = UIImage.icon(for: activityType, size: size)
let view = UIImageView(image: image)
view.tintColor = tintColor ?? UIColor.color(for: activityType)
return view
}
}

extension ActivityTypeName {
var iconFilename: String {
switch self {
case .walking:
return "walkingIcon"
case .running:
return "runningIcon"
case .cycling:
return "cyclingIcon"
case .car, .unknown:
return "carIcon"
case .taxi:
return "taxiIcon"
case .motorcycle:
return "motorcycleIcon"
case .train, .metro:
return "trainIcon"
case .tram, .cableCar, .funicular, .chairlift, .skiLift:
return "tramIcon"
case .airplane:
return "airplaneIcon"
case .bus:
return "busIcon"
case .boat:
return "boatIcon"
case .stationary, .bogus:
return "defaultPlaceIcon"
case .tractor:
return "tractorIcon"
case .tuktuk, .songthaew:
return "tuktukIcon"
case .skateboarding:
return "skateboardingIcon"
case .inlineSkating:
return "inlineSkatingIcon"
case .snowboarding:
return "snowboardingIcon"
case .skiing:
return "skiingIcon"
case .horseback:
return "horsebackIcon"
case .scooter:
return "scooterIcon"
case .swimming:
return "swimmingIcon"
case .golf:
return "golfIcon"
case .wheelchair:
return "wheelchairIcon"
case .rowing, .kayaking:
return "rowingIcon"
case .surfing:
return "surfingIcon"
case .hiking:
return "hikingIcon"
}
}
}
129 changes: 104 additions & 25 deletions CurrentItemWidget/CurrentItemWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ struct CurrentItemWidgetEntryView : View {

let store = MiniStore()
let appGroup = AppGroup(appName: .arcMini, suiteName: "group.ArcApp", readOnly: true)

static let dateFormatter: DateFormatter = {
let formatter = DateFormatter()
formatter.dateStyle = .none
Expand All @@ -59,19 +59,36 @@ struct CurrentItemWidgetEntryView : View {
}

var body: some View {
switch family {
case .systemSmall:
bodySmall
.widgetBackground(Color.clear)
case .accessoryRectangular:
bodyAccessoryRectangular
.widgetBackground(Color.clear)
default:
fatalError()
}
}

var bodySmall: some View {
ZStack(alignment: .top) {
if let currentItem = currentItem, let dateRange = currentItem.dateRange {
VStack(alignment: .leading) {
if let currentItemTitle = currentItemTitle {
Text(currentItemTitle)
.font(.system(size: 14, weight: .semibold))
HStack(alignment: .top) {
VStack(alignment: .leading) {
if let currentItemTitle = currentItemTitle {
Text(currentItemTitle)
.font(.system(size: 14, weight: .semibold))
}
Text(CurrentItemWidgetEntryView.dateFormatter.string(from: dateRange.start))
.font(.system(size: 26, weight: .regular))
Text(dateRange.start, style: .relative)
.font(.system(size: 10, weight: .regular))
.opacity(0.6)
Spacer()
}
Text(CurrentItemWidgetEntryView.dateFormatter.string(from: dateRange.start))
.font(.system(size: 26, weight: .regular))
Text(dateRange.start, style: .relative)
.font(.system(size: 10, weight: .regular))
.opacity(0.6)
Spacer()
itemIcon.frame(width: 24, height: 24)
}

} else {
Expand All @@ -82,10 +99,10 @@ struct CurrentItemWidgetEntryView : View {
if appGroup.currentRecorder == nil {
HStack {
Spacer()
Image("warningIcon20").renderingMode(.template).foregroundColor(Color.red)
Image("warningIcon20").renderingMode(.template).foregroundColor(.red)
}
}

VStack {
Spacer()
HStack {
Expand All @@ -95,16 +112,18 @@ struct CurrentItemWidgetEntryView : View {
Spacer()
HStack(spacing: 3) {
ForEach(appGroup.apps.values.sorted { $0.appName.sortIndex < $1.appName.sortIndex }, id: \.updated) { appState in
if appState.isAlive {
Text("")
.font(.system(size: 8, weight: .regular))
.foregroundColor(Color.green)
.opacity(0.4)
} else {
Text("")
.font(.system(size: 10, weight: .regular))
.foregroundColor(Color.red)
.opacity(0.4)
if appState.updated.age < .oneMonth {
if appState.isAlive {
Text("")
.font(.system(size: 8, weight: .regular))
.foregroundColor(Color.green)
.opacity(0.4)
} else {
Text("")
.font(.system(size: 10, weight: .regular))
.foregroundColor(Color.red)
.opacity(0.4)
}
}
}
}
Expand All @@ -114,19 +133,79 @@ struct CurrentItemWidgetEntryView : View {
.padding([.top, .leading, .trailing], 16)
.padding([.bottom], 12)
}


var bodyAccessoryRectangular: some View {
ZStack(alignment: .top) {
if let currentItem = currentItem, let dateRange = currentItem.dateRange {
HStack(alignment: .center) {
VStack(alignment: .leading, spacing: 4) {
if let currentItemTitle = currentItemTitle {
HStack(spacing: 2) {
itemIcon
.frame(width: 16, height: 16)
Text(currentItemTitle)
.lineLimit(1)
.font(.system(size: 14, weight: .regular))
}
}
Text(CurrentItemWidgetEntryView.dateFormatter.string(from: dateRange.start))
.font(.system(size: 14, weight: .semibold))
Text(dateRange.start, style: .relative)
.font(.system(size: 14, weight: .regular))
.opacity(0.8)
}
}

} else {
HStack(spacing: 2) {
Image(systemName: "exclamationmark.triangle.fill")
.frame(width: 16, height: 16)
Text("No current item!")
.font(.system(size: 14, weight: .semibold))
}
}
}
.padding(2)
}

var itemIcon: some View {
if let path = currentItem as? LocoKit.Path, let activityType = path.modeActivityType {
return AnyView(
Image.icon(for: activityType, size: 24)
.resizable()
.renderingMode(.template)
.foregroundColor(Color(uiColor: UIColor.color(for: activityType)))
)
}
return AnyView(EmptyView())
}

}

@main
struct CurrentItemWidget: Widget {
let kind: String = "CurrentItemWidget"

// TODO: should remove the contentMarginsDisabled() eventually
// it's a workaround for the automatic margins iOS 17 adds
var body: some WidgetConfiguration {
StaticConfiguration<CurrentItemWidgetEntryView>(kind: kind, provider: Provider()) { entry in
CurrentItemWidgetEntryView(entry: entry)
}
.configurationDisplayName("Arc Current Item")
.description("The current Arc timeline item.")
.supportedFamilies([.systemSmall])
.description("The current timeline item.")
.supportedFamilies([.systemSmall, .accessoryRectangular])
.contentMarginsDisabled()
}
}

// workaround for iOS 17's required new background thing while still supporting iOS 16
extension View {
func widgetBackground(_ backgroundView: some View) -> some View {
if #available(iOSApplicationExtension 17.0, *) {
return containerBackground(for: .widget) { backgroundView }
} else {
return background(backgroundView)
}
}
}
File renamed without changes.

0 comments on commit b51113b

Please sign in to comment.