Skip to content

Commit

Permalink
PVVM
Browse files Browse the repository at this point in the history
  • Loading branch information
ivalkou committed Feb 2, 2021
1 parent f42067d commit 00dc7c4
Show file tree
Hide file tree
Showing 117 changed files with 3,371 additions and 56 deletions.
590 changes: 575 additions & 15 deletions FreeAPS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"object": {
"pins": [
{
"package": "Alamofire",
"repositoryURL": "https://github.com/Alamofire/Alamofire.git",
"state": {
"branch": null,
"revision": "eaf6e622dd41b07b251d8f01752eab31bc811493",
"version": "5.4.1"
}
},
{
"package": "Moya",
"repositoryURL": "https://github.com/Moya/Moya",
"state": {
"branch": null,
"revision": "b3e5a233e0d85fd4d69f561c80988590859c7dee",
"version": "14.0.0"
}
},
{
"package": "ReactiveSwift",
"repositoryURL": "https://github.com/Moya/ReactiveSwift.git",
"state": {
"branch": null,
"revision": "f195d82bb30e412e70446e2b4a77e1b514099e88",
"version": "6.1.0"
}
},
{
"package": "RxSwift",
"repositoryURL": "https://github.com/ReactiveX/RxSwift.git",
"state": {
"branch": null,
"revision": "002d325b0bdee94e7882e1114af5ff4fe1e96afa",
"version": "5.1.1"
}
},
{
"package": "Swinject",
"repositoryURL": "https://github.com/Swinject/Swinject",
"state": {
"branch": null,
"revision": "8a76d2c74bafbb455763487cc6a08e91bad1f78b",
"version": "2.7.1"
}
}
]
},
"version": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,90 @@
<key>orderHint</key>
<integer>0</integer>
</dict>
<key>ReactiveSwift (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>8</integer>
</dict>
<key>ReactiveSwift (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>9</integer>
</dict>
<key>ReactiveSwift (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>7</integer>
</dict>
<key>ReactiveSwift-UIExamples (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>5</integer>
</dict>
<key>ReactiveSwift-UIExamples (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>6</integer>
</dict>
<key>ReactiveSwift-UIExamples (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>4</integer>
</dict>
<key>Rx (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>11</integer>
</dict>
<key>Rx (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>12</integer>
</dict>
<key>Rx (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>10</integer>
</dict>
<key>Sample-iOS (Playground) 1.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>2</integer>
</dict>
<key>Sample-iOS (Playground) 2.xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>3</integer>
</dict>
<key>Sample-iOS (Playground).xcscheme</key>
<dict>
<key>isShown</key>
<false/>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
</dict>
</plist>
24 changes: 0 additions & 24 deletions FreeAPS/ContentView.swift

This file was deleted.

17 changes: 0 additions & 17 deletions FreeAPS/FreeAPSApp.swift

This file was deleted.

File renamed without changes.
10 changes: 10 additions & 0 deletions FreeAPS/Resources/FreeAPS.entitlements
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.developer.applesignin</key>
<array>
<string>Default</string>
</array>
</dict>
</plist>
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
26 changes: 26 additions & 0 deletions FreeAPS/Sources/Application/FreeAPSApp.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//
// FreeAPSApp.swift
// FreeAPS
//
// Created by Ivan Valkou on 12.01.2021.
//

import SwiftUI
import Swinject

@main
struct FreeAPSApp: App {
private let resolver = Container(defaultObjectScope: .container) { container in
UIContainer.register(container: container)
StorageContainer.register(container: container)
NetworkContainer.register(container: container)
SecurityContainer.register(container: container)
}.synchronize()

var body: some Scene {
resolver.resolve(AppearanceManager.self)!.setupGlobalAppearance()
return WindowGroup {
Main.Builder(resolver: resolver).buildView()
}
}
}
9 changes: 9 additions & 0 deletions FreeAPS/Sources/Containers/NetworkContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import Swinject
import UIKit

enum NetworkContainer {
static func register(container: Container) {
container.register(NetworkManager.self) { _ in BaseNetworkManager() }
container.register(AuthorizationManager.self) { r in BaseAuthorizationManager(resolver: r) }
}
}
7 changes: 7 additions & 0 deletions FreeAPS/Sources/Containers/SecurityContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Swinject

enum SecurityContainer {
static func register(container: Container) {
container.register(UnlockManager.self) { _ in BaseUnlockManager() }
}
}
23 changes: 23 additions & 0 deletions FreeAPS/Sources/Containers/StorageContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Foundation
import Swinject

enum StorageContainer {
static func register(container: Container) {
container.register(FileManager.self) { _ in
Foundation.FileManager.default
}

container.register(Keychain.self) { _ in BaseKeychain() }

container.register(IsDrinkImageFileStorage.self) { r in BaseImageFileStorage(resolver: r, name: "IsDrink")
}
container
.register(DrinkTypeImageFileStorage.self) { r in BaseImageFileStorage(resolver: r, name: "DrinkType")
}
}
}

protocol IsDrinkImageFileStorage: ImageFileStorage {}
protocol DrinkTypeImageFileStorage: ImageFileStorage {}
extension BaseImageFileStorage: IsDrinkImageFileStorage {}
extension BaseImageFileStorage: DrinkTypeImageFileStorage {}
8 changes: 8 additions & 0 deletions FreeAPS/Sources/Containers/UIContainer.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Swinject

enum UIContainer {
static func register(container: Container) {
container.register(AppearanceManager.self) { _ in BaseAppearanceManager() }
container.register(Router.self) { r in BaseRouter(resolver: r) }
}
}
9 changes: 9 additions & 0 deletions FreeAPS/Sources/Helpers/CheckBox.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import SwiftUI

struct CheckBox: View {
@Binding var isChecked: Bool

var body: some View {
Image(systemName: isChecked ? "checkmark.circle.fill" : "circle")
}
}
82 changes: 82 additions & 0 deletions FreeAPS/Sources/Helpers/FlowStack.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import SwiftUI

@available(iOS 13.0, OSX 10.15, tvOS 13.0, watchOS 6.0, *)
struct FlowStack<Content>: View where Content: View {
// The number of columns we want to display
var columns: Int
// The total number of items in the stack
var numItems: Int
// The alignment of our columns in the last row
// when they don't fill all the column slots
var alignment: HorizontalAlignment

let content: (Int, CGFloat) -> Content

private func width(for size: CGSize) -> CGFloat {
size.width / CGFloat(columns)
}

private func index(forRow row: Int, column: Int) -> Int {
(row * columns) + column
}

private var lastRowColumns: Int { numItems % columns }

private var rows: Int { numItems / columns }

init(
columns: Int,
numItems: Int,
alignment: HorizontalAlignment?,
@ViewBuilder content: @escaping (Int, CGFloat) -> Content
) {
self.content = content
self.columns = columns
self.numItems = numItems
self.alignment = alignment ?? HorizontalAlignment.leading
}

var body: some View {
// A GeometryReader is required to size items in the scroll view
GeometryReader { geometry in

// Assume a vertical scrolling orientation for the grid
ScrollView(Axis.Set.vertical) {
// VStacks are our rows
VStack(alignment: self.alignment, spacing: 0) {
ForEach(0 ..< self.rows) { row in

// HStacks are our columns
HStack(spacing: 0) {
ForEach(0 ..< self.columns) { column in
self.content(
// Pass the index to the content
self.index(forRow: row, column: column),
// Pass the column width to the content
self.width(for: geometry.size)
)
// Size the content to frame to fill the column
.frame(width: self.width(for: geometry.size))
}
}
}

// Last row
// HStacks are our columns
HStack(spacing: 0) {
ForEach(0 ..< self.lastRowColumns) { column in
self.content(
// Pass the index to the content
self.index(forRow: self.rows, column: column),
// Pass the column width to the content
self.width(for: geometry.size)
)
// Size the content to frame to fill the column
.frame(width: self.width(for: geometry.size))
}
}
}
}
}
}
}
17 changes: 17 additions & 0 deletions FreeAPS/Sources/Helpers/Formatters.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Foundation
import HealthKit

enum Formatters {
static func percent(for number: Double) -> String {
let formater = NumberFormatter()
formater.numberStyle = .percent
return formater.string(for: number)!
}

static func timeFor(minutes: Int) -> String {
let formater = DateComponentsFormatter()
formater.unitsStyle = .abbreviated
formater.allowedUnits = [.hour, .minute]
return formater.string(from: TimeInterval(minutes * 60))!
}
}
Loading

0 comments on commit 00dc7c4

Please sign in to comment.