Rename Favorites to Home

Fix #329
This commit is contained in:
Arkadiusz Fal
2022-11-09 14:34:04 +01:00
parent e4588478c9
commit dbb7134eb7
16 changed files with 125 additions and 44 deletions

View File

@@ -168,7 +168,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: [.favorites, .subscriptions, .trending, .playlists])
static let visibleSections = Key<Set<VisibleSection>>("visibleSections", default: [.home])
#if os(iOS)
static let enterFullscreenInLandscape = Key<Bool>("enterFullscreenInLandscape", default: UIDevice.current.userInterfaceIdiom == .phone)
@@ -233,7 +233,7 @@ enum PlayerSidebarSetting: String, CaseIterable, Defaults.Serializable {
}
enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
case favorites, subscriptions, popular, trending, playlists
case home, subscriptions, popular, trending, playlists
var title: String {
rawValue.capitalized.localized()
@@ -241,8 +241,8 @@ enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
var tabSelection: TabSelection {
switch self {
case .favorites:
return TabSelection.favorites
case .home:
return TabSelection.home
case .subscriptions:
return TabSelection.subscriptions
case .popular:
@@ -256,7 +256,7 @@ enum VisibleSection: String, CaseIterable, Comparable, Defaults.Serializable {
private var sortOrder: Int {
switch self {
case .favorites:
case .home:
return 0
case .subscriptions:
return 1

View File

@@ -0,0 +1,42 @@
import SwiftUI
struct HistoryView: View {
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
var watches: FetchedResults<Watch>
@EnvironmentObject<PlayerModel> private var player
var limit = 10
var body: some View {
LazyVStack {
ForEach(visibleWatches, id: \.videoID) { watch in
PlayerQueueRow(
item: PlayerQueueItem.from(watch, video: player.historyVideo(watch.videoID)),
history: true
)
.onAppear {
player.loadHistoryVideoDetails(watch.videoID)
}
.contextMenu {
VideoContextMenuView(video: watch.video)
}
}
#if os(tvOS)
.padding(.horizontal, 40)
#else
.padding(.horizontal, 15)
#endif
}
}
private var visibleWatches: [Watch] {
Array(watches.filter { $0.videoID != player.currentVideo?.videoID }.prefix(limit))
}
}
struct HistoryView_Previews: PreviewProvider {
static var previews: some View {
HistoryView()
}
}

View File

@@ -3,7 +3,7 @@ import Siesta
import SwiftUI
import UniformTypeIdentifiers
struct FavoritesView: View {
struct HomeView: View {
@EnvironmentObject<AccountsModel> private var accounts
@EnvironmentObject<PlaylistsModel> private var playlists
@@ -18,6 +18,8 @@ struct FavoritesView: View {
@Default(.favorites) private var favorites
#endif
private var navigation: NavigationModel { .shared }
var body: some View {
BrowserPlayerControls {
ScrollView(.vertical, showsIndicators: false) {
@@ -39,9 +41,38 @@ struct FavoritesView: View {
.padding(.top, item == first && RefreshControl.navigationBarTitleDisplayMode == .inline ? 10 : 0)
#endif
}
Color.clear.padding(.bottom, 30)
#endif
}
VStack {
Text("History")
#if os(tvOS)
.padding(.horizontal, 40)
#else
.padding(.horizontal, 15)
#endif
.font(.title3.bold())
.frame(maxWidth: .infinity, alignment: .leading)
.foregroundColor(.secondary)
HistoryView(limit: 100)
}
#if os(tvOS)
HStack {
Button {
navigation.presentingOpenVideos = true
} label: {
Label("Open Videos...", systemImage: "folder")
.padding(.horizontal, 20)
.padding(.vertical, 10)
}
.buttonStyle(.plain)
}
#else
Color.clear.padding(.bottom, 60)
#endif
}
.onAppear {
Defaults.observe(.favorites) { _ in
@@ -56,7 +87,7 @@ struct FavoritesView: View {
.edgesIgnoringSafeArea(.horizontal)
#else
.onDrop(of: [UTType.text], delegate: DropFavoriteOutside(current: $dragging))
.navigationTitle("Favorites")
.navigationTitle("Home")
#endif
#if os(macOS)
.background(Color.secondaryBackground)
@@ -77,11 +108,11 @@ struct FavoritesView: View {
struct Favorites_Previews: PreviewProvider {
static var previews: some View {
TabView {
FavoritesView()
.overlay(VideoPlayerView().injectFixtureEnvironmentObjects())
HomeView()
// .overlay(VideoPlayerView().injectFixtureEnvironmentObjects())
.injectFixtureEnvironmentObjects()
.tabItem {
Label("a", systemImage: "")
Label("Home", systemImage: "house")
}
}
}

View File

@@ -11,8 +11,8 @@ struct MenuCommands: Commands {
private var navigationMenu: some Commands {
CommandGroup(before: .windowSize) {
Button("Favorites") {
setTabSelection(.favorites)
Button("Home") {
setTabSelection(.home)
}
.keyboardShortcut("1")

View File

@@ -19,8 +19,8 @@ struct AppTabNavigation: View {
var body: some View {
TabView(selection: navigation.tabSelectionBinding) {
if visibleSections.contains(.favorites) {
favoritesNavigationView
if visibleSections.contains(.home) {
homeNavigationView
}
if subscriptionsVisible {
@@ -47,16 +47,16 @@ struct AppTabNavigation: View {
.environment(\.navigationStyle, .tab)
}
private var favoritesNavigationView: some View {
private var homeNavigationView: some View {
NavigationView {
LazyView(FavoritesView())
LazyView(HomeView())
.toolbar { toolbarContent }
}
.tabItem {
Label("Favorites", systemImage: "heart.fill")
.accessibility(label: Text("Favorites"))
Label("Home", systemImage: "house.fill")
.accessibility(label: Text("Home"))
}
.tag(TabSelection.favorites)
.tag(TabSelection.home)
}
private var subscriptionsNavigationView: some View {

View File

@@ -40,10 +40,10 @@ struct Sidebar: View {
var mainNavigationLinks: some View {
Section(header: Text("Videos")) {
if visibleSections.contains(.favorites) {
NavigationLink(destination: LazyView(FavoritesView()), tag: TabSelection.favorites, selection: $navigation.tabSelection) {
Label("Favorites", systemImage: "heart")
.accessibility(label: Text("Favorites"))
if visibleSections.contains(.home) {
NavigationLink(destination: LazyView(HomeView()), tag: TabSelection.home, selection: $navigation.tabSelection) {
Label("Home", systemImage: "house")
.accessibility(label: Text("Home"))
}
.id("favorites")
}

View File

@@ -40,7 +40,7 @@ struct OpenURLHandler {
handleSearchUrlOpen(parser)
case .favorites:
hideViewsAboveBrowser()
navigation.tabSelection = .favorites
navigation.tabSelection = .home
#if os(macOS)
focusMainWindow()
#endif

View File

@@ -209,7 +209,7 @@ struct SearchView: View {
visibleSections.append(.playlists)
}
[VisibleSection.favorites, .trending].forEach { section in
[VisibleSection.home, .trending].forEach { section in
if preferred.contains(section) {
visibleSections.append(section)
}