Skip to content

Commit

Permalink
UpNextMenuBar is now separated.
Browse files Browse the repository at this point in the history
  • Loading branch information
MadeiraAlexandre committed Nov 22, 2023
1 parent 7fbb3d3 commit 7d45905
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 83 deletions.
92 changes: 92 additions & 0 deletions Shared/View/MenuBar/UpNextMenuBar.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//
// UpNextMenuBar.swift
// Story (iOS)
//
// Created by Alexandre Madeira on 22/11/23.
//

import SwiftUI
import SDWebImageSwiftUI

struct UpNextMenuBar: View {
@StateObject private var viewModel: UpNextViewModel = .shared
@FetchRequest(
entity: WatchlistItem.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \WatchlistItem.title, ascending: true)],
predicate: NSCompoundPredicate(type: .and, subpredicates: [ NSPredicate(format: "displayOnUpNext == %d", true),
NSPredicate(format: "isArchive == %d", false),
NSPredicate(format: "watched == %d", false)])
) private var items: FetchedResults<WatchlistItem>
var body: some View {
Form {
Section {
List {
ForEach(viewModel.episodes) { item in
upNextRowItem(item)
.onTapGesture {
Task { await viewModel.markAsWatched(item) }
}
.padding(.top, item == viewModel.episodes.first ? 8 : 0)
.padding(.top, item == viewModel.episodes.last ? 8 : 0)
}
}
.overlay {
if !viewModel.isLoaded {
ProgressView("Loading")
}
}
.redacted(reason: viewModel.isLoaded ? [] : .placeholder)
} header: {
HStack {
Text("upNext")
.font(.callout)
.fontWeight(.semibold)
Spacer()
Button("Refresh", systemImage: "arrow.clockwise") {
Task { await viewModel.reload(items) }
}
.labelStyle(.iconOnly)
}

}
}
.task {
await viewModel.load(items)
await viewModel.checkForNewEpisodes(items)
}
#if os(macOS)
.formStyle(.grouped)
#endif
}

private func upNextRowItem(_ item: UpNextEpisode) -> some View {
HStack {
WebImage(url: item.episode.itemImageSmall ?? item.backupImage)
.placeholder {
ZStack {
Rectangle().fill(.gray.gradient)
Image(systemName: "sparkles.tv")
.foregroundColor(.white.opacity(0.8))
}
.frame(width: 95, height: 50)
}
.resizable()
.aspectRatio(contentMode: .fill)
.transition(.opacity)
.frame(width: 95, height: 50)
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
VStack(alignment: .leading) {
Text(item.showTitle)
.font(.callout)
.lineLimit(1)
Text(String(format: NSLocalizedString("S%d, E%d", comment: ""), item.episode.itemSeasonNumber, item.episode.itemEpisodeNumber))
.font(.caption)
.textCase(.uppercase)
.foregroundColor(.secondary)
.lineLimit(1)
}
.padding(.leading, 2)
Spacer()
}
}
}
83 changes: 0 additions & 83 deletions Shared/View/Up Next/VerticalUpNextListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -317,89 +317,6 @@ extension VerticalUpNextListView {
}
}

struct UpNextMenuBar: View {
@StateObject private var viewModel: UpNextViewModel = .shared
@FetchRequest(
entity: WatchlistItem.entity(),
sortDescriptors: [NSSortDescriptor(keyPath: \WatchlistItem.title, ascending: true)],
predicate: NSCompoundPredicate(type: .and, subpredicates: [ NSPredicate(format: "displayOnUpNext == %d", true),
NSPredicate(format: "isArchive == %d", false),
NSPredicate(format: "watched == %d", false)])
) private var items: FetchedResults<WatchlistItem>
var body: some View {
Form {
Section {
List {
ForEach(viewModel.episodes) { item in
upNextRowItem(item)
.onTapGesture {
Task { await viewModel.markAsWatched(item) }
}
.padding(.top, item == viewModel.episodes.first ? 8 : 0)
.padding(.top, item == viewModel.episodes.last ? 8 : 0)
}
}
.overlay {
if !viewModel.isLoaded {
ProgressView("Loading")
}
}
.redacted(reason: viewModel.isLoaded ? [] : .placeholder)
} header: {
HStack {
Text("upNext")
.font(.callout)
.fontWeight(.semibold)
Spacer()
Button("Refresh", systemImage: "arrow.clockwise") {
Task { await viewModel.reload(items) }
}
.labelStyle(.iconOnly)
}

}
}
.task {
await viewModel.load(items)
await viewModel.checkForNewEpisodes(items)
}
#if os(macOS)
.formStyle(.grouped)
#endif
}

private func upNextRowItem(_ item: UpNextEpisode) -> some View {
HStack {
WebImage(url: item.episode.itemImageSmall ?? item.backupImage)
.placeholder {
ZStack {
Rectangle().fill(.gray.gradient)
Image(systemName: "sparkles.tv")
.foregroundColor(.white.opacity(0.8))
}
.frame(width: 95, height: 50)
}
.resizable()
.aspectRatio(contentMode: .fill)
.transition(.opacity)
.frame(width: 95, height: 50)
.clipShape(RoundedRectangle(cornerRadius: 8, style: .continuous))
VStack(alignment: .leading) {
Text(item.showTitle)
.font(.callout)
.lineLimit(1)
Text(String(format: NSLocalizedString("S%d, E%d", comment: ""), item.episode.itemSeasonNumber, item.episode.itemEpisodeNumber))
.font(.caption)
.textCase(.uppercase)
.foregroundColor(.secondary)
.lineLimit(1)
}
.padding(.leading, 2)
Spacer()
}
}
}

private struct DrawingConstants {
#if os(iOS)
static let columns = [GridItem(.adaptive(minimum: 160))]
Expand Down
12 changes: 12 additions & 0 deletions Story.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@
B8D7AEE428BA64F40053CE5A /* Bundle-Decodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = B82C268E279644E000259D98 /* Bundle-Decodable.swift */; };
B8D8AF8F27D4D0550042AEB6 /* AttributionView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8AF8E27D4D0550042AEB6 /* AttributionView.swift */; };
B8D8AF9227D4DB720042AEB6 /* SearchViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8D8AF9127D4DB720042AEB6 /* SearchViewModel.swift */; };
B8DA5CC62B0E432200678592 /* UpNextMenuBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DA5CC52B0E432200678592 /* UpNextMenuBar.swift */; };
B8DD56A1290DE2FD002CAAFD /* CenterHorizontalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DD569F290DE2D7002CAAFD /* CenterHorizontalView.swift */; };
B8DD56A2290DE2FE002CAAFD /* CenterHorizontalView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B8DD569F290DE2D7002CAAFD /* CenterHorizontalView.swift */; };
B8E3ABF62955361C00CA0945 /* CloudKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B8E3ABF52955361C00CA0945 /* CloudKit.framework */; };
Expand Down Expand Up @@ -643,6 +644,7 @@
B8D7AEE228BA64DF0053CE5A /* DataPlaceholder.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = DataPlaceholder.json; sourceTree = "<group>"; };
B8D8AF8E27D4D0550042AEB6 /* AttributionView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AttributionView.swift; sourceTree = "<group>"; };
B8D8AF9127D4DB720042AEB6 /* SearchViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchViewModel.swift; sourceTree = "<group>"; };
B8DA5CC52B0E432200678592 /* UpNextMenuBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UpNextMenuBar.swift; sourceTree = "<group>"; };
B8DD569F290DE2D7002CAAFD /* CenterHorizontalView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CenterHorizontalView.swift; sourceTree = "<group>"; };
B8E3ABEF29552B6900CA0945 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = System/Library/Frameworks/CloudKit.framework; sourceTree = SDKROOT; };
B8E3ABF52955361C00CA0945 /* CloudKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CloudKit.framework; path = Platforms/WatchOS.platform/Developer/SDKs/WatchOS9.1.sdk/System/Library/Frameworks/CloudKit.framework; sourceTree = DEVELOPER_DIR; };
Expand Down Expand Up @@ -853,6 +855,7 @@
B8110F0F2792678400844FEB /* View */ = {
isa = PBXGroup;
children = (
B8DA5CC42B0E430B00678592 /* MenuBar */,
B81941B92A0861B00057DA04 /* Buttons */,
B81941AD2A08394D0057DA04 /* Changelog */,
B824E4482A05A87600E385CE /* Company */,
Expand Down Expand Up @@ -1384,6 +1387,14 @@
path = Placeholder;
sourceTree = "<group>";
};
B8DA5CC42B0E430B00678592 /* MenuBar */ = {
isa = PBXGroup;
children = (
B8DA5CC52B0E432200678592 /* UpNextMenuBar.swift */,
);
path = MenuBar;
sourceTree = "<group>";
};
B8E7651927B738D200D9B731 /* Configuration */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1916,6 +1927,7 @@
B8F6DE5829329AE8005D1A50 /* EndpointDetails.swift in Sources */,
B88B88C729DE55B500497058 /* AppAlternateIcons.swift in Sources */,
B86E589127A4BE75005DBF38 /* Endpoints.swift in Sources */,
B8DA5CC62B0E432200678592 /* UpNextMenuBar.swift in Sources */,
B86F7ABD2A087FF900AA4855 /* HorizontalUpNextListView.swift in Sources */,
B8F6DE6329379F70005D1A50 /* ItemContentSectionDetails.swift in Sources */,
B804E397284FCBCB00F59855 /* ItemContentCardView.swift in Sources */,
Expand Down

0 comments on commit 7d45905

Please sign in to comment.