mirror of
https://github.com/yattee/yattee.git
synced 2024-11-09 15:58:20 +00:00
Setting for app tab navigation section
This commit is contained in:
parent
3ca2105b9b
commit
278c4cad69
@ -57,6 +57,10 @@ extension Defaults.Keys {
|
||||
|
||||
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
|
||||
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
|
||||
|
||||
#if os(iOS)
|
||||
static let tabNavigationSection = Key<TabNavigationSectionSetting>("tabNavigationSection", default: .trending)
|
||||
#endif
|
||||
}
|
||||
|
||||
enum ResolutionSetting: String, CaseIterable, Defaults.Serializable {
|
||||
@ -92,3 +96,9 @@ enum PlayerSidebarSetting: String, CaseIterable, Defaults.Serializable {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
enum TabNavigationSectionSetting: String, Defaults.Serializable {
|
||||
case trending, popular
|
||||
}
|
||||
#endif
|
||||
|
@ -25,6 +25,8 @@ struct FavoriteItemView: View {
|
||||
}
|
||||
|
||||
var body: some View {
|
||||
Group {
|
||||
if isVisible {
|
||||
VStack(alignment: .leading, spacing: 2) {
|
||||
Text(label)
|
||||
.font(.title3.bold())
|
||||
@ -63,6 +65,19 @@ struct FavoriteItemView: View {
|
||||
)
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private var isVisible: Bool {
|
||||
switch item.section {
|
||||
case .subscriptions:
|
||||
return accounts.app.supportsSubscriptions
|
||||
case .popular:
|
||||
return accounts.app.supportsPopular
|
||||
default:
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
private var resource: Resource? {
|
||||
switch item.section {
|
||||
|
@ -8,6 +8,8 @@ struct AppTabNavigation: View {
|
||||
@EnvironmentObject<RecentsModel> private var recents
|
||||
@EnvironmentObject<SearchModel> private var search
|
||||
|
||||
@Default(.tabNavigationSection) private var tabNavigationSection
|
||||
|
||||
var body: some View {
|
||||
TabView(selection: navigation.tabSelectionBinding) {
|
||||
NavigationView {
|
||||
@ -20,7 +22,7 @@ struct AppTabNavigation: View {
|
||||
}
|
||||
.tag(TabSelection.favorites)
|
||||
|
||||
if accounts.app.supportsSubscriptions {
|
||||
if subscriptionsVisible {
|
||||
NavigationView {
|
||||
LazyView(SubscriptionsView())
|
||||
.toolbar { toolbarContent }
|
||||
@ -32,28 +34,20 @@ struct AppTabNavigation: View {
|
||||
.tag(TabSelection.subscriptions)
|
||||
}
|
||||
|
||||
// TODO: reenable with settings
|
||||
if accounts.app.supportsPopular && false {
|
||||
NavigationView {
|
||||
LazyView(PopularView())
|
||||
.toolbar { toolbarContent }
|
||||
if subscriptionsVisible {
|
||||
if accounts.app.supportsPopular {
|
||||
if tabNavigationSection == .popular {
|
||||
popularNavigationView
|
||||
} else {
|
||||
trendingNavigationView
|
||||
}
|
||||
.tabItem {
|
||||
Label("Popular", systemImage: "chart.bar")
|
||||
.accessibility(label: Text("Popular"))
|
||||
}
|
||||
.tag(TabSelection.popular)
|
||||
} else {
|
||||
if accounts.app.supportsPopular {
|
||||
popularNavigationView
|
||||
}
|
||||
|
||||
NavigationView {
|
||||
LazyView(TrendingView())
|
||||
.toolbar { toolbarContent }
|
||||
trendingNavigationView
|
||||
}
|
||||
.tabItem {
|
||||
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
|
||||
.accessibility(label: Text("Trending"))
|
||||
}
|
||||
.tag(TabSelection.trending)
|
||||
|
||||
if accounts.app.supportsUserPlaylists {
|
||||
NavigationView {
|
||||
@ -125,6 +119,34 @@ struct AppTabNavigation: View {
|
||||
}
|
||||
}
|
||||
|
||||
private var subscriptionsVisible: Bool {
|
||||
accounts.app.supportsSubscriptions && !(accounts.current?.anonymous ?? true)
|
||||
}
|
||||
|
||||
private var popularNavigationView: some View {
|
||||
NavigationView {
|
||||
LazyView(PopularView())
|
||||
.toolbar { toolbarContent }
|
||||
}
|
||||
.tabItem {
|
||||
Label("Popular", systemImage: "chart.bar")
|
||||
.accessibility(label: Text("Popular"))
|
||||
}
|
||||
.tag(TabSelection.popular)
|
||||
}
|
||||
|
||||
private var trendingNavigationView: some View {
|
||||
NavigationView {
|
||||
LazyView(TrendingView())
|
||||
.toolbar { toolbarContent }
|
||||
}
|
||||
.tabItem {
|
||||
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
|
||||
.accessibility(label: Text("Trending"))
|
||||
}
|
||||
.tag(TabSelection.trending)
|
||||
}
|
||||
|
||||
private var playerNavigationLink: some View {
|
||||
NavigationLink(isActive: $player.playerNavigationLinkActive, destination: {
|
||||
VideoPlayerView()
|
||||
|
@ -85,6 +85,7 @@ struct ContentView: View {
|
||||
}
|
||||
.sheet(isPresented: $navigation.presentingPlaylistForm) {
|
||||
PlaylistFormView(playlist: $navigation.editedPlaylist)
|
||||
.environmentObject(accounts)
|
||||
.environmentObject(playlists)
|
||||
}
|
||||
.sheet(isPresented: $navigation.presentingSettings, onDismiss: openWelcomeScreenIfAccountEmpty) {
|
||||
|
@ -8,15 +8,17 @@ final class PlayerViewController: UIViewController {
|
||||
var playerModel: PlayerModel!
|
||||
var playerViewController = AVPlayerViewController()
|
||||
|
||||
#if !os(tvOS)
|
||||
var aspectRatio: Double? {
|
||||
let ratio = Double(playerViewController.videoBounds.width) / Double(playerViewController.videoBounds.height)
|
||||
|
||||
if !ratio.isFinite {
|
||||
return VideoPlayerView.defaultAspectRatio
|
||||
guard ratio.isFinite else {
|
||||
return VideoPlayerView.defaultAspectRatio // swiftlint:disable:this implicit_return
|
||||
}
|
||||
|
||||
return [ratio, 1.0].max()!
|
||||
}
|
||||
#endif
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
@ -14,7 +14,7 @@ struct PlaylistFormView: View {
|
||||
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
@EnvironmentObject<InvidiousAPI> private var api
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
@EnvironmentObject<PlaylistsModel> private var playlists
|
||||
|
||||
var editing: Bool {
|
||||
@ -185,7 +185,7 @@ struct PlaylistFormView: View {
|
||||
}
|
||||
|
||||
var resource: Resource? {
|
||||
editing ? api.playlist(playlist.id) : api.playlists
|
||||
editing ? accounts.api.playlist(playlist.id) : accounts.api.playlists
|
||||
}
|
||||
|
||||
var visibilityFormItem: some View {
|
||||
@ -230,7 +230,7 @@ struct PlaylistFormView: View {
|
||||
}
|
||||
|
||||
func deletePlaylistAndDismiss() {
|
||||
api.playlist(playlist.id)?.request(.delete).onSuccess { _ in
|
||||
accounts.api.playlist(playlist.id)?.request(.delete).onSuccess { _ in
|
||||
playlist = nil
|
||||
playlists.load(force: true)
|
||||
dismiss()
|
||||
|
@ -51,16 +51,20 @@ struct PlaylistsView: View {
|
||||
#if os(tvOS)
|
||||
.fullScreenCover(isPresented: $showingNewPlaylist, onDismiss: selectCreatedPlaylist) {
|
||||
PlaylistFormView(playlist: $createdPlaylist)
|
||||
.environmentObject(accounts)
|
||||
}
|
||||
.fullScreenCover(isPresented: $showingEditPlaylist, onDismiss: selectEditedPlaylist) {
|
||||
PlaylistFormView(playlist: $editedPlaylist)
|
||||
.environmentObject(accounts)
|
||||
}
|
||||
#else
|
||||
.sheet(isPresented: $showingNewPlaylist, onDismiss: selectCreatedPlaylist) {
|
||||
PlaylistFormView(playlist: $createdPlaylist)
|
||||
.environmentObject(accounts)
|
||||
}
|
||||
.sheet(isPresented: $showingEditPlaylist, onDismiss: selectEditedPlaylist) {
|
||||
PlaylistFormView(playlist: $editedPlaylist)
|
||||
.environmentObject(accounts)
|
||||
}
|
||||
#endif
|
||||
.toolbar {
|
||||
|
@ -4,11 +4,18 @@ import SwiftUI
|
||||
struct BrowsingSettings: View {
|
||||
@Default(.channelOnThumbnail) private var channelOnThumbnail
|
||||
@Default(.timeOnThumbnail) private var timeOnThumbnail
|
||||
#if os(iOS)
|
||||
@Default(.tabNavigationSection) private var tabNavigationSection
|
||||
#endif
|
||||
|
||||
var body: some View {
|
||||
Section(header: SettingsHeader(text: "Thumbnails")) {
|
||||
Section(header: SettingsHeader(text: "Browsing"), footer: footer) {
|
||||
Toggle("Display channel names on thumbnails", isOn: $channelOnThumbnail)
|
||||
Toggle("Display video length on thumbnails", isOn: $timeOnThumbnail)
|
||||
|
||||
#if os(iOS)
|
||||
preferredTabPicker
|
||||
#endif
|
||||
}
|
||||
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
|
||||
|
||||
@ -16,6 +23,23 @@ struct BrowsingSettings: View {
|
||||
Spacer()
|
||||
#endif
|
||||
}
|
||||
|
||||
var footer: some View {
|
||||
#if os(iOS)
|
||||
Text("This tab will be displayed when there is no space to display all tabs")
|
||||
#else
|
||||
EmptyView()
|
||||
#endif
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
var preferredTabPicker: some View {
|
||||
Picker("Preferred tab", selection: $tabNavigationSection) {
|
||||
Text("Trending").tag(TabNavigationSectionSetting.trending)
|
||||
Text("Popular").tag(TabNavigationSectionSetting.popular)
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
struct BrowsingSettings_Previews: PreviewProvider {
|
||||
|
@ -43,8 +43,13 @@ struct EditFavorites: View {
|
||||
.padding(20)
|
||||
|
||||
ForEach(model.addableItems()) { item in
|
||||
HStack {
|
||||
HStack {
|
||||
Text(label(item))
|
||||
Spacer()
|
||||
Text("only with Invidious")
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
|
||||
Spacer()
|
||||
|
||||
@ -52,6 +57,7 @@ struct EditFavorites: View {
|
||||
model.add(item)
|
||||
} label: {
|
||||
Label("Add to Favorites", systemImage: "heart")
|
||||
.font(.system(size: 30))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user