diff --git a/Model/Channel.swift b/Model/Channel.swift index c623a0d6..7da66f9e 100644 --- a/Model/Channel.swift +++ b/Model/Channel.swift @@ -4,7 +4,7 @@ import Foundation import SwiftyJSON struct Channel: Identifiable, Hashable { - enum ContentType: String, Identifiable { + enum ContentType: String, Identifiable, CaseIterable { case videos case playlists case livestreams @@ -15,6 +15,15 @@ struct Channel: Identifiable, Hashable { rawValue } + var description: String { + switch self { + case .livestreams: + return "Live Streams".localized() + default: + return rawValue.capitalized.localized() + } + } + var contentItemType: ContentItem.ContentType { switch self { case .videos: @@ -29,6 +38,21 @@ struct Channel: Identifiable, Hashable { return .channel } } + + var systemImage: String { + switch self { + case .videos: + return "video" + case .playlists: + return "list.and.film" + case .livestreams: + return "dot.radiowaves.left.and.right" + case .shorts: + return "1.square" + case .channels: + return "person.3" + } + } } struct Tab: Identifiable, Hashable { @@ -80,4 +104,9 @@ struct Channel: Identifiable, Hashable { var contentItem: ContentItem { ContentItem(channel: self) } + + func hasData(for contentType: ContentType) -> Bool { + guard contentType != .videos, contentType != .playlists else { return true } + return tabs.contains(where: { $0.contentType == contentType }) + } } diff --git a/Shared/Views/ChannelVideosView.swift b/Shared/Views/ChannelVideosView.swift index e9117012..cdf44685 100644 --- a/Shared/Views/ChannelVideosView.swift +++ b/Shared/Views/ChannelVideosView.swift @@ -289,17 +289,10 @@ struct ChannelVideosView: View { private var contentTypePicker: some View { Picker("Content type", selection: $contentType) { if let channel = presentedChannel { - Text("Videos").tag(Channel.ContentType.videos) - Text("Playlists").tag(Channel.ContentType.playlists) - - if channel.tabs.contains(where: { $0.contentType == .livestreams }) { - Text("Live streams").tag(Channel.ContentType.livestreams) - } - if channel.tabs.contains(where: { $0.contentType == .shorts }) { - Text("Shorts").tag(Channel.ContentType.shorts) - } - if channel.tabs.contains(where: { $0.contentType == .channels }) { - Text("Channels").tag(Channel.ContentType.channels) + ForEach(Channel.ContentType.allCases, id: \.self) { type in + if channel.hasData(for: type) { + Label(type.description, systemImage: type.systemImage).tag(type) + } } } }