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

[DRAFT] List updates and image assets #1

Merged
merged 6 commits into from
Aug 28, 2024
Merged
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,9 @@ fastlane/test_output
# https://github.com/johnno1962/injectionforxcode

iOSInjectionProject/

# Environment
#
# Ignore macOS environment items

.DS_Store

This file was deleted.

27 changes: 27 additions & 0 deletions CollectSomeMore/Assets.xcassets/AccentColor.colorset/Contents.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,33 @@
{
"colors" : [
{
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "0.600",
"green" : "0.200",
"red" : "0.000"
}
},
"idiom" : "universal"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"color" : {
"color-space" : "display-p3",
"components" : {
"alpha" : "1.000",
"blue" : "1.000",
"green" : "0.800",
"red" : "0.600"
}
},
"idiom" : "universal"
}
],
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
@@ -1,6 +1,7 @@
{
"images" : [
{
"filename" : "AppIcon_GamesAndThings_iOS.png",
"idiom" : "universal",
"platform" : "ios",
"size" : "1024x1024"
Expand Down
6 changes: 3 additions & 3 deletions CollectSomeMore/CollectSomeMoreApp.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// CollectSomeMoreApp.swift
// CollectSomeMore
// Gamesandthings.swift
// Games and Things - tracking your collections across gaming genres.
//
// Created by Adam Jolicoeur on 6/7/24.
//
Expand All @@ -9,7 +9,7 @@ import SwiftUI
import SwiftData

@main
struct CollectSomeMoreApp: App {
struct GamesAndThings: App {
var sharedModelContainer: ModelContainer = {
let schema = Schema([
Movie.self,
Expand Down
128 changes: 128 additions & 0 deletions CollectSomeMore/Comics.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
//
// ComicsData.swift
// GamesAndThings
//
// Created by Adam Jolicoeur on 7/2/24.
//

import SwiftUI

// Step 1: Define a comics Model
struct Comic: Identifiable {
let id = UUID()
let title: String
let genre: String
let description: String
}

// Step 2: Extend the ComicsViewModel
class ComicViewModel: ObservableObject {
@Published var comic: [Comic] = [
Comic(title: "Inception", genre: "Science Fiction", description: "A thief who steals corporate secrets through the use of dream-sharing technology is given the inverse task of planting an idea into the mind of a CEO."),
Comic(title: "The Shawshank Redemption", genre: "Drama", description: "Two imprisoned men bond over a number of years, finding solace and eventual redemption through acts of common decency."),
Comic(title: "The Dark Knight", genre: "Action", description: "When the menace known as the Joker emerges from his mysterious past, he wreaks havoc and chaos on the people of Gotham."),
]

// Method to add a new comic
func addComic(title: String, genre: String, description: String) {
let newComic = Comic(title: title, genre: genre, description: description)
comic.append(newComic)
}
}

// Step 3: Build the ComicView
struct ComicView: View {
var comic: Comic

var body: some View {
VStack(alignment: .leading, spacing: 10) {
// Text(comic.title)
// .font(.headline)
// .foregroundColor(.primary)
Label("Genre: \(comic.genre)", systemImage: "popcorn")
.labelStyle(.titleAndIcon)
.font(.subheadline)
// Text("Genre: \(comic.genre)")
// .font(.subheadline)
// .foregroundColor(.secondary)

Text(comic.description)
.font(.body)
.foregroundColor(.secondary)
}
.padding()
.background(Color(UIColor.systemGray6))
.cornerRadius(8)
.shadow(radius: 2)
}
}

// Step 4: Create the ComicsFormView
struct ComicFormView: View {
@Environment(\.presentationMode) var presentationMode
@ObservedObject var viewModel: ComicViewModel
@State private var title: String = ""
@State private var genre: String = ""
@State private var description: String = ""

var body: some View {
NavigationView {
Form {
Section(header: Text("Comic Details")) {
TextField("Title", text: $title)
TextField("Genre", text: $genre)
TextField("Description", text: $description)
}

Button(action: {
viewModel.addComic(title: title, genre: genre, description: description)
presentationMode.wrappedValue.dismiss()
}) {
Text("Add comics")
}
.disabled(title.isEmpty || genre.isEmpty || description.isEmpty)
}
.navigationTitle("Add New comics")
}
}
}

// Step 5: Update the Main View
struct ComicListView: View {
@StateObject private var viewModel = ComicViewModel()
@State private var showingForm = false

var body: some View {
NavigationView {
List(viewModel.comic) { comic in
NavigationLink {
ComicView(comic: comic)
} label: {
Text(comic.title)
}
ComicView(comic: comic)
.padding(.vertical, 5)
}
.navigationTitle("Comics")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button(action: {
showingForm.toggle()
}) {
Image(systemName: "plus")
}
.sheet(isPresented: $showingForm) {
ComicFormView(viewModel: viewModel)
}
}
}
}
}
}

// Preview
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ComicListView()
}
}
46 changes: 29 additions & 17 deletions CollectSomeMore/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ struct ContentView: View {
@Query(sort: \Movie.title) private var movies: [Movie]

@State private var newMovie: Movie?

@State private var searchText = ""

var body: some View {
NavigationSplitView {
Group {
if !movies.isEmpty {
List {
ForEach(movies) { movie in
ForEach(filteredMovies) { movie in
NavigationLink {
MovieDetail(movie: movie)
} label: {
Expand All @@ -28,21 +29,24 @@ struct ContentView: View {
}
.onDelete(perform: deleteItems)
}
.navigationTitle("Movies")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addMovie) {
Label("Add Movie", systemImage: "plus.app")
}
}
}
.searchable(text: $searchText)
} else {
ContentUnavailableView {
Label("No Movies", systemImage: "film.stack")
}
}
}
.navigationTitle("Movies")
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
EditButton()
}
ToolbarItem {
Button(action: addMovie) {
Label("Add Movie", systemImage: "plus")
Label("There are no movies in your collection.", systemImage: "list.and.film")
Button("Add a movie", action: addMovie)
}
.navigationTitle("Movies")
}
}
.sheet(item: $newMovie) { movie in
Expand All @@ -53,13 +57,21 @@ struct ContentView: View {
}
} detail: {
Text("Select a movie")
.navigationTitle("Movie")
.navigationTitle("Movies")
}
}

private var filteredMovies: [Movie] {
if searchText.isEmpty {
return movies
} else {
return movies.filter { $0.title.localizedCaseInsensitiveContains(searchText) }
}
}

private func addMovie() {
withAnimation {
let newItem = Movie(title: "", releaseDate: .now)
let newItem = Movie(id: UUID(), title: "", releaseDate: .now, purchaseDate: Date(timeIntervalSinceNow: -5_000_000), genre: "Action")
modelContext.insert(newItem)
newMovie = newItem
}
Expand All @@ -74,7 +86,7 @@ struct ContentView: View {
}
}

#Preview {
#Preview("List view") {
ContentView()
.modelContainer(MovieData.shared.modelContainer)
}
Expand Down
39 changes: 39 additions & 0 deletions CollectSomeMore/GamesAndThings.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//
// Gamesandthings.swift
// Games and Things - tracking your collections across gaming genres.
//
// Created by Adam Jolicoeur on 6/7/24.
//

import Foundation
import SwiftData

@Model
final class Movie {
var id: UUID
var title: String
var releaseDate: Date
var purchaseDate: Date
var genre: String
var imageData: Data?

init(id: UUID = UUID(), title: String, releaseDate: Date, purchaseDate: Date, genre: String, imageData: Data? = nil) {
self.id = id
self.title = title
self.releaseDate = releaseDate
self.purchaseDate = purchaseDate
self.genre = genre
self.imageData = imageData
}

static let sampleData = [
Movie(id: UUID(), title: "Deadpool",
releaseDate: Date(timeIntervalSinceReferenceDate: -402_00_00),
purchaseDate: Date(timeIntervalSinceNow: -5_000_000),
genre: "Superhero"),
Movie(id: UUID(), title: "Deadpool & Wolverine",
releaseDate: Date(timeIntervalSinceReferenceDate: -20_000_000),
purchaseDate: Date(timeIntervalSinceNow: -5_000_000),
genre: "Comedy")
]
}
50 changes: 16 additions & 34 deletions CollectSomeMore/Movie.swift
Original file line number Diff line number Diff line change
@@ -1,35 +1,17 @@
//
// Movie.swift
// CollectSomeMore
//
// Created by Adam Jolicoeur on 6/7/24.
//
import SwiftUI

import Foundation
import SwiftData

@Model
final class Movie {
var title: String
var releaseDate: Date

init(title: String, releaseDate: Date) {
self.title = title
self.releaseDate = releaseDate
}

static let sampleData = [
Movie(title: "Amusing Space Traveler 3",
releaseDate: Date(timeIntervalSinceReferenceDate: -402_00_00)),
Movie(title: "Difficult Cat",
releaseDate: Date(timeIntervalSinceReferenceDate: -20_000_000)),
Movie(title: "Electrifying Trek",
releaseDate: Date(timeIntervalSinceReferenceDate: 300_000_000)),
Movie(title: "Reckless Train Ride 2",
releaseDate: Date(timeIntervalSinceReferenceDate: 120_000_000)),
Movie(title: "The Last Venture",
releaseDate: Date(timeIntervalSinceReferenceDate: 550_000_000)),
Movie(title: "Glamorous Neighbor",
releaseDate: Date(timeIntervalSinceReferenceDate: 700_000_000))
]
}
//class Movie: ObservableObject {
// @Published var title: String
// @Published var releaseDate: Date
// @Published var purchaseDate: Date
// @Published var genre: String
// @Published var imageData: Data?
//
// init(title: String, releaseDate: Date, purchaseDate: Date, genre: String, imageData: Data? = nil) {
// self.title = title
// self.releaseDate = releaseDate
// self.purchaseDate = purchaseDate
// self.genre = genre
// self.imageData = imageData
// }
//}
Loading
Loading