From 7d247bddb3812cdb91115e56dbad36209e5c2ed6 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Sun, 7 Nov 2021 17:52:42 +0100 Subject: [PATCH] UI improvements --- Model/Player/PlayerModel.swift | 13 ++++++-- Open in Yattee/Resources/popup.css | 15 --------- Open in Yattee/Resources/popup.html | 11 ------- Open in Yattee/Resources/popup.js | 1 - Open in Yattee/content.js | 2 +- .../AccentColor.colorset/Contents.json | 18 +++++++++++ Shared/Favorites/FavoritesView.swift | 31 +++++++++++++------ Shared/Navigation/Sidebar.swift | 2 +- Shared/Player/PlaybackBar.swift | 11 +++++++ Shared/Settings/SettingsView.swift | 6 ++++ tvOS/EditFavorites.swift | 6 +--- 11 files changed, 71 insertions(+), 45 deletions(-) delete mode 100644 Open in Yattee/Resources/popup.css delete mode 100644 Open in Yattee/Resources/popup.html delete mode 100644 Open in Yattee/Resources/popup.js diff --git a/Model/Player/PlayerModel.swift b/Model/Player/PlayerModel.swift index 640a8bbc..984ddc3f 100644 --- a/Model/Player/PlayerModel.swift +++ b/Model/Player/PlayerModel.swift @@ -58,6 +58,15 @@ final class PlayerModel: ObservableObject { var playingInPictureInPicture = false + @Published var presentingErrorDetails = false + var playerError: Error? { didSet { + #if !os(tvOS) + if !playerError.isNil { + presentingErrorDetails = true + } + #endif + }} + init(accounts: AccountsModel? = nil, instances: InstancesModel? = nil) { self.accounts = accounts ?? AccountsModel() self.instances = instances ?? InstancesModel() @@ -123,6 +132,7 @@ final class PlayerModel: ObservableObject { of video: Video, preservingTime: Bool = false ) { + playerError = nil resetSegments() sponsorBlock.loadSegments(videoID: video.videoID, categories: Defaults[.sponsorBlockCategories]) @@ -298,8 +308,7 @@ final class PlayerModel: ObservableObject { self.play() } case .failed: - print("item error: \(String(describing: item.error))") - print((item.asset as! AVURLAsset).url) + self.playerError = item.error default: return diff --git a/Open in Yattee/Resources/popup.css b/Open in Yattee/Resources/popup.css deleted file mode 100644 index 5b149b9e..00000000 --- a/Open in Yattee/Resources/popup.css +++ /dev/null @@ -1,15 +0,0 @@ -:root { - color-scheme: light dark; -} - -body { - width: 100px; - padding: 10px; - - font-family: system-ui; - text-align: center; -} - -@media (prefers-color-scheme: dark) { - /* Dark Mode styles go here. */ -} diff --git a/Open in Yattee/Resources/popup.html b/Open in Yattee/Resources/popup.html deleted file mode 100644 index ac523193..00000000 --- a/Open in Yattee/Resources/popup.html +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - Hello World! - - diff --git a/Open in Yattee/Resources/popup.js b/Open in Yattee/Resources/popup.js deleted file mode 100644 index 5c1aa869..00000000 --- a/Open in Yattee/Resources/popup.js +++ /dev/null @@ -1 +0,0 @@ -console.log("Hello World!", browser); diff --git a/Open in Yattee/content.js b/Open in Yattee/content.js index 3a646afc..4d6ab55b 100644 --- a/Open in Yattee/content.js +++ b/Open in Yattee/content.js @@ -17,7 +17,7 @@ function redirect() { } function replaceContentWithLink() { - document.querySelector('body').innerHTML = yatteeLink(); + document.querySelector('body').innerHTML = '

' + yatteeLink() + '

'; } function redirectAndReplaceContentWithLink(){ diff --git a/Shared/Assets.xcassets/AccentColor.colorset/Contents.json b/Shared/Assets.xcassets/AccentColor.colorset/Contents.json index 768d80ed..db492b7d 100644 --- a/Shared/Assets.xcassets/AccentColor.colorset/Contents.json +++ b/Shared/Assets.xcassets/AccentColor.colorset/Contents.json @@ -11,6 +11,24 @@ } }, "idiom" : "universal" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "color" : { + "color-space" : "display-p3", + "components" : { + "alpha" : "1.000", + "blue" : "0.263", + "green" : "0.290", + "red" : "0.859" + } + }, + "idiom" : "universal" } ], "info" : { diff --git a/Shared/Favorites/FavoritesView.swift b/Shared/Favorites/FavoritesView.swift index 261e5ec3..8401fe0f 100644 --- a/Shared/Favorites/FavoritesView.swift +++ b/Shared/Favorites/FavoritesView.swift @@ -10,24 +10,37 @@ struct FavoritesView: View { @State private var dragging: FavoriteItem? @State private var presentingEditFavorites = false + @State private var favoritesChanged = false + + var favoritesObserver: Any? + + #if !os(tvOS) + @Default(.favorites) private var favorites + #endif + var body: some View { PlayerControlsView { ScrollView(.vertical, showsIndicators: false) { if !accounts.current.isNil { - ForEach(Defaults[.favorites]) { item in - FavoriteItemView(item: item, dragging: $dragging) - } - #if os(tvOS) - Button { - presentingEditFavorites = true - } label: { - Text("Edit Favorites...") + ForEach(Defaults[.favorites]) { item in + FavoriteItemView(item: item, dragging: $dragging) + } + #else + ForEach(favorites) { item in + FavoriteItemView(item: item, dragging: $dragging) } #endif } } - .redrawOn(change: presentingEditFavorites) + .onAppear { + Defaults.observe(.favorites) { _ in + favoritesChanged.toggle() + } + .tieToLifetime(of: accounts) + } + .redrawOn(change: favoritesChanged) + #if os(tvOS) .sheet(isPresented: $presentingEditFavorites) { EditFavorites() diff --git a/Shared/Navigation/Sidebar.swift b/Shared/Navigation/Sidebar.swift index a3174e59..4e2421d7 100644 --- a/Shared/Navigation/Sidebar.swift +++ b/Shared/Navigation/Sidebar.swift @@ -26,7 +26,7 @@ struct Sidebar: View { } .navigationTitle("Yattee") #if os(iOS) - .navigationBarTitleDisplayMode(.inline) + .navigationBarTitleDisplayMode(.inline) #endif } diff --git a/Shared/Player/PlaybackBar.swift b/Shared/Player/PlaybackBar.swift index b002cfe0..3ef92575 100644 --- a/Shared/Player/PlaybackBar.swift +++ b/Shared/Player/PlaybackBar.swift @@ -34,6 +34,14 @@ struct PlaybackBar: View { Image(systemName: "dot.radiowaves.left.and.right") } else if player.isLoadingAvailableStreams || player.isLoadingStream { Image(systemName: "bolt.horizontal.fill") + } else if !player.playerError.isNil { + Button { + player.presentingErrorDetails = true + } label: { + Image(systemName: "exclamationmark.circle.fill") + .foregroundColor(.red) + } + .buttonStyle(.plain) } streamControl @@ -57,6 +65,9 @@ struct PlaybackBar: View { Spacer() } } + .alert(player.playerError?.localizedDescription ?? "", isPresented: $player.presentingErrorDetails) { + Button("OK") {} + } .environment(\.colorScheme, .dark) .frame(minWidth: 0, maxWidth: .infinity) .padding(4) diff --git a/Shared/Settings/SettingsView.swift b/Shared/Settings/SettingsView.swift index 5e6700b6..feac890c 100644 --- a/Shared/Settings/SettingsView.swift +++ b/Shared/Settings/SettingsView.swift @@ -55,6 +55,12 @@ struct SettingsView: View { List { #if os(tvOS) AccountSelectionView() + + Section(header: SettingsHeader(text: "Favorites")) { + NavigationLink("Edit favorites...") { + EditFavorites() + } + } #endif InstancesSettings() BrowsingSettings() diff --git a/tvOS/EditFavorites.swift b/tvOS/EditFavorites.swift index 4589e5b4..22df6c9e 100644 --- a/tvOS/EditFavorites.swift +++ b/tvOS/EditFavorites.swift @@ -11,11 +11,6 @@ struct EditFavorites: View { var body: some View { VStack { ScrollView { - Text("Edit Favorites") - .font(.system(size: 40)) - .fontWeight(.bold) - .foregroundColor(.secondary) - ForEach(favorites) { item in HStack { Text(label(item)) @@ -75,6 +70,7 @@ struct EditFavorites: View { } .frame(width: 1000, alignment: .leading) } + .navigationTitle("Edit Favorites") } func label(_ item: FavoriteItem) -> String {