Skip to content

Commit

Permalink
Add watchOS
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexCatch committed May 19, 2021
1 parent abc5d76 commit 47d0e49
Show file tree
Hide file tree
Showing 40 changed files with 1,701 additions and 15 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions Oak/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class AppDelegate: NSObject, UIApplicationDelegate {
application.registerForRemoteNotifications()

UIView.appearance(whenContainedInInstancesOf: [UIAlertController.self]).tintColor = UIColor(Color("AccentColor"))

UITableView.appearance().tableHeaderView = UIView(frame: CGRect.zero)

WatchSessionService.sharedManager.startSession()
return true
}

Expand Down
4 changes: 0 additions & 4 deletions Oak/Persistence/PersistentStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,6 @@ class RealPersistentStore: PersistentStore {
try viewContext.save()
}

deinit {
print("PersistentStore is being deallocated and it shouldnt")
}

public func toggleICloudSync(sync: Bool) {
setupContainer(sync: sync)
}
Expand Down
60 changes: 60 additions & 0 deletions Oak/Services/WatchSessionService.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// WatchSessionService.swift
// WatchOak Extension
//
// Created by Alex Catchpole on 19/05/2021.
//

import Foundation
import WatchConnectivity

class WatchSessionService: NSObject, WCSessionDelegate {
static let sharedManager = WatchSessionService()

private override init() {
super.init()
}

private let session: WCSession? = WCSession.isSupported() ? WCSession.default : nil

private var validSession: WCSession? {

// paired - the user has to have their device paired to the watch
// watchAppInstalled - the user must have your watch app installed

// Note: if the device is paired, but your watch app is not installed
// consider prompting the user to install it for a better experience

if let session = session, session.isPaired && session.isWatchAppInstalled {
return session
}
return nil
}

func startSession() {
session?.delegate = self
session?.activate()
}

func setApplicationContext(context: [String : Any]) throws {
guard let session = validSession else {
return
}

try session.updateApplicationContext(context)
}

func session(_ session: WCSession, activationDidCompleteWith activationState: WCSessionActivationState, error: Error?) {
print("activation did complete")
print(activationState.rawValue)
print(error)
}

func sessionDidBecomeInactive(_ session: WCSession) {
print("session did become inactive")
}

func sessionDidDeactivate(_ session: WCSession) {
print("session did deactivate")
}
}
8 changes: 8 additions & 0 deletions Oak/Views/Accounts/AccountsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ import SwiftlySearch
struct AccountsView: View {
@StateObject private var viewModel: AccountsViewModel = Resolver.resolve()

init() {
do {
try WatchSessionService.sharedManager.setApplicationContext(context: ["hello": "helloworld", "demo": "\(UUID().uuidString)"])
} catch let err {
print(err)
}
}

var body: some View {
NavigationView {
VStack {
Expand Down
6 changes: 0 additions & 6 deletions Oak/Views/Shared/AccountRow/AccountRowViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,6 @@ import Foundation
import SwiftUI
import Resolver

struct AccountDisplayable: Identifiable {
var id: String
var name: String
var username: String?
}

class AccountRowViewModel: Identifiable, ObservableObject {
var id: String {
get {
Expand Down
697 changes: 693 additions & 4 deletions OakOTP.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

25 changes: 25 additions & 0 deletions WatchOak Extension/AccountsView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//
// AccountsView.swift
// WatchOak Extension
//
// Created by Alex Catchpole on 19/05/2021.
//

import SwiftUI
import Resolver

struct AccountsView: View {
@StateObject private var viewModel: AccountsViewModel = Resolver.resolve()

var body: some View {
List(viewModel.accountListItemViewModels, id: \.id) { vm in
AccountListItem(viewModel: vm)
}.navigationTitle("Accounts")
}
}

struct AccountsView_Previews: PreviewProvider {
static var previews: some View {
AccountsView()
}
}
32 changes: 32 additions & 0 deletions WatchOak Extension/AccountsViewModel.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
//
// AccountsViewModel.swift
// WatchOak Extension
//
// Created by Alex Catchpole on 19/05/2021.
//

import Foundation
import SwiftUI
import Resolver

class AccountsViewModel: NSObject, AccountServiceDelegate, ObservableObject {
@Injected private var accountService: AccountService

@Published var accountListItemViewModels: [AccountListItemViewModel] = []

override init() {
super.init()
accountService.delegate = self
}

func accountsChanged(accounts: [Account]) {
self.accountListItemViewModels = accounts.map { AccountListItemViewModel(account: $0) }
}
}

extension Resolver {
static func RegisterAccountsViewModel() {
register { AccountsViewModel() }
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : "<=145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
{
"assets" : [
{
"filename" : "Circular.imageset",
"idiom" : "watch",
"role" : "circular"
},
{
"filename" : "Extra Large.imageset",
"idiom" : "watch",
"role" : "extra-large"
},
{
"filename" : "Graphic Bezel.imageset",
"idiom" : "watch",
"role" : "graphic-bezel"
},
{
"filename" : "Graphic Circular.imageset",
"idiom" : "watch",
"role" : "graphic-circular"
},
{
"filename" : "Graphic Corner.imageset",
"idiom" : "watch",
"role" : "graphic-corner"
},
{
"filename" : "Graphic Extra Large.imageset",
"idiom" : "watch",
"role" : "graphic-extra-large"
},
{
"filename" : "Graphic Large Rectangular.imageset",
"idiom" : "watch",
"role" : "graphic-large-rectangular"
},
{
"filename" : "Modular.imageset",
"idiom" : "watch",
"role" : "modular"
},
{
"filename" : "Utilitarian.imageset",
"idiom" : "watch",
"role" : "utilitarian"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : "<=145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : "<=145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">145"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"images" : [
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">161"
},
{
"idiom" : "watch",
"scale" : "2x",
"screen-width" : ">183"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit 47d0e49

Please sign in to comment.