mirror of
https://github.com/yattee/yattee.git
synced 2025-08-05 02:04:07 +00:00
Subscribed channels list in tab navigation
This commit is contained in:
109
Shared/Subscriptions/ChannelsView.swift
Normal file
109
Shared/Subscriptions/ChannelsView.swift
Normal file
@@ -0,0 +1,109 @@
|
||||
import SDWebImageSwiftUI
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelsView: View {
|
||||
@ObservedObject private var subscriptions = SubsribedChannelsModel.shared
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var body: some View {
|
||||
List {
|
||||
Section(header: header) {
|
||||
ForEach(subscriptions.all) { channel in
|
||||
NavigationLink(destination: ChannelVideosView(channel: channel).modifier(PlayerOverlayModifier())) {
|
||||
HStack {
|
||||
if let url = channel.thumbnailURL {
|
||||
ThumbnailView(url: url)
|
||||
.frame(width: 35, height: 35)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 35))
|
||||
Text(channel.name)
|
||||
} else {
|
||||
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 50)
|
||||
#endif
|
||||
|
||||
Color.clear.padding(.bottom, 50)
|
||||
.listRowBackground(Color.clear)
|
||||
.backport
|
||||
.listRowSeparator(false)
|
||||
}
|
||||
}
|
||||
.onAppear {
|
||||
subscriptions.load()
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
subscriptions.load(force: true)
|
||||
}
|
||||
#if os(iOS)
|
||||
.refreshControl { refreshControl in
|
||||
subscriptions.load(force: true) {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
}
|
||||
.backport
|
||||
.refreshable {
|
||||
await subscriptions.load(force: true)
|
||||
}
|
||||
#endif
|
||||
#if !os(tvOS)
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
subscriptions.load(force: true)
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
)
|
||||
#endif
|
||||
#if !os(macOS)
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
subscriptions.load()
|
||||
}
|
||||
#endif
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 30)
|
||||
#endif
|
||||
}
|
||||
|
||||
var header: some View {
|
||||
HStack {
|
||||
#if os(tvOS)
|
||||
SubscriptionsPageButton()
|
||||
#endif
|
||||
|
||||
Spacer()
|
||||
|
||||
CacheStatusHeader(
|
||||
refreshTime: subscriptions.formattedCacheTime,
|
||||
isLoading: subscriptions.isLoading
|
||||
)
|
||||
|
||||
#if os(tvOS)
|
||||
Button {
|
||||
subscriptions.load(force: true)
|
||||
} label: {
|
||||
Label("Refresh", systemImage: "arrow.clockwise")
|
||||
.labelStyle(.iconOnly)
|
||||
.imageScale(.small)
|
||||
.font(.caption2)
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
#if os(tvOS)
|
||||
.padding(.bottom, 15)
|
||||
.padding(.top, 15)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct ChannelsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
ChannelsView()
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,8 +1,8 @@
|
||||
import Foundation
|
||||
import Siesta
|
||||
|
||||
final class SubscriptionsViewModel: ObservableObject {
|
||||
static let shared = SubscriptionsViewModel()
|
||||
final class FeedModel: ObservableObject {
|
||||
static let shared = FeedModel()
|
||||
|
||||
@Published var isLoading = false
|
||||
@Published var videos = [Video]()
|
||||
@@ -114,7 +114,8 @@ final class SubscriptionsViewModel: ObservableObject {
|
||||
}
|
||||
|
||||
private func loadCachedFeed() {
|
||||
let cache = FeedCacheModel.shared.retrieveFeed(account: accounts.current)
|
||||
guard let account = accounts.current else { return }
|
||||
let cache = FeedCacheModel.shared.retrieveFeed(account: account)
|
||||
if !cache.isEmpty {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.videos = cache
|
82
Shared/Subscriptions/FeedView.swift
Normal file
82
Shared/Subscriptions/FeedView.swift
Normal file
@@ -0,0 +1,82 @@
|
||||
import Defaults
|
||||
import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct FeedView: View {
|
||||
@ObservedObject private var feed = FeedModel.shared
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: feed.videos)
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
VerticalCells(items: videos) {
|
||||
HStack {
|
||||
#if os(tvOS)
|
||||
SubscriptionsPageButton()
|
||||
#endif
|
||||
|
||||
Spacer()
|
||||
|
||||
CacheStatusHeader(refreshTime: feed.formattedFeedTime, isLoading: feed.isLoading)
|
||||
|
||||
#if os(tvOS)
|
||||
Button {
|
||||
feed.loadResources(force: true)
|
||||
} label: {
|
||||
Label("Refresh", systemImage: "arrow.clockwise")
|
||||
.labelStyle(.iconOnly)
|
||||
.imageScale(.small)
|
||||
.font(.caption2)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
.padding(.leading, 30)
|
||||
#if os(tvOS)
|
||||
.padding(.bottom, 15)
|
||||
#endif
|
||||
}
|
||||
.environment(\.loadMoreContentHandler) { feed.loadNextPage() }
|
||||
.onAppear {
|
||||
feed.loadResources()
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
feed.reset()
|
||||
feed.loadResources(force: true)
|
||||
}
|
||||
#if os(iOS)
|
||||
.refreshControl { refreshControl in
|
||||
feed.loadResources(force: true) {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
}
|
||||
.backport
|
||||
.refreshable {
|
||||
await feed.loadResources(force: true)
|
||||
}
|
||||
#endif
|
||||
#if !os(tvOS)
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
feed.loadResources(force: true)
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
)
|
||||
#endif
|
||||
#if !os(macOS)
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
feed.loadResources()
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriptonsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NavigationView {
|
||||
FeedView()
|
||||
}
|
||||
}
|
||||
}
|
22
Shared/Subscriptions/SubscriptionsPageButton.swift
Normal file
22
Shared/Subscriptions/SubscriptionsPageButton.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsPageButton: View {
|
||||
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
subscriptionsViewPage = subscriptionsViewPage.next()
|
||||
} label: {
|
||||
Text(subscriptionsViewPage.rawValue.capitalized)
|
||||
.frame(maxWidth: .infinity)
|
||||
.font(.caption2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct SubscriptionsPageButton_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SubscriptionsPageButton()
|
||||
}
|
||||
}
|
@@ -1,78 +1,68 @@
|
||||
import Siesta
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct SubscriptionsView: View {
|
||||
@ObservedObject private var model = SubscriptionsViewModel.shared
|
||||
@ObservedObject private var accounts = AccountsModel.shared
|
||||
|
||||
var videos: [ContentItem] {
|
||||
ContentItem.array(of: model.videos)
|
||||
enum Page: String, CaseIterable, Defaults.Serializable {
|
||||
case feed
|
||||
case channels
|
||||
}
|
||||
|
||||
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
|
||||
|
||||
var body: some View {
|
||||
SignInRequiredView(title: "Subscriptions".localized()) {
|
||||
VerticalCells(items: videos) {
|
||||
HStack {
|
||||
Spacer()
|
||||
|
||||
CacheStatusHeader(refreshTime: model.formattedFeedTime, isLoading: model.isLoading)
|
||||
|
||||
#if os(tvOS)
|
||||
Button {
|
||||
model.loadResources(force: true)
|
||||
} label: {
|
||||
Label("Refresh", systemImage: "arrow.clockwise")
|
||||
.labelStyle(.iconOnly)
|
||||
.imageScale(.small)
|
||||
.font(.caption2)
|
||||
}
|
||||
.padding(.horizontal, 10)
|
||||
#endif
|
||||
}
|
||||
switch subscriptionsViewPage {
|
||||
case .feed:
|
||||
FeedView()
|
||||
case .channels:
|
||||
ChannelsView()
|
||||
#if os(tvOS)
|
||||
.ignoresSafeArea(.all, edges: .horizontal)
|
||||
#endif
|
||||
}
|
||||
.environment(\.loadMoreContentHandler) { model.loadNextPage() }
|
||||
.onAppear {
|
||||
model.loadResources()
|
||||
}
|
||||
.onChange(of: accounts.current) { _ in
|
||||
model.reset()
|
||||
model.loadResources(force: true)
|
||||
}
|
||||
#if os(iOS)
|
||||
.refreshControl { refreshControl in
|
||||
model.loadResources(force: true) {
|
||||
refreshControl.endRefreshing()
|
||||
}
|
||||
}
|
||||
.backport
|
||||
.refreshable {
|
||||
await model.loadResources(force: true)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
.background(
|
||||
Button("Refresh") {
|
||||
model.loadResources(force: true)
|
||||
}
|
||||
.keyboardShortcut("r")
|
||||
.opacity(0)
|
||||
)
|
||||
#endif
|
||||
#if os(iOS)
|
||||
.navigationBarTitleDisplayMode(RefreshControl.navigationBarTitleDisplayMode)
|
||||
#endif
|
||||
#if !os(macOS)
|
||||
.onReceive(NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification)) { _ in
|
||||
model.loadResources()
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .principal) {
|
||||
subscriptionsMenu
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#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)
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 12) {
|
||||
Text(menuLabel)
|
||||
.font(.headline)
|
||||
.foregroundColor(.primary)
|
||||
|
||||
Image(systemName: "chevron.down.circle.fill")
|
||||
.foregroundColor(.accentColor)
|
||||
.imageScale(.small)
|
||||
}
|
||||
.transaction { t in t.animation = nil }
|
||||
}
|
||||
}
|
||||
|
||||
var menuLabel: String {
|
||||
subscriptionsViewPage == .channels ? "Channels" : "Feed"
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
struct SubscriptonsView_Previews: PreviewProvider {
|
||||
struct SubscriptionsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
SubscriptionsView()
|
||||
NavigationView {
|
||||
SubscriptionsView()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user