mirror of
https://github.com/yattee/yattee.git
synced 2025-08-04 01:34:10 +00:00
Add recent documents to home on iOS
This commit is contained in:
@@ -22,10 +22,13 @@ extension Defaults.Keys {
|
||||
static let enableReturnYouTubeDislike = Key<Bool>("enableReturnYouTubeDislike", default: false)
|
||||
|
||||
static let showHome = Key<Bool>("showHome", default: true)
|
||||
static let showDocuments = Key<Bool>("showDocuments", 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)
|
||||
#if os(iOS)
|
||||
static let showDocuments = Key<Bool>("showDocuments", default: false)
|
||||
static let homeRecentDocumentsItems = Key<Int>("homeRecentDocumentsItems", default: 3)
|
||||
#endif
|
||||
static let homeHistoryItems = Key<Int>("homeHistoryItems", default: 10)
|
||||
static let favorites = Key<[FavoriteItem]>("favorites", default: [])
|
||||
|
||||
|
@@ -7,16 +7,7 @@ struct DocumentsView: View {
|
||||
BrowserPlayerControls {
|
||||
ScrollView(.vertical, showsIndicators: false) {
|
||||
if model.directoryContents.isEmpty {
|
||||
VStack(alignment: .center, spacing: 20) {
|
||||
HStack {
|
||||
Image(systemName: "doc")
|
||||
Text("No documents")
|
||||
}
|
||||
Text("Share files from Finder on a Mac\nor iTunes on Windows")
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.foregroundColor(.secondary)
|
||||
NoDocumentsView()
|
||||
} else {
|
||||
ForEach(model.sortedDirectoryContents, id: \.absoluteString) { url in
|
||||
let video = Video.local(model.replacePrivateVar(url) ?? url)
|
||||
|
22
Shared/Documents/NoDocumentsView.swift
Normal file
22
Shared/Documents/NoDocumentsView.swift
Normal file
@@ -0,0 +1,22 @@
|
||||
import SwiftUI
|
||||
|
||||
struct NoDocumentsView: View {
|
||||
var body: some View {
|
||||
VStack(alignment: .center, spacing: 20) {
|
||||
HStack {
|
||||
Image(systemName: "doc")
|
||||
Text("No documents")
|
||||
}
|
||||
Text("Share files from Finder on a Mac\nor iTunes on Windows")
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
.frame(maxWidth: .infinity)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
struct NoDocumentsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
NoDocumentsView()
|
||||
}
|
||||
}
|
36
Shared/Documents/RecentDocumentsView.swift
Normal file
36
Shared/Documents/RecentDocumentsView.swift
Normal file
@@ -0,0 +1,36 @@
|
||||
import Defaults
|
||||
import SwiftUI
|
||||
|
||||
struct RecentDocumentsView: View {
|
||||
var limit = 3
|
||||
let model = DocumentsModel.shared
|
||||
|
||||
var body: some View {
|
||||
LazyVStack {
|
||||
if recentDocuments.isEmpty {
|
||||
NoDocumentsView()
|
||||
} else {
|
||||
ForEach(recentDocuments, id: \.absoluteString) { url in
|
||||
let video = Video.local(model.replacePrivateVar(url) ?? url)
|
||||
PlayerQueueRow(
|
||||
item: PlayerQueueItem(video)
|
||||
)
|
||||
.contextMenu {
|
||||
VideoContextMenuView(video: video)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
.padding(.horizontal, 15)
|
||||
}
|
||||
|
||||
var recentDocuments: [URL] {
|
||||
model.recentDocuments(limit)
|
||||
}
|
||||
}
|
||||
|
||||
struct RecentDocumentsView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
RecentDocumentsView()
|
||||
}
|
||||
}
|
@@ -15,12 +15,18 @@ struct HomeView: View {
|
||||
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
|
||||
var watches: FetchedResults<Watch>
|
||||
@State private var historyID = UUID()
|
||||
#if os(iOS)
|
||||
@State private var recentDocumentsID = UUID()
|
||||
#endif
|
||||
|
||||
var favoritesObserver: Any?
|
||||
|
||||
#if !os(tvOS)
|
||||
@Default(.favorites) private var favorites
|
||||
#endif
|
||||
#if os(iOS)
|
||||
@Default(.homeRecentDocumentsItems) private var homeRecentDocumentsItems
|
||||
#endif
|
||||
@Default(.homeHistoryItems) private var homeHistoryItems
|
||||
@Default(.showFavoritesInHome) private var showFavoritesInHome
|
||||
@Default(.showOpenActionsInHome) private var showOpenActionsInHome
|
||||
@@ -87,10 +93,33 @@ struct HomeView: View {
|
||||
#endif
|
||||
}
|
||||
|
||||
if homeRecentDocumentsItems > 0 {
|
||||
VStack {
|
||||
HStack {
|
||||
sectionLabel("Recent Documents")
|
||||
|
||||
Spacer()
|
||||
|
||||
Button {
|
||||
recentDocumentsID = UUID()
|
||||
} label: {
|
||||
Label("Refresh", systemImage: "arrow.clockwise")
|
||||
.font(.headline)
|
||||
.labelStyle(.iconOnly)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
RecentDocumentsView(limit: homeRecentDocumentsItems)
|
||||
.id(recentDocumentsID)
|
||||
}
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
}
|
||||
|
||||
if homeHistoryItems > 0 {
|
||||
VStack {
|
||||
HStack {
|
||||
Text("History")
|
||||
sectionLabel("History")
|
||||
Spacer()
|
||||
Button {
|
||||
navigation.presentAlert(
|
||||
@@ -108,17 +137,11 @@ struct HomeView: View {
|
||||
Label("Clear History", systemImage: "trash")
|
||||
.font(.headline)
|
||||
.labelStyle(.iconOnly)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 40)
|
||||
#else
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
.font(.title3.bold())
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.foregroundColor(.secondary)
|
||||
|
||||
HistoryView(limit: homeHistoryItems)
|
||||
.id(historyID)
|
||||
@@ -157,9 +180,21 @@ struct HomeView: View {
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
func sectionLabel(_ label: String) -> some View {
|
||||
Text(label)
|
||||
#if os(tvOS)
|
||||
.padding(.horizontal, 40)
|
||||
#else
|
||||
.padding(.horizontal, 15)
|
||||
#endif
|
||||
.font(.title3.bold())
|
||||
.frame(maxWidth: .infinity, alignment: .leading)
|
||||
.foregroundColor(.secondary)
|
||||
}
|
||||
}
|
||||
|
||||
struct Favorites_Previews: PreviewProvider {
|
||||
struct Home_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
TabView {
|
||||
HomeView()
|
||||
|
@@ -8,6 +8,7 @@ struct BrowsingSettings: View {
|
||||
#endif
|
||||
@Default(.accountPickerDisplaysAnonymousAccounts) private var accountPickerDisplaysAnonymousAccounts
|
||||
#if os(iOS)
|
||||
@Default(.homeRecentDocumentsItems) private var homeRecentDocumentsItems
|
||||
@Default(.lockPortraitWhenBrowsing) private var lockPortraitWhenBrowsing
|
||||
#endif
|
||||
@Default(.thumbnailsQuality) private var thumbnailsQuality
|
||||
@@ -24,6 +25,9 @@ struct BrowsingSettings: View {
|
||||
@EnvironmentObject<AccountsModel> private var accounts
|
||||
|
||||
@State private var homeHistoryItemsText = ""
|
||||
#if os(iOS)
|
||||
@State private var homeRecentDocumentsItemsText = ""
|
||||
#endif
|
||||
#if os(macOS)
|
||||
@State private var presentingEditFavoritesSheet = false
|
||||
#endif
|
||||
@@ -87,6 +91,22 @@ struct BrowsingSettings: View {
|
||||
}
|
||||
.multilineTextAlignment(.trailing)
|
||||
|
||||
HStack {
|
||||
Text("Recent documents")
|
||||
TextField("Recent documents", text: $homeRecentDocumentsItemsText)
|
||||
.labelsHidden()
|
||||
#if !os(macOS)
|
||||
.keyboardType(.numberPad)
|
||||
#endif
|
||||
.onAppear {
|
||||
homeRecentDocumentsItemsText = String(homeRecentDocumentsItems)
|
||||
}
|
||||
.onChange(of: homeRecentDocumentsItemsText) { newValue in
|
||||
homeRecentDocumentsItems = Int(newValue) ?? 3
|
||||
}
|
||||
}
|
||||
.multilineTextAlignment(.trailing)
|
||||
|
||||
if !accounts.isEmpty {
|
||||
Toggle("Show Favorites", isOn: $showFavoritesInHome)
|
||||
|
||||
|
Reference in New Issue
Block a user