diff --git a/FriendsCollection.xcodeproj/project.pbxproj b/FriendsCollection.xcodeproj/project.pbxproj index b0af779..17cfdaf 100644 --- a/FriendsCollection.xcodeproj/project.pbxproj +++ b/FriendsCollection.xcodeproj/project.pbxproj @@ -185,8 +185,7 @@ children = ( E6D5A01F2526213700054C51 /* FriendsCharacters.json */, ); - name = Config; - path = "New Group"; + path = Config; sourceTree = ""; }; /* End PBXGroup section */ diff --git a/FriendsCollection/Assets.xcassets/AllCast-clear.imageset/AllCast-clear.jpg b/FriendsCollection/Assets.xcassets/AllCast-clear.imageset/AllCast-clear.jpg new file mode 100644 index 0000000..320d17c Binary files /dev/null and b/FriendsCollection/Assets.xcassets/AllCast-clear.imageset/AllCast-clear.jpg differ diff --git a/FriendsCollection/Assets.xcassets/AllCast-clear.imageset/Contents.json b/FriendsCollection/Assets.xcassets/AllCast-clear.imageset/Contents.json new file mode 100644 index 0000000..3d3651b --- /dev/null +++ b/FriendsCollection/Assets.xcassets/AllCast-clear.imageset/Contents.json @@ -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 + } +} diff --git a/FriendsCollection/Assets.xcassets/AllCast-small.imageset/AllCast-small.jpg b/FriendsCollection/Assets.xcassets/AllCast-small.imageset/AllCast-small.jpg new file mode 100644 index 0000000..11223d4 Binary files /dev/null and b/FriendsCollection/Assets.xcassets/AllCast-small.imageset/AllCast-small.jpg differ diff --git a/FriendsCollection/Assets.xcassets/AllCast-small.imageset/Contents.json b/FriendsCollection/Assets.xcassets/AllCast-small.imageset/Contents.json new file mode 100644 index 0000000..669614d --- /dev/null +++ b/FriendsCollection/Assets.xcassets/AllCast-small.imageset/Contents.json @@ -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 + } +} diff --git a/FriendsCollection/Assets.xcassets/AllCast.imageset/AllCast.jpg b/FriendsCollection/Assets.xcassets/AllCast.imageset/AllCast.jpg new file mode 100644 index 0000000..81755c6 Binary files /dev/null and b/FriendsCollection/Assets.xcassets/AllCast.imageset/AllCast.jpg differ diff --git a/FriendsCollection/Assets.xcassets/AllCast.imageset/Contents.json b/FriendsCollection/Assets.xcassets/AllCast.imageset/Contents.json new file mode 100644 index 0000000..1e0777e --- /dev/null +++ b/FriendsCollection/Assets.xcassets/AllCast.imageset/Contents.json @@ -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 + } +} diff --git a/FriendsCollection/New Group/FriendsCharacters.json b/FriendsCollection/Config/FriendsCharacters.json similarity index 100% rename from FriendsCollection/New Group/FriendsCharacters.json rename to FriendsCollection/Config/FriendsCharacters.json diff --git a/FriendsCollection/FriendsCollection.entitlements b/FriendsCollection/FriendsCollection.entitlements new file mode 100644 index 0000000..ee95ab7 --- /dev/null +++ b/FriendsCollection/FriendsCollection.entitlements @@ -0,0 +1,10 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + + diff --git a/FriendsCollection/FriendsCollectionApp.swift b/FriendsCollection/FriendsCollectionApp.swift index 7f3b00a..11f8af9 100644 --- a/FriendsCollection/FriendsCollectionApp.swift +++ b/FriendsCollection/FriendsCollectionApp.swift @@ -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") + } + } } } diff --git a/FriendsCollection/View/ContentView.swift b/FriendsCollection/View/ContentView.swift index ab6d9b0..aa2366a 100644 --- a/FriendsCollection/View/ContentView.swift +++ b/FriendsCollection/View/ContentView.swift @@ -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") } } } diff --git a/FriendsCollection/ViewModel/CharacterPresenter.swift b/FriendsCollection/ViewModel/CharacterPresenter.swift index e386b0a..9236485 100644 --- a/FriendsCollection/ViewModel/CharacterPresenter.swift +++ b/FriendsCollection/ViewModel/CharacterPresenter.swift @@ -52,7 +52,6 @@ struct CharacterPresenter: View { .truncationMode(.head) } } - .padding(.all, 10) .frame(height: 150) .background(_color) }