Skip to content
This repository was archived by the owner on Jan 14, 2024. It is now read-only.

Commit 2b0f868

Browse files
authored
Merge pull request #10 from conath/8-vertical-scrolling-cover-flow
Add vertical scroll to Cover Flow
2 parents c42df84 + 992bb09 commit 2b0f868

18 files changed

+377
-186
lines changed

TheatricalMovieTrailers.xcodeproj/project.pbxproj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
833CB265253A147500E1D15C /* UIApplication+version+build.swift in Sources */ = {isa = PBXBuildFile; fileRef = 833CB264253A147500E1D15C /* UIApplication+version+build.swift */; };
2727
834ADB3925397DE1002D9F1E /* MovieInfoOverView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 834ADB3825397DE1002D9F1E /* MovieInfoOverView.swift */; };
2828
834ADB3D25398496002D9F1E /* CoverFlowRotatingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 834ADB3C25398496002D9F1E /* CoverFlowRotatingView.swift */; };
29+
834FFDC4254085ED007E63C2 /* AVPlayerViewController+enterFullScreen.swift in Sources */ = {isa = PBXBuildFile; fileRef = 834FFDC3254085ED007E63C2 /* AVPlayerViewController+enterFullScreen.swift */; };
2930
8380C59C24A665B000CA1EB4 /* TrailerMetaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8380C59B24A665B000CA1EB4 /* TrailerMetaView.swift */; };
3031
8380C59E24A66F3000CA1EB4 /* TrailerListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8380C59D24A66F3000CA1EB4 /* TrailerListView.swift */; };
3132
8380C5A324A6721A00CA1EB4 /* ExternalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8380C5A224A6721A00CA1EB4 /* ExternalView.swift */; };
@@ -34,6 +35,8 @@
3435
83AE012E25370A2E00A416FC /* TrailerListRow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83AE012D25370A2E00A416FC /* TrailerListRow.swift */; };
3536
83BAC28E2538CC56004D59BC /* FramedImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83BAC28D2538CC56004D59BC /* FramedImage.swift */; };
3637
83CBE5122537600F00E22FAE /* CoverFlowListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83CBE5112537600F00E22FAE /* CoverFlowListView.swift */; };
38+
83D21174253F9CDD00EF54A3 /* SortingMode.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D21173253F9CDD00EF54A3 /* SortingMode.swift */; };
39+
83D2117825405FC900EF54A3 /* InlineTrailerPlayerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D2117725405FC900EF54A3 /* InlineTrailerPlayerView.swift */; };
3740
83D5252924A661760086707E /* MovieMetaView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83D5252824A661760086707E /* MovieMetaView.swift */; };
3841
83F59A45253DCAFD00EEA7A5 /* CoverFlowScrollView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F59A44253DCAFD00EEA7A5 /* CoverFlowScrollView.swift */; };
3942
83F59A48253DCC1700EEA7A5 /* CoverFlowItemView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 83F59A47253DCC1700EEA7A5 /* CoverFlowItemView.swift */; };
@@ -61,6 +64,7 @@
6164
833CB264253A147500E1D15C /* UIApplication+version+build.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIApplication+version+build.swift"; sourceTree = "<group>"; };
6265
834ADB3825397DE1002D9F1E /* MovieInfoOverView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieInfoOverView.swift; sourceTree = "<group>"; };
6366
834ADB3C25398496002D9F1E /* CoverFlowRotatingView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverFlowRotatingView.swift; sourceTree = "<group>"; };
67+
834FFDC3254085ED007E63C2 /* AVPlayerViewController+enterFullScreen.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AVPlayerViewController+enterFullScreen.swift"; sourceTree = "<group>"; };
6468
8380C59B24A665B000CA1EB4 /* TrailerMetaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailerMetaView.swift; sourceTree = "<group>"; };
6569
8380C59D24A66F3000CA1EB4 /* TrailerListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailerListView.swift; sourceTree = "<group>"; };
6670
8380C5A224A6721A00CA1EB4 /* ExternalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExternalView.swift; sourceTree = "<group>"; };
@@ -71,6 +75,8 @@
7175
83AE012D25370A2E00A416FC /* TrailerListRow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TrailerListRow.swift; sourceTree = "<group>"; };
7276
83BAC28D2538CC56004D59BC /* FramedImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FramedImage.swift; sourceTree = "<group>"; };
7377
83CBE5112537600F00E22FAE /* CoverFlowListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverFlowListView.swift; sourceTree = "<group>"; };
78+
83D21173253F9CDD00EF54A3 /* SortingMode.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SortingMode.swift; sourceTree = "<group>"; };
79+
83D2117725405FC900EF54A3 /* InlineTrailerPlayerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InlineTrailerPlayerView.swift; sourceTree = "<group>"; };
7480
83D5252824A661760086707E /* MovieMetaView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MovieMetaView.swift; sourceTree = "<group>"; };
7581
83F59A44253DCAFD00EEA7A5 /* CoverFlowScrollView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverFlowScrollView.swift; sourceTree = "<group>"; };
7682
83F59A47253DCC1700EEA7A5 /* CoverFlowItemView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CoverFlowItemView.swift; sourceTree = "<group>"; };
@@ -128,6 +134,8 @@
128134
8380C59F24A670D800CA1EB4 /* Supporting Files */ = {
129135
isa = PBXGroup;
130136
children = (
137+
834FFDC3254085ED007E63C2 /* AVPlayerViewController+enterFullScreen.swift */,
138+
831CD8FA24ABEC36008EDC6F /* CustomDarkAppearance.swift */,
131139
833CB264253A147500E1D15C /* UIApplication+version+build.swift */,
132140
8396CA1924A6A756007734F0 /* current_720p.xml */,
133141
8396CA1B24A6A766007734F0 /* current.xml */,
@@ -144,6 +152,7 @@
144152
children = (
145153
8316E0FB24A64B5E00467F14 /* MovieInfo.swift */,
146154
831CD8F424ABE34A008EDC6F /* Settings.swift */,
155+
83D21173253F9CDD00EF54A3 /* SortingMode.swift */,
147156
);
148157
path = Model;
149158
sourceTree = "<group>";
@@ -158,8 +167,8 @@
158167
8380C5A224A6721A00CA1EB4 /* ExternalView.swift */,
159168
8316E10124A64CD500467F14 /* ExternalTrailerView.swift */,
160169
8334EF7A252E697300A1EB87 /* ExternalMovieMetaView.swift */,
161-
831CD8FA24ABEC36008EDC6F /* CustomDarkAppearance.swift */,
162170
830AA4182536FB94006A3AEB /* TrailerPlayerView.swift */,
171+
83D2117725405FC900EF54A3 /* InlineTrailerPlayerView.swift */,
163172
8380C59D24A66F3000CA1EB4 /* TrailerListView.swift */,
164173
833CB25E253A03C800E1D15C /* CompactTrailerListView.swift */,
165174
83AE012D25370A2E00A416FC /* TrailerListRow.swift */,
@@ -257,9 +266,11 @@
257266
834ADB3925397DE1002D9F1E /* MovieInfoOverView.swift in Sources */,
258267
833CB265253A147500E1D15C /* UIApplication+version+build.swift in Sources */,
259268
8316E0E624A64AD300467F14 /* SceneDelegate.swift in Sources */,
269+
834FFDC4254085ED007E63C2 /* AVPlayerViewController+enterFullScreen.swift in Sources */,
260270
833CB25F253A03C800E1D15C /* CompactTrailerListView.swift in Sources */,
261271
831CD8F524ABE34A008EDC6F /* Settings.swift in Sources */,
262272
8316E0FA24A64B3F00467F14 /* MovieTrailerView.swift in Sources */,
273+
83D21174253F9CDD00EF54A3 /* SortingMode.swift in Sources */,
263274
831CD8FB24ABEC36008EDC6F /* CustomDarkAppearance.swift in Sources */,
264275
834ADB3D25398496002D9F1E /* CoverFlowRotatingView.swift in Sources */,
265276
83F59A48253DCC1700EEA7A5 /* CoverFlowItemView.swift in Sources */,
@@ -268,6 +279,7 @@
268279
8334EF7B252E697300A1EB87 /* ExternalMovieMetaView.swift in Sources */,
269280
8380C59E24A66F3000CA1EB4 /* TrailerListView.swift in Sources */,
270281
83AE012E25370A2E00A416FC /* TrailerListRow.swift in Sources */,
282+
83D2117825405FC900EF54A3 /* InlineTrailerPlayerView.swift in Sources */,
271283
830AA4192536FB94006A3AEB /* TrailerPlayerView.swift in Sources */,
272284
8380C59C24A665B000CA1EB4 /* TrailerMetaView.swift in Sources */,
273285
838403492538B7B80056E50A /* MoviePosterView.swift in Sources */,
@@ -412,7 +424,7 @@
412424
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
413425
CODE_SIGN_IDENTITY = "Apple Development";
414426
CODE_SIGN_STYLE = Automatic;
415-
CURRENT_PROJECT_VERSION = 24;
427+
CURRENT_PROJECT_VERSION = 25;
416428
DEVELOPMENT_ASSET_PATHS = "\"TheatricalMovieTrailers/Preview Content\"";
417429
DEVELOPMENT_TEAM = U96PJYMZWW;
418430
ENABLE_PREVIEWS = YES;
@@ -437,7 +449,7 @@
437449
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
438450
CODE_SIGN_IDENTITY = "Apple Development";
439451
CODE_SIGN_STYLE = Automatic;
440-
CURRENT_PROJECT_VERSION = 24;
452+
CURRENT_PROJECT_VERSION = 25;
441453
DEVELOPMENT_ASSET_PATHS = "\"TheatricalMovieTrailers/Preview Content\"";
442454
DEVELOPMENT_TEAM = U96PJYMZWW;
443455
ENABLE_PREVIEWS = YES;

TheatricalMovieTrailers/AppDelegate.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ class AppDelegate: UIResponder, UIApplicationDelegate, ObservableObject {
4343
self.idsAndImages.updateValue(image, forKey: movieInfo.id)
4444
}
4545
} else {
46-
self.idsAndImages.updateValue(nil, forKey: movieInfo.id)
46+
DispatchQueue.main.async {
47+
self.idsAndImages.updateValue(nil, forKey: movieInfo.id)
48+
}
4749
}
4850
}
4951
}

TheatricalMovieTrailers/ContentView.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ struct ContentView: View {
1111
@ObservedObject var settings = Settings.instance()
1212
@ObservedObject var appDelegate = UIApplication.shared.delegate as! AppDelegate
1313
@EnvironmentObject var sceneDelegate: SceneDelegate
14+
@State var sortingMode = SortingMode.ReleaseAscending
1415

1516
var body: some View {
1617
ZStack {
1718
if let model = sceneDelegate.model, appDelegate.idsAndImages.count == model.count {
1819
MovieInfoOverView(model: model)
1920
}
20-
/// We reference the `prefersDarkAppearance` to make the `ContentView` update when the setting changes.
21-
if settings.prefersDarkAppearance {
22-
Color.clear
23-
}
2421
}
2522
.overlay(
2623
ZStack {

TheatricalMovieTrailers/Info.plist

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
<string>1.0</string>
2121
<key>CFBundleVersion</key>
2222
<string>$(CURRENT_PROJECT_VERSION)</string>
23+
<key>ITSAppUsesNonExemptEncryption</key>
24+
<false/>
2325
<key>LSRequiresIPhoneOS</key>
2426
<true/>
2527
<key>UIApplicationSceneManifest</key>
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
//
2+
// SortingMode.swift
3+
// TheatricalMovieTrailers
4+
//
5+
// Created by Christoph Parstorfer on 21.10.20.
6+
//
7+
8+
import Foundation
9+
10+
enum SortingMode: String {
11+
case ReleaseAscending = "Release date"
12+
case ReleaseDescending = "Release (reversed)"
13+
case TitleAscending = "Title (A-Z)"
14+
15+
func nextMode() -> SortingMode {
16+
switch self {
17+
case .ReleaseAscending:
18+
return .ReleaseDescending
19+
case .ReleaseDescending:
20+
return .TitleAscending
21+
default:
22+
return .ReleaseAscending
23+
}
24+
}
25+
26+
var predicate: ((MovieInfo, MovieInfo) -> Bool) {
27+
get {
28+
switch self {
29+
case .ReleaseAscending:
30+
return {
31+
if $0.releaseDate != nil && $1.releaseDate == nil {
32+
return false
33+
} else if $0.releaseDate == nil && $1.releaseDate != nil {
34+
return true
35+
} else if let r0 = $0.releaseDate, let r1 = $1.releaseDate {
36+
return r0 < r1
37+
} else {
38+
return $0.title < $1.title
39+
}
40+
}
41+
case .ReleaseDescending:
42+
return {
43+
if $0.releaseDate != nil && $1.releaseDate == nil {
44+
return true
45+
} else if $0.releaseDate == nil && $1.releaseDate != nil {
46+
return false
47+
} else if let r0 = $0.releaseDate, let r1 = $1.releaseDate {
48+
return r0 > r1
49+
} else {
50+
return $0.title < $1.title
51+
}
52+
}
53+
default:
54+
return {
55+
return $0.title < $1.title
56+
}
57+
}
58+
}
59+
}
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// AVPlayerViewController+enterFullScreen.swift
3+
// TheatricalMovieTrailers
4+
//
5+
// Created by Christoph Parstorfer on 21.10.20.
6+
//
7+
8+
import AVKit
9+
10+
/// Exposes private API to enter and exit full screen programmatically
11+
/// https://github.com/SparkDev97/iOS14-Runtime-Headers/blob/master/Frameworks/AVKit.framework/AVPlayerViewController.h#L249
12+
extension AVPlayerViewController {
13+
func enterFullScreen(animated: Bool) {
14+
perform(NSSelectorFromString("enterFullScreenAnimated:completionHandler:"), with: animated, with: nil)
15+
}
16+
func exitFullScreen(animated: Bool) {
17+
perform(NSSelectorFromString("exitFullScreenAnimated:completionHandler:"), with: animated, with: nil)
18+
}
19+
}

TheatricalMovieTrailers/Views/CustomDarkAppearance.swift renamed to TheatricalMovieTrailers/Supporting Files/CustomDarkAppearance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct CustomDarkAppearance: ViewModifier {
2222
.preferredColorScheme(
2323
// using .none does cause the ContentView to update properly
2424
// if prefersDarkAppearance was switched from true to false
25-
.none//UITraitCollection().userInterfaceStyle == .dark ? .dark : .light
25+
UITraitCollection().userInterfaceStyle == .dark ? .dark : .light
2626
)
2727
)
2828
}

TheatricalMovieTrailers/Supporting Files/SceneDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate, ObservableObject {
2424
let view = ContentView()
2525
let contentView = view.environmentObject(self)
2626
let parserDelegate = MovieInfoXMLParserDelegate { maybeModel in
27-
self.model = maybeModel
2827
if let model = maybeModel {
28+
self.model = model.sorted(by: SortingMode.ReleaseAscending.predicate)
2929
appDelegate.fetchImagesFor(model: model)
3030
}
3131
}

TheatricalMovieTrailers/Views/CompactTrailerListView.swift

Lines changed: 2 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,9 @@
88
import SwiftUI
99

1010
struct CompactTrailerListView: View {
11-
enum SortingMode: String {
12-
case TitleAscending = "Title (A-Z)"
13-
case ReleaseAscending = "Release date"
14-
case ReleaseDescending = "Release (reversed)"
15-
16-
func nextMode() -> SortingMode {
17-
switch self {
18-
case .TitleAscending:
19-
return .ReleaseAscending
20-
case .ReleaseAscending:
21-
return .ReleaseDescending
22-
default:
23-
return .TitleAscending
24-
}
25-
}
26-
27-
var predicate: ((MovieInfo, MovieInfo) -> Bool) {
28-
get {
29-
switch self {
30-
case .ReleaseAscending:
31-
return {
32-
if let r0 = $0.releaseDate, let r1 = $1.releaseDate {
33-
return r0 < r1
34-
} else {
35-
return $0.title < $1.title
36-
}
37-
}
38-
case .ReleaseDescending:
39-
return {
40-
if let r0 = $0.releaseDate, let r1 = $1.releaseDate {
41-
return r0 > r1
42-
} else {
43-
return $0.title < $1.title
44-
}
45-
}
46-
default:
47-
return {
48-
return $0.title < $1.title
49-
}
50-
}
51-
}
52-
}
53-
}
54-
5511
@Binding var model: [MovieInfo]
12+
@Binding var sortingMode: SortingMode
5613
@State private var showingSettings = false
57-
@State var sortingMode = SortingMode.ReleaseAscending
5814

5915
var body: some View {
6016
GeometryReader { geo in
@@ -112,7 +68,7 @@ struct CompactTrailerListView: View {
11268
#if DEBUG
11369
struct CompactTrailerListView_Previews: PreviewProvider {
11470
static var previews: some View {
115-
CompactTrailerListView(model: .constant([MovieInfo.Example.AQuietPlaceII, MovieInfo.Example.AQuietPlaceII]))
71+
CompactTrailerListView(model: .constant([MovieInfo.Example.AQuietPlaceII]), sortingMode: .constant(.ReleaseAscending))
11672
.colorScheme(.dark)
11773
.background(Color.black)
11874
}

TheatricalMovieTrailers/Views/CoverFlowItemView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ struct CoverFlowItemView: View {
2929
Spacer()
3030

3131
Text(model.title)
32-
.font(.headline)
32+
.font(.title)
3333
.lineLimit(4)
3434
.multilineTextAlignment(.center)
3535
.padding(.init(top: 0, leading: 16, bottom: 32, trailing: 16))

0 commit comments

Comments
 (0)