2022-12-11 11:38:57 +00:00
|
|
|
import Defaults
|
2022-12-16 08:35:10 +00:00
|
|
|
import Siesta
|
2022-12-10 02:01:59 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SubscriptionsView: View {
|
2022-12-11 11:38:57 +00:00
|
|
|
enum Page: String, CaseIterable, Defaults.Serializable {
|
|
|
|
case feed
|
|
|
|
case channels
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
2022-12-11 11:38:57 +00:00
|
|
|
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
|
2022-12-12 00:18:29 +00:00
|
|
|
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
2023-02-25 15:42:18 +00:00
|
|
|
@Default(.hideShorts) private var hideShorts
|
2022-12-11 11:38:57 +00:00
|
|
|
|
2022-12-12 23:39:50 +00:00
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
2022-12-16 08:35:10 +00:00
|
|
|
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
2022-12-12 23:39:50 +00:00
|
|
|
|
2022-12-10 02:01:59 +00:00
|
|
|
var body: some View {
|
2022-12-10 21:37:14 +00:00
|
|
|
SignInRequiredView(title: "Subscriptions".localized()) {
|
2022-12-11 11:38:57 +00:00
|
|
|
switch subscriptionsViewPage {
|
|
|
|
case .feed:
|
|
|
|
FeedView()
|
|
|
|
case .channels:
|
|
|
|
ChannelsView()
|
|
|
|
#if os(tvOS)
|
|
|
|
.ignoresSafeArea(.all, edges: .horizontal)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2022-12-12 00:18:29 +00:00
|
|
|
.environment(\.listingStyle, subscriptionsListingStyle)
|
2023-02-25 15:42:18 +00:00
|
|
|
.environment(\.hideShorts, hideShorts)
|
2022-12-10 02:01:59 +00:00
|
|
|
|
2022-12-11 11:38:57 +00:00
|
|
|
#if os(iOS)
|
2022-12-12 00:18:29 +00:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .principal) {
|
|
|
|
subscriptionsMenu
|
|
|
|
}
|
2022-12-16 08:35:10 +00:00
|
|
|
|
|
|
|
ToolbarItem {
|
|
|
|
RequestErrorButton(error: requestError)
|
|
|
|
}
|
2022-12-12 00:18:29 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if os(macOS)
|
2022-12-11 11:38:57 +00:00
|
|
|
.toolbar {
|
2023-04-22 15:59:28 +00:00
|
|
|
ToolbarItemGroup {
|
2022-12-12 00:18:29 +00:00
|
|
|
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
2023-02-25 15:42:18 +00:00
|
|
|
HideShortsButtons(hide: $hideShorts)
|
2022-12-13 12:14:20 +00:00
|
|
|
toggleWatchedButton
|
2023-04-22 15:59:28 +00:00
|
|
|
.id(feed.watchedId)
|
2022-12-13 21:32:49 +00:00
|
|
|
playUnwatchedButton
|
2023-04-22 15:59:28 +00:00
|
|
|
.id(feed.watchedId)
|
2022-12-13 21:32:49 +00:00
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-10 20:08:03 +00:00
|
|
|
|
2022-12-16 08:35:10 +00:00
|
|
|
var requestError: RequestError? {
|
|
|
|
subscriptionsViewPage == .channels ? subscriptions.error : feed.error
|
|
|
|
}
|
|
|
|
|
2022-12-11 11:38:57 +00:00
|
|
|
#if os(iOS)
|
|
|
|
var subscriptionsMenu: some View {
|
|
|
|
Menu {
|
|
|
|
Picker("Page", selection: $subscriptionsViewPage) {
|
|
|
|
Label("Feed", systemImage: "film").tag(Page.feed)
|
|
|
|
Label("Channels", systemImage: "person.3.fill").tag(Page.channels)
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
2022-12-11 22:15:56 +00:00
|
|
|
|
2022-12-12 00:18:29 +00:00
|
|
|
if subscriptionsViewPage == .feed {
|
|
|
|
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
|
|
|
}
|
|
|
|
|
2023-02-25 15:42:18 +00:00
|
|
|
Section {
|
|
|
|
HideShortsButtons(hide: $hideShorts)
|
|
|
|
}
|
|
|
|
|
2022-12-13 12:14:20 +00:00
|
|
|
playUnwatchedButton
|
|
|
|
|
|
|
|
toggleWatchedButton
|
|
|
|
|
2022-12-11 22:15:56 +00:00
|
|
|
Section {
|
|
|
|
SettingsButtons()
|
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
} label: {
|
|
|
|
HStack(spacing: 12) {
|
2022-12-11 22:40:08 +00:00
|
|
|
menuLabel
|
2022-12-11 11:38:57 +00:00
|
|
|
.foregroundColor(.primary)
|
|
|
|
|
|
|
|
Image(systemName: "chevron.down.circle.fill")
|
|
|
|
.foregroundColor(.accentColor)
|
|
|
|
.imageScale(.small)
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
.transaction { t in t.animation = nil }
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-11 22:40:08 +00:00
|
|
|
var menuLabel: some View {
|
|
|
|
HStack {
|
|
|
|
Image(systemName: subscriptionsViewPage == .channels ? "person.3.fill" : "film")
|
2022-12-12 00:18:29 +00:00
|
|
|
.imageScale(.small)
|
2022-12-11 22:40:08 +00:00
|
|
|
Text(subscriptionsViewPage.rawValue.capitalized.localized())
|
|
|
|
.font(.headline)
|
|
|
|
}
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
#endif
|
2022-12-13 12:14:20 +00:00
|
|
|
|
|
|
|
var playUnwatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.playUnwatchedFeed()
|
|
|
|
} label: {
|
|
|
|
Label("Play all unwatched", systemImage: "play")
|
|
|
|
}
|
|
|
|
.disabled(!feed.canPlayUnwatchedFeed)
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder var toggleWatchedButton: some View {
|
|
|
|
if feed.canMarkAllFeedAsWatched {
|
|
|
|
markAllFeedAsWatchedButton
|
|
|
|
} else {
|
|
|
|
markAllFeedAsUnwatchedButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var markAllFeedAsWatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.markAllFeedAsWatched()
|
|
|
|
} label: {
|
|
|
|
Label("Mark all as watched", systemImage: "checkmark.circle.fill")
|
|
|
|
}
|
|
|
|
.disabled(!feed.canMarkAllFeedAsWatched)
|
|
|
|
}
|
|
|
|
|
|
|
|
var markAllFeedAsUnwatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.markAllFeedAsUnwatched()
|
|
|
|
} label: {
|
|
|
|
Label("Mark all as unwatched", systemImage: "checkmark.circle")
|
|
|
|
}
|
|
|
|
}
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
|
|
|
|
2022-12-11 11:38:57 +00:00
|
|
|
struct SubscriptionsView_Previews: PreviewProvider {
|
2022-12-10 02:01:59 +00:00
|
|
|
static var previews: some View {
|
2022-12-11 11:38:57 +00:00
|
|
|
NavigationView {
|
|
|
|
SubscriptionsView()
|
|
|
|
}
|
2022-12-10 02:01:59 +00:00
|
|
|
}
|
|
|
|
}
|