-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,491 additions
and
28 deletions.
There are no files selected for viewing
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
Binary file modified
BIN
+73.6 KB
(300%)
...deproj/project.xcworkspace/xcuserdata/ludovico.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
6 changes: 6 additions & 0 deletions
6
...st contact.xcodeproj/xcuserdata/ludovico.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist
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,6 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Bucket | ||
uuid = "5845566B-65CB-4070-B27C-8C4B040B8DAF" | ||
type = "1" | ||
version = "2.0"> | ||
</Bucket> |
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,49 @@ | ||
// | ||
// AppData.swift | ||
// First contact | ||
// | ||
// Created by Ludovic Ollagnier on 30/05/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
@Observable | ||
class AppData { | ||
|
||
var showDivider: Bool | ||
var applications: [Application] | ||
|
||
var installedApp: Set<Application> | ||
|
||
var todayPath: [Application] | ||
|
||
init(applications: [Application]) { | ||
self.applications = applications | ||
installedApp = [] | ||
showDivider = true | ||
todayPath = [] | ||
} | ||
|
||
func install(app: Application) { | ||
installedApp.insert(app) | ||
} | ||
|
||
func isAppInstalled(_ app: Application) -> Bool { | ||
installedApp.contains(app) | ||
} | ||
} | ||
|
||
// Old way, before iOS 17 | ||
//class AppData: ObservableObject { | ||
// | ||
// @Published var showDivider: Bool | ||
// @Published var applications: [Application] | ||
// | ||
// init(applications: [Application]) { | ||
// self.applications = applications | ||
// showDivider = true | ||
// | ||
//// Alternative à Published | ||
//// objectWillChange.send() | ||
// } | ||
//} |
27 changes: 27 additions & 0 deletions
27
Projects/First contact/First contact/Models/Application.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,27 @@ | ||
// | ||
// Application.swift | ||
// First contact | ||
// | ||
// Created by Ludovic Ollagnier on 30/05/2024. | ||
// | ||
|
||
import Foundation | ||
|
||
struct Application: Identifiable, Hashable { | ||
|
||
let id = UUID() | ||
let name: String | ||
let appIconName: String | ||
let developerName: String | ||
|
||
let price: Double? | ||
let hasInAppPurchase: Bool | ||
|
||
static var demoApps: [Application] { | ||
[Application(name: "Duolingo", appIconName: "eyes", developerName: "Duolingo", price: nil, hasInAppPurchase: true), | ||
Application(name: "Procreate Pocket", appIconName: "pencil.and.scribble", developerName: "Savage Interactive", price: 6.99, hasInAppPurchase: false), | ||
Application(name: "Filca - SLR Film Camera", appIconName: "camera", developerName: "Cheol Kim", price: 1.99, hasInAppPurchase: true), | ||
Application(name: "Monopoly Go!", appIconName: "banknote", developerName: "Scopely", price: nil, hasInAppPurchase: true) | ||
] | ||
} | ||
} |
File renamed without changes.
44 changes: 44 additions & 0 deletions
44
Projects/First contact/First contact/Views/AppCellView.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,44 @@ | ||
// | ||
// AppCellView.swift | ||
// First contact | ||
// | ||
// Created by Ludovic Ollagnier on 30/05/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AppCellView: View { | ||
|
||
let app: Application | ||
|
||
var body: some View { | ||
HStack { | ||
AppIconView(iconName: app.appIconName, radius: 8) | ||
.frame(width: 40, height: 40) | ||
VStack(alignment: .leading) { | ||
Text(app.name) | ||
Text(app.developerName) | ||
.font(.caption2) | ||
.foregroundStyle(.secondary) | ||
} | ||
Spacer() | ||
VStack { | ||
AppInstallButton(app: app) | ||
if app.hasInAppPurchase { | ||
Text("Achats intégrés") | ||
.font(.system(size: 8)) | ||
.fontWeight(.light) | ||
.foregroundStyle(.secondary) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
AppCellView(app: Application.demoApps.first!) | ||
} | ||
|
||
#Preview { | ||
AppCellView(app: Application.demoApps.first!) | ||
} |
28 changes: 28 additions & 0 deletions
28
Projects/First contact/First contact/Views/AppIconView.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,28 @@ | ||
// | ||
// AppIconView.swift | ||
// First contact | ||
// | ||
// Created by Ludovic Ollagnier on 30/05/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AppIconView: View { | ||
|
||
let iconName: String | ||
var radius = 20.0 | ||
|
||
var body: some View { | ||
RoundedRectangle(cornerRadius: radius, style: .continuous) | ||
.foregroundStyle(.gray) | ||
.overlay { | ||
Image(systemName: iconName) | ||
.resizable() | ||
.padding() | ||
} } | ||
} | ||
|
||
#Preview { | ||
AppIconView(iconName: "leaf") | ||
.frame(width: 128, height: 128) | ||
} |
50 changes: 50 additions & 0 deletions
50
Projects/First contact/First contact/Views/AppInstallButton.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,50 @@ | ||
// | ||
// AppInstallButton.swift | ||
// First contact | ||
// | ||
// Created by Ludovic Ollagnier on 30/05/2024. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct AppInstallButton: View { | ||
|
||
let app: Application | ||
|
||
@Environment(\.locale) var locale | ||
@Environment(AppData.self) var data: AppData | ||
|
||
var body: some View { | ||
Button(action: { | ||
data.install(app: app) | ||
}) { | ||
if data.isAppInstalled(app) { | ||
Image(systemName: "icloud.and.arrow.down") | ||
.padding(.horizontal) | ||
} else { | ||
buttonText | ||
.lineLimit(1) | ||
.minimumScaleFactor(0.8) | ||
.frame(width: 50) | ||
} | ||
} | ||
.buttonStyle(AppStoreButtonStyle()) | ||
} | ||
|
||
@ViewBuilder | ||
private var buttonText: some View { | ||
if let price = app.price { | ||
Text(price, format: .currency(code: locale.currency?.identifier ?? "EUR")) | ||
} else { | ||
Text("Obtenir") | ||
} | ||
} | ||
} | ||
|
||
#Preview { | ||
AppInstallButton(app: Application.demoApps.first!) | ||
} | ||
|
||
#Preview { | ||
AppInstallButton(app: Application.demoApps.last!) | ||
} |
File renamed without changes.
Oops, something went wrong.