-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: create watchOS version closes #6
- Loading branch information
Showing
22 changed files
with
924 additions
and
9 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1600" | ||
version = "1.7"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES" | ||
buildArchitectures = "Automatic"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A0AC531C2CA1DC9900872903" | ||
BuildableName = "HaxWatch.app" | ||
BlueprintName = "HaxWatch" | ||
ReferencedContainer = "container:Hax.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A064ABA828D3ADA500572ADD" | ||
BuildableName = "Hax.app" | ||
BlueprintName = "Hax" | ||
ReferencedContainer = "container:Hax.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
shouldAutocreateTestPlan = "YES"> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A0AC531C2CA1DC9900872903" | ||
BuildableName = "HaxWatch.app" | ||
BlueprintName = "HaxWatch" | ||
ReferencedContainer = "container:Hax.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<BuildableProductRunnable | ||
runnableDebuggingMode = "0"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "A0AC531C2CA1DC9900872903" | ||
BuildableName = "HaxWatch.app" | ||
BlueprintName = "HaxWatch" | ||
ReferencedContainer = "container:Hax.xcodeproj"> | ||
</BuildableReference> | ||
</BuildableProductRunnable> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// | ||
// HaxWCSessionDelegate.swift | ||
// Hax | ||
// | ||
// Created by Luis Fariña on 30/9/24. | ||
// | ||
|
||
import WatchConnectivity | ||
|
||
final class HaxWCSessionDelegate: NSObject { | ||
|
||
// MARK: Properties | ||
|
||
var didReceiveApplicationContext: ( | ||
@Sendable (_ applicationContext: [String: Any]) -> Void | ||
)? | ||
|
||
// MARK: Initialization | ||
|
||
override init() { | ||
super.init() | ||
|
||
guard WCSession.isSupported() else { | ||
return | ||
} | ||
|
||
let session = WCSession.default | ||
session.delegate = self | ||
session.activate() | ||
} | ||
} | ||
|
||
// MARK: - WCSessionDelegate | ||
|
||
extension HaxWCSessionDelegate: WCSessionDelegate { | ||
|
||
func session( | ||
_ session: WCSession, | ||
activationDidCompleteWith activationState: WCSessionActivationState, | ||
error: (any Error)? | ||
) { | ||
// Do nothing | ||
} | ||
|
||
#if !os(watchOS) | ||
func sessionDidBecomeInactive(_ session: WCSession) { | ||
// Do nothing | ||
} | ||
|
||
func sessionDidDeactivate(_ session: WCSession) { | ||
// Do nothing | ||
} | ||
#endif | ||
|
||
func session( | ||
_ session: WCSession, | ||
didReceiveApplicationContext applicationContext: [String: Any] | ||
) { | ||
didReceiveApplicationContext?(applicationContext) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// HaxWatchApp.swift | ||
// HaxWatch | ||
// | ||
// Created by Luis Fariña on 23/9/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
@main | ||
struct HaxWatchApp: App { | ||
|
||
// MARK: Properties | ||
|
||
private let haxWCSessionDelegate = HaxWCSessionDelegate() | ||
|
||
// MARK: Body | ||
|
||
var body: some Scene { | ||
WindowGroup { | ||
MainView() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// ItemRowView.swift | ||
// HaxWatch | ||
// | ||
// Created by Luis Fariña on 25/9/24. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ItemRowView: View { | ||
|
||
// MARK: Properties | ||
|
||
let model: ItemRowViewModel | ||
|
||
// MARK: Body | ||
|
||
var body: some View { | ||
VStack(alignment: .leading, spacing: 5) { | ||
HStack(spacing: 3) { | ||
if model.shouldDisplayIndex { | ||
Text(verbatim: "#\(model.index)") | ||
Text(verbatim: "⸱") | ||
} | ||
if model.shouldDisplayScore, | ||
let score = model.item.score { | ||
Text( | ||
"\(Image(systemName: "arrow.up"))\(score)", | ||
tableName: "" | ||
) | ||
Text(verbatim: "⸱") | ||
} | ||
if let elapsedTimeString = model.item.elapsedTimeString { | ||
Text(elapsedTimeString) | ||
} | ||
} | ||
.foregroundColor(.secondary) | ||
.lineLimit(1) | ||
if let title = model.item.title { | ||
Text(title) | ||
} | ||
Spacer() | ||
if let urlSimpleString = model.item.urlSimpleString { | ||
Text(urlSimpleString) | ||
.foregroundColor(.secondary) | ||
.lineLimit(1) | ||
} | ||
} | ||
} | ||
} | ||
|
||
// MARK: - Previews | ||
|
||
#Preview { | ||
ItemRowView( | ||
model: ItemRowViewModel( | ||
in: .feed, | ||
index: 42, | ||
item: .example | ||
) | ||
) | ||
} |
52 changes: 52 additions & 0 deletions
52
HaxWatch/Presentation/Screens/View Models/FeedViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// FeedViewModel.swift | ||
// HaxWatch | ||
// | ||
// Created by Luis Fariña on 24/9/24. | ||
// | ||
|
||
import Foundation | ||
|
||
@MainActor | ||
@Observable | ||
class FeedViewModel { | ||
|
||
// MARK: Types | ||
|
||
enum State { | ||
|
||
// MARK: Cases | ||
|
||
case error(Error) | ||
case loaded(items: [Item]) | ||
case loading | ||
} | ||
|
||
// MARK: Properties | ||
|
||
let feed: Feed | ||
var state = State.loading | ||
|
||
// MARK: Initialization | ||
|
||
init(feed: Feed) { | ||
self.feed = feed | ||
} | ||
|
||
// MARK: Methods | ||
|
||
func onAppear() async { | ||
do { | ||
state = .loaded( | ||
items: try await HackerNewsService.shared.items( | ||
in: feed, | ||
page: 1, | ||
pageSize: 10, | ||
resetCache: true | ||
) | ||
) | ||
} catch { | ||
state = .error(error) | ||
} | ||
} | ||
} |
Oops, something went wrong.