Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapitre5 multitasking #1

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions FriendsCollection.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@
children = (
E6D5A01F2526213700054C51 /* FriendsCharacters.json */,
);
name = Config;
path = "New Group";
path = Config;
sourceTree = "<group>";
};
/* End PBXGroup section */
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "AllCast-clear.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "AllCast-small.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
21 changes: 21 additions & 0 deletions FriendsCollection/Assets.xcassets/AllCast.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"images" : [
{
"filename" : "AllCast.jpg",
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"scale" : "2x"
},
{
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
10 changes: 10 additions & 0 deletions FriendsCollection/FriendsCollection.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.security.app-sandbox</key>
<true/>
<key>com.apple.security.network.client</key>
<true/>
</dict>
</plist>
9 changes: 9 additions & 0 deletions FriendsCollection/FriendsCollectionApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@ import SwiftUI

@main
struct FriendsCollectionApp: App {
@Environment(\.scenePhase) var _scenePhase
var body: some Scene {
WindowGroup {
ContentView()
}
.onChange(of: _scenePhase) { newPhase in
switch newPhase {
case .active: print("active")
case .inactive: print("inactive")
case .background: print("background")
default: print("other")
}
}
}
}

Expand Down
138 changes: 117 additions & 21 deletions FriendsCollection/View/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,130 @@

import SwiftUI

struct ContentView: View {
struct SideBar: View {
var body: some View {
List {
NavigationLink(destination: MainContent(_season: 0, _mainCharacters: 0).navigationTitle("All Characters")) {
Label("All Characters", systemImage: "person.3")
}
Section(header:Text("Seasons")) {
ForEach(1...10, id:\.self) {number in
NavigationLink(destination: MainContent(_season: number, _mainCharacters: 0).navigationTitle("Season \(number)")) {
Label("Season \(number)", systemImage: "tv")
}
}
}
Section(header:Text("Type")) {
NavigationLink(destination: MainContent(_season: -1, _mainCharacters: 1).navigationTitle("Main Characters")) {
Label("Main", systemImage: "star.circle.fill")
}
NavigationLink(destination: MainContent(_season: -1, _mainCharacters: 2).navigationTitle("Guest")) {
Label("Guests", systemImage: "info.circle.fill")
}
}
}
.listStyle(SidebarListStyle())
}
}

struct MainContent: View {
@Environment(\.horizontalSizeClass) var _horizontalSizeClass
@ObservedObject private var _friendsCollection = CharacterDirectory()
@State private var _showEditForm:Bool = false
var _friendsGrid:[GridItem] = [
GridItem(.adaptive(minimum: 320))
]
let _season:Int
let _mainCharacters:Int

var body: some View {
VStack {
HStack {
Text("Friends Collection")
.font(.system(.title))
.bold()
Spacer()
Button(action: {
self._showEditForm = true
}) {
Image(systemName: "plus.circle")
if _horizontalSizeClass == .regular {
ScrollView {
GeometryReader { geometry in
Image("AllCast-clear")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: geometry.size.width, height: geometry.size.height)
.offset(y: geometry.frame(in: .global).minY/5)
.clipped()
}
.font(.system(size:32))
.sheet(isPresented: self.$_showEditForm) {
CharacterEditForm(_characterDirectory: _friendsCollection)
}
}.padding()
List{
ForEach(_friendsCollection.getCharacters(), id: \._id) {value in
CharacterPresenter(content:value)
.frame(maxWidth: .infinity)
.frame(height: 250)
LazyVGrid(columns: _friendsGrid){
ForEach(_friendsCollection.getCharacters(), id: \._id) {value in
switch _season {
case 0: CharacterPresenter(content:value)
case -1:
if _mainCharacters == 1 && value._isMain {
CharacterPresenter(content:value)
}
if _mainCharacters == 2 && !value._isMain {
CharacterPresenter(content:value)
}
default:
if _season == value._season {
CharacterPresenter(content:value)
}
}
}
}.padding(.all, 10)
}
.edgesIgnoringSafeArea(.top)
.navigationBarItems(trailing: Button(action: {
self._showEditForm = true
}) {
Image(systemName: "plus.circle")
}
.font(.system(size:32))
.sheet(isPresented: self.$_showEditForm) {
CharacterEditForm(_characterDirectory: _friendsCollection)
})
} else {
VStack {
ScrollView {
Image("AllCast")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(height: 250)
.padding(/*@START_MENU_TOKEN@*/10/*@END_MENU_TOKEN@*/)
LazyVGrid(columns: _friendsGrid){
ForEach(_friendsCollection.getCharacters(), id: \._id) {value in
switch _season {
case 0: CharacterPresenter(content:value)
case -1:
if _mainCharacters == 1 && value._isMain {
CharacterPresenter(content:value)
}
if _mainCharacters == 2 && !value._isMain {
CharacterPresenter(content:value)
}
default:
if _season == value._season {
CharacterPresenter(content:value)
}
}
}
}.padding(.all, 10)
}
}
.listRowInsets(.init(top: 0, leading: 0, bottom: 0, trailing: 0))
.navigationBarItems(trailing: Button(action: {
self._showEditForm = true
}) {
Image(systemName: "plus.circle")
}
.font(.system(size:32))
.sheet(isPresented: self.$_showEditForm) {
CharacterEditForm(_characterDirectory: _friendsCollection)
})
}
}
}

struct ContentView: View {

var body: some View {
NavigationView {
SideBar().navigationTitle("Friends Collection")
MainContent(_season: 0, _mainCharacters: 0).navigationTitle("All Characters")
}
}
}
Expand Down
1 change: 0 additions & 1 deletion FriendsCollection/ViewModel/CharacterPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ struct CharacterPresenter: View {
.truncationMode(.head)
}
}
.padding(.all, 10)
.frame(height: 150)
.background(_color)
}
Expand Down