Skip to content

Commit 22ee7f5

Browse files
Update .gitignore, refactor Swift views for improved UI and data binding
1 parent 2827a97 commit 22ee7f5

File tree

4 files changed

+96
-18
lines changed

4 files changed

+96
-18
lines changed

.gitignore

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,63 @@
1-
Secrets.plist
1+
Secrets.plist
2+
# Xcode
3+
#
4+
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
5+
6+
## User settings
7+
xcuserdata/
8+
9+
## Obj-C/Swift specific
10+
*.hmap
11+
12+
## App packaging
13+
*.ipa
14+
*.dSYM.zip
15+
*.dSYM
16+
17+
## Playgrounds
18+
timeline.xctimeline
19+
playground.xcworkspace
20+
21+
# Swift Package Manager
22+
#
23+
# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies.
24+
# Packages/
25+
# Package.pins
26+
# Package.resolved
27+
# *.xcodeproj
28+
#
29+
# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata
30+
# hence it is not needed unless you have added a package configuration file to your project
31+
# .swiftpm
32+
33+
.build/
34+
35+
# CocoaPods
36+
#
37+
# We recommend against adding the Pods directory to your .gitignore. However
38+
# you should judge for yourself, the pros and cons are mentioned at:
39+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
40+
#
41+
# Pods/
42+
#
43+
# Add this line if you want to avoid checking in source code from the Xcode workspace
44+
# *.xcworkspace
45+
46+
# Carthage
47+
#
48+
# Add this line if you want to avoid checking in source code from Carthage dependencies.
49+
# Carthage/Checkouts
50+
51+
Carthage/Build/
52+
53+
# fastlane
54+
#
55+
# It is recommended to not store the screenshots in the git repo.
56+
# Instead, use fastlane to re-generate the screenshots whenever they are needed.
57+
# For more information about the recommended setup visit:
58+
# https://docs.fastlane.tools/best-practices/source-control/#source-control
59+
60+
fastlane/report.xml
61+
fastlane/Preview.html
62+
fastlane/screenshots/**/*.png
63+
fastlane/test_output

adntmdbapp/ContentView.swift

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ struct MovieListView: View {
2828

2929
var body: some View {
3030
List {
31-
ForEach($networkManager.movies) { $movie in
32-
NavigationLink(destination: MovieDetailView(networkManager: networkManager, movie: $movie)) {
33-
MovieRowView(movie: $movie, networkManager: networkManager)
31+
ForEach(networkManager.movies) { movie in
32+
NavigationLink(destination: MovieDetailView(networkManager: networkManager, movie: .constant(movie))) {
33+
MovieRowView(movie: movie, networkManager: networkManager)
3434
}
3535
}
3636
if networkManager.currentPage <= networkManager.totalPages {
@@ -62,21 +62,30 @@ struct MovieListView: View {
6262
}
6363

6464
struct MovieRowView: View {
65-
@Binding var movie: Movie
65+
let movie: Movie
6666
@ObservedObject var networkManager: NetworkManager
6767

6868
var body: some View {
69-
HStack {
69+
HStack(spacing: 15) {
7070
networkManager.posterImage(for: movie)
71-
.frame(width: 50, height: 75)
72-
VStack(alignment: .leading) {
71+
.frame(width: 60, height: 90)
72+
.cornerRadius(8)
73+
74+
VStack(alignment: .leading, spacing: 5) {
7375
Text(movie.title)
7476
.font(.headline)
75-
Text("Rating: \(String(format: "%.1f", movie.rating))")
76-
.font(.subheadline)
77-
.foregroundColor(.secondary)
77+
.lineLimit(2)
78+
79+
HStack {
80+
Image(systemName: "star.fill")
81+
.foregroundColor(.yellow)
82+
Text(String(format: "%.1f", movie.rating))
83+
.font(.subheadline)
84+
}
7885
}
86+
7987
Spacer()
88+
8089
Button(action: {
8190
networkManager.toggleFavorite(for: movie)
8291
}) {
@@ -85,6 +94,7 @@ struct MovieRowView: View {
8594
}
8695
.buttonStyle(PlainButtonStyle())
8796
}
97+
.padding(.vertical, 8)
8898
}
8999
}
90100

adntmdbapp/FavoriteView.swift

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,21 @@ struct FavoriteView: View {
44
@ObservedObject var networkManager: NetworkManager
55

66
var body: some View {
7-
NavigationView {
8-
List {
9-
ForEach($networkManager.favoriteMovies) { $movie in
10-
NavigationLink(destination: MovieDetailView(networkManager: networkManager, movie: $movie)) {
11-
MovieRowView(movie: $movie, networkManager: networkManager)
12-
}
7+
List {
8+
ForEach(networkManager.favoriteMovies) { movie in
9+
NavigationLink(destination: MovieDetailView(networkManager: networkManager, movie: .constant(movie))) {
10+
MovieRowView(movie: movie, networkManager: networkManager)
1311
}
1412
}
15-
.navigationTitle("Favorites")
13+
.onDelete(perform: removeItems)
14+
}
15+
.navigationTitle("Favorites")
16+
}
17+
18+
func removeItems(at offsets: IndexSet) {
19+
for index in offsets {
20+
let movie = networkManager.favoriteMovies[index]
21+
networkManager.toggleFavorite(for: movie)
1622
}
1723
}
1824
}

0 commit comments

Comments
 (0)