Home settings

This commit is contained in:
Arkadiusz Fal 2022-11-11 21:28:40 +01:00
parent ef1f95a3ad
commit 51bd46b3ae
11 changed files with 202 additions and 139 deletions

View File

@ -4,11 +4,11 @@ import Foundation
struct FavoritesModel {
static let shared = FavoritesModel()
@Default(.showFavoritesInHome) var showFavoritesInHome
@Default(.favorites) var all
@Default(.visibleSections) var visibleSections
var isEnabled: Bool {
visibleSections.contains(.home)
showFavoritesInHome
}
func contains(_ item: FavoriteItem) -> Bool {

View File

@ -21,7 +21,11 @@ extension Defaults.Keys {
static let enableReturnYouTubeDislike = Key<Bool>("enableReturnYouTubeDislike", default: false)
static let homeHistoryItems = Key<Int>("homeHistoryItems", default: 30)
static let showHome = Key<Bool>("showHome", default: true)
static let showOpenActionsInHome = Key<Bool>("showOpenActionsInHome", default: true)
static let showOpenActionsToolbarItem = Key<Bool>("showOpenActionsToolbarItem", default: false)
static let showFavoritesInHome = Key<Bool>("showFavoritesInHome", default: true)
static let homeHistoryItems = Key<Int>("homeHistoryItems", default: 10)
static let favorites = Key<[FavoriteItem]>("favorites", default: [])
#if !os(tvOS)
@ -169,7 +173,7 @@ extension Defaults.Keys {
static let trendingCategory = Key<TrendingCategory>("trendingCategory", default: .default)
static let trendingCountry = Key<Country>("trendingCountry", default: .us)
static let visibleSections = Key<Set<VisibleSection>>("visibleSections", default: [.home])
static let visibleSections = Key<Set<VisibleSection>>("visibleSections", default: [.subscriptions, .trending, .playlists])
#if os(iOS)
static let enterFullscreenInLandscape = Key<Bool>("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone)
@ -234,7 +238,7 @@ enum PlayerSidebarSetting: String, CaseIterable, Defaults.Serializable {
}
enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
case home, subscriptions, popular, trending, playlists
case subscriptions, popular, trending, playlists
var title: String {
rawValue.capitalized.localized()
@ -242,8 +246,6 @@ enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
var tabSelection: TabSelection {
switch self {
case .home:
return TabSelection.home
case .subscriptions:
return TabSelection.subscriptions
case .popular:
@ -257,16 +259,14 @@ enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
private var sortOrder: Int {
switch self {
case .home:
return 0
case .subscriptions:
return 1
return 0
case .popular:
return 2
return 1
case .trending:
return 3
return 2
case .playlists:
return 4
return 3
}
}

View File

@ -18,12 +18,15 @@ struct HomeView: View {
@Default(.favorites) private var favorites
#endif
@Default(.homeHistoryItems) private var homeHistoryItems
@Default(.showFavoritesInHome) private var showFavoritesInHome
@Default(.showOpenActionsInHome) private var showOpenActionsInHome
private var navigation: NavigationModel { .shared }
var body: some View {
BrowserPlayerControls {
ScrollView(.vertical, showsIndicators: false) {
if showOpenActionsInHome {
HStack {
#if os(tvOS)
OpenVideosButton(text: "Open Video", imageSystemName: "globe") {
@ -53,8 +56,9 @@ struct HomeView: View {
#else
.padding(.horizontal, 15)
#endif
}
if !accounts.current.isNil {
if !accounts.current.isNil, showFavoritesInHome {
#if os(tvOS)
ForEach(Defaults[.favorites]) { item in
FavoriteItemView(item: item, dragging: $dragging)
@ -75,6 +79,7 @@ struct HomeView: View {
#endif
}
if homeHistoryItems > 0 {
VStack {
Text("History")
@ -89,6 +94,7 @@ struct HomeView: View {
HistoryView(limit: homeHistoryItems)
}
}
#if !os(tvOS)
Color.clear.padding(.bottom, 60)

View File

@ -5,6 +5,8 @@ import SwiftUI
#endif
struct AppSidebarNavigation: View {
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
@ -75,12 +77,14 @@ struct AppSidebarNavigation: View {
#endif
ToolbarItemGroup(placement: openVideosToolbarItemPlacement) {
if showOpenActionsToolbarItem {
Button {
navigation.presentingOpenVideos = true
} label: {
Label("Open Videos", systemImage: "play.circle.fill")
}
}
}
ToolbarItemGroup(placement: accountsMenuToolbarItemPlacement) {
AccountsMenuView()

View File

@ -13,16 +13,20 @@ struct AppTabNavigation: View {
@EnvironmentObject<SubscriptionsModel> private var subscriptions
@EnvironmentObject<ThumbnailsModel> private var thumbnailsModel
@Default(.showHome) private var showHome
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@Default(.visibleSections) private var visibleSections
let persistenceController = PersistenceController.shared
var body: some View {
TabView(selection: navigation.tabSelectionBinding) {
if visibleSections.contains(.home) {
let tabs = Group {
if showHome {
homeNavigationView
}
if !accounts.isEmpty {
if subscriptionsVisible {
subscriptionsNavigationView
}
@ -39,10 +43,18 @@ struct AppTabNavigation: View {
playlistsNavigationView
}
if !accounts.isEmpty {
searchNavigationView
}
}
if #available(iOS 16, tvOS 16, *) {
tabs
.toolbar(accounts.isEmpty ? .hidden : .visible, for: .tabBar)
} else {
tabs
}
}
.id(accounts.current?.id ?? "")
.overlay(playlistView)
.overlay(channelView)
@ -141,9 +153,11 @@ struct AppTabNavigation: View {
}
ToolbarItemGroup(placement: .navigationBarTrailing) {
if showOpenActionsToolbarItem {
Button(action: { navigation.presentingOpenVideos = true }) {
Label("Open Videos", systemImage: "play.circle.fill")
}
}
AccountsMenuView()
}
}

View File

@ -5,6 +5,7 @@ struct Sidebar: View {
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<NavigationModel> private var navigation
@Default(.showHome) private var showHome
@Default(.visibleSections) private var visibleSections
var body: some View {
@ -40,13 +41,14 @@ struct Sidebar: View {
var mainNavigationLinks: some View {
Section(header: Text("Videos")) {
if visibleSections.contains(.home) {
if showHome {
NavigationLink(destination: LazyView(HomeView()), tag: TabSelection.home, selection: $navigation.tabSelection) {
Label("Home", systemImage: "house")
.accessibility(label: Text("Home"))
}
.id("favorites")
}
if !accounts.isEmpty {
if visibleSections.contains(.subscriptions),
accounts.app.supportsSubscriptions && accounts.signedIn
{
@ -73,7 +75,6 @@ struct Sidebar: View {
.id("trending")
}
if !accounts.isEmpty {
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
Label("Search", systemImage: "magnifyingglass")
.accessibility(label: Text("Search"))

View File

@ -29,6 +29,7 @@ struct SearchView: View {
@Default(.recentlyOpened) private var recentlyOpened
@Default(.saveRecents) private var saveRecents
@Default(.showHome) private var showHome
private var videos = [Video]()
@ -209,13 +210,11 @@ struct SearchView: View {
visibleSections.append(.playlists)
}
[VisibleSection.home, .trending].forEach { section in
if preferred.contains(section) {
visibleSections.append(section)
}
if preferred.contains(.trending) {
visibleSections.append(.trending)
}
return !visibleSections.isEmpty
return !visibleSections.isEmpty || showHome
}
private var results: some View {

View File

@ -13,12 +13,24 @@ struct BrowsingSettings: View {
@Default(.thumbnailsQuality) private var thumbnailsQuality
@Default(.channelOnThumbnail) private var channelOnThumbnail
@Default(.timeOnThumbnail) private var timeOnThumbnail
@Default(.showHome) private var showHome
@Default(.showFavoritesInHome) private var showFavoritesInHome
@Default(.showOpenActionsInHome) private var showOpenActionsInHome
@Default(.showOpenActionsToolbarItem) private var showOpenActionsToolbarItem
@Default(.homeHistoryItems) private var homeHistoryItems
@Default(.visibleSections) private var visibleSections
@EnvironmentObject<AccountsModel> private var accounts
@State private var homeHistoryItemsText = ""
var body: some View {
Group {
#if os(macOS)
VStack(alignment: .leading) {
sections
Spacer()
}
#else
List {
sections
@ -38,14 +50,45 @@ struct BrowsingSettings: View {
private var sections: some View {
Group {
homeSettings
interfaceSettings
if !accounts.isEmpty {
thumbnailsSettings
visibleSectionsSettings
}
}
}
private var homeSettings: some View {
Section(header: SettingsHeader(text: "Home".localized())) {
#if !os(tvOS)
if !accounts.isEmpty {
Toggle("Show Home", isOn: $showHome)
}
#endif
Toggle("Show Open Videos quick actions", isOn: $showOpenActionsInHome)
if !accounts.isEmpty {
Toggle("Show Favorites", isOn: $showFavoritesInHome)
}
HStack {
TextField("Recent history items", text: $homeHistoryItemsText)
#if !os(macOS)
.keyboardType(.URL)
#endif
.onAppear {
homeHistoryItemsText = String(homeHistoryItems)
}
.onChange(of: homeHistoryItemsText) { newValue in
homeHistoryItems = Int(newValue) ?? 10
}
}
.multilineTextAlignment(.trailing)
}
}
private var interfaceSettings: some View {
Section(header: SettingsHeader(text: "Interface".localized())) {
Toggle("Show Open Videos toolbar button", isOn: $showOpenActionsToolbarItem)
#if os(iOS)
Toggle("Lock portrait mode", isOn: $lockPortraitWhenBrowsing)
.onChange(of: lockPortraitWhenBrowsing) { lock in
@ -57,6 +100,7 @@ struct BrowsingSettings: View {
}
#endif
if !accounts.isEmpty {
#if !os(tvOS)
Toggle("Show account username", isOn: $accountPickerDisplaysUsername)
#endif
@ -64,6 +108,7 @@ struct BrowsingSettings: View {
Toggle("Show anonymous accounts", isOn: $accountPickerDisplaysAnonymousAccounts)
}
}
}
private var thumbnailsSettings: some View {
Section(header: SettingsHeader(text: "Thumbnails".localized())) {

View File

@ -34,7 +34,6 @@ struct SettingsView: View {
var settings: some View {
#if os(macOS)
TabView(selection: $selection) {
if !accounts.isEmpty {
Form {
BrowsingSettings()
}
@ -42,7 +41,6 @@ struct SettingsView: View {
Label("Browsing", systemImage: "list.and.film")
}
.tag(Optional(Tabs.browsing))
}
Form {
PlayerSettings()
@ -125,13 +123,11 @@ struct SettingsView: View {
}
#endif
if !accounts.isEmpty {
NavigationLink {
BrowsingSettings()
} label: {
Label("Browsing", systemImage: "list.and.film")
}
}
NavigationLink {
PlayerSettings()
@ -221,9 +217,9 @@ struct SettingsView: View {
private var windowHeight: Double {
switch selection {
case nil:
return accounts.isEmpty ? 680 : 400
return accounts.isEmpty ? 680 : 520
case .browsing:
return 400
return 520
case .player:
return 680
case .quality:
@ -233,7 +229,7 @@ struct SettingsView: View {
case .sponsorBlock:
return 700
case .advanced:
return 650
return 750
case .help:
return 600
}

View File

@ -203,7 +203,7 @@ struct YatteeApp: App {
recents.clear()
}
var section = Defaults[.visibleSections].min()?.tabSelection
var section = Defaults[.showHome] ? TabSelection.home : Defaults[.visibleSections].min()?.tabSelection
#if os(macOS)
if section == .playlists {

View File

@ -13,11 +13,9 @@ struct TVNavigationView: View {
var body: some View {
NavigationView {
TabView(selection: navigation.tabSelectionBinding) {
if visibleSections.contains(.home) {
LazyView(HomeView())
.tabItem { Text("Home") }
.tag(TabSelection.home)
}
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions, accounts.api.signedIn {
LazyView(SubscriptionsView())