2022-12-11 17:08:57 +05:30
|
|
|
import Defaults
|
2022-12-16 14:05:10 +05:30
|
|
|
import Siesta
|
2022-12-10 07:31:59 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct SubscriptionsView: View {
|
2022-12-11 17:08:57 +05:30
|
|
|
enum Page: String, CaseIterable, Defaults.Serializable {
|
|
|
|
case feed
|
|
|
|
case channels
|
2022-12-10 07:31:59 +05:30
|
|
|
}
|
|
|
|
|
2022-12-11 17:08:57 +05:30
|
|
|
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
|
2022-12-12 05:48:29 +05:30
|
|
|
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
|
2022-12-11 17:08:57 +05:30
|
|
|
|
2022-12-13 05:09:50 +05:30
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
2022-12-16 14:05:10 +05:30
|
|
|
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
2022-12-13 05:09:50 +05:30
|
|
|
|
2022-12-10 07:31:59 +05:30
|
|
|
var body: some View {
|
2022-12-11 03:07:14 +05:30
|
|
|
SignInRequiredView(title: "Subscriptions".localized()) {
|
2022-12-11 17:08:57 +05:30
|
|
|
switch subscriptionsViewPage {
|
|
|
|
case .feed:
|
|
|
|
FeedView()
|
|
|
|
case .channels:
|
|
|
|
ChannelsView()
|
|
|
|
#if os(tvOS)
|
|
|
|
.ignoresSafeArea(.all, edges: .horizontal)
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
2022-12-12 05:48:29 +05:30
|
|
|
.environment(\.listingStyle, subscriptionsListingStyle)
|
2022-12-11 17:08:57 +05:30
|
|
|
#if os(iOS)
|
2022-12-12 05:48:29 +05:30
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
|
|
|
.toolbar {
|
|
|
|
ToolbarItem(placement: .principal) {
|
2023-05-25 20:43:01 +05:30
|
|
|
HStack {
|
|
|
|
Picker("Page", selection: $subscriptionsViewPage) {
|
|
|
|
Label("Feed", systemImage: "film").tag(Page.feed)
|
|
|
|
Label("Channels", systemImage: "person.3.fill").tag(Page.channels)
|
|
|
|
}
|
|
|
|
.pickerStyle(.segmented)
|
2023-05-27 04:32:46 +05:30
|
|
|
.labelStyle(.titleOnly)
|
2023-05-25 20:43:01 +05:30
|
|
|
|
|
|
|
subscriptionsMenu
|
|
|
|
}
|
|
|
|
.frame(maxWidth: 500)
|
2022-12-12 05:48:29 +05:30
|
|
|
}
|
2022-12-16 14:05:10 +05:30
|
|
|
|
|
|
|
ToolbarItem {
|
|
|
|
RequestErrorButton(error: requestError)
|
|
|
|
}
|
2022-12-12 05:48:29 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#if os(macOS)
|
2022-12-11 17:08:57 +05:30
|
|
|
.toolbar {
|
2023-04-22 21:29:28 +05:30
|
|
|
ToolbarItemGroup {
|
2022-12-12 05:48:29 +05:30
|
|
|
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
2023-05-23 22:18:39 +05:30
|
|
|
HideWatchedButtons()
|
2023-05-23 22:24:53 +05:30
|
|
|
HideShortsButtons()
|
2022-12-13 17:44:20 +05:30
|
|
|
toggleWatchedButton
|
2023-04-22 21:29:28 +05:30
|
|
|
.id(feed.watchedId)
|
2022-12-14 03:02:49 +05:30
|
|
|
playUnwatchedButton
|
2023-04-22 21:29:28 +05:30
|
|
|
.id(feed.watchedId)
|
2022-12-14 03:02:49 +05:30
|
|
|
}
|
2022-12-11 17:08:57 +05:30
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
2022-12-11 01:38:03 +05:30
|
|
|
|
2022-12-16 14:05:10 +05:30
|
|
|
var requestError: RequestError? {
|
|
|
|
subscriptionsViewPage == .channels ? subscriptions.error : feed.error
|
|
|
|
}
|
|
|
|
|
2022-12-11 17:08:57 +05:30
|
|
|
#if os(iOS)
|
|
|
|
var subscriptionsMenu: some View {
|
|
|
|
Menu {
|
2022-12-12 05:48:29 +05:30
|
|
|
if subscriptionsViewPage == .feed {
|
|
|
|
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
|
|
|
|
|
2023-05-25 22:24:12 +05:30
|
|
|
Section {
|
|
|
|
HideWatchedButtons()
|
|
|
|
HideShortsButtons()
|
|
|
|
}
|
2023-02-25 21:12:18 +05:30
|
|
|
|
2023-05-25 22:24:12 +05:30
|
|
|
playUnwatchedButton
|
2022-12-13 17:44:20 +05:30
|
|
|
|
2023-05-25 22:24:12 +05:30
|
|
|
toggleWatchedButton
|
|
|
|
}
|
2022-12-13 17:44:20 +05:30
|
|
|
|
2022-12-12 03:45:56 +05:30
|
|
|
Section {
|
|
|
|
SettingsButtons()
|
|
|
|
}
|
2022-12-11 17:08:57 +05:30
|
|
|
} label: {
|
|
|
|
HStack(spacing: 12) {
|
|
|
|
Image(systemName: "chevron.down.circle.fill")
|
|
|
|
.foregroundColor(.accentColor)
|
2023-05-25 20:43:01 +05:30
|
|
|
.imageScale(.large)
|
2022-12-10 07:31:59 +05:30
|
|
|
}
|
2022-12-11 17:08:57 +05:30
|
|
|
.transaction { t in t.animation = nil }
|
2022-12-10 07:31:59 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-12 04:10:08 +05:30
|
|
|
var menuLabel: some View {
|
|
|
|
HStack {
|
|
|
|
Image(systemName: subscriptionsViewPage == .channels ? "person.3.fill" : "film")
|
2022-12-12 05:48:29 +05:30
|
|
|
.imageScale(.small)
|
2022-12-12 04:10:08 +05:30
|
|
|
Text(subscriptionsViewPage.rawValue.capitalized.localized())
|
|
|
|
.font(.headline)
|
|
|
|
}
|
2022-12-10 07:31:59 +05:30
|
|
|
}
|
2022-12-11 17:08:57 +05:30
|
|
|
#endif
|
2022-12-13 17:44:20 +05:30
|
|
|
|
|
|
|
var playUnwatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.playUnwatchedFeed()
|
|
|
|
} label: {
|
|
|
|
Label("Play all unwatched", systemImage: "play")
|
|
|
|
}
|
2024-02-26 18:42:11 +05:30
|
|
|
.help("Play all unwatched")
|
2022-12-13 17:44:20 +05:30
|
|
|
.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")
|
|
|
|
}
|
2024-02-26 18:42:11 +05:30
|
|
|
.help("Mark all as watched")
|
2022-12-13 17:44:20 +05:30
|
|
|
.disabled(!feed.canMarkAllFeedAsWatched)
|
|
|
|
}
|
|
|
|
|
|
|
|
var markAllFeedAsUnwatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.markAllFeedAsUnwatched()
|
|
|
|
} label: {
|
|
|
|
Label("Mark all as unwatched", systemImage: "checkmark.circle")
|
|
|
|
}
|
2024-02-26 18:42:11 +05:30
|
|
|
.help("Mark all as unwatched")
|
2022-12-13 17:44:20 +05:30
|
|
|
}
|
2022-12-10 07:31:59 +05:30
|
|
|
}
|
|
|
|
|
2022-12-11 17:08:57 +05:30
|
|
|
struct SubscriptionsView_Previews: PreviewProvider {
|
2022-12-10 07:31:59 +05:30
|
|
|
static var previews: some View {
|
2022-12-11 17:08:57 +05:30
|
|
|
NavigationView {
|
|
|
|
SubscriptionsView()
|
|
|
|
}
|
2022-12-10 07:31:59 +05:30
|
|
|
}
|
|
|
|
}
|