Add an option to switch between flatten/grouped library view

By default, a library shows its items in a flatten view. This patch
further adds an option that allows users to show items grouped in their
own folders as well.
This commit is contained in:
Min-Yih Hsu 2022-01-28 09:59:31 +08:00
parent f84d796536
commit e760a586d7
6 changed files with 18 additions and 4 deletions

View File

@ -324,6 +324,8 @@ internal enum L10n {
internal static var settings: String { return L10n.tr("Localizable", "settings") }
/// Show Cast & Crew
internal static var showCastAndCrew: String { return L10n.tr("Localizable", "showCastAndCrew") }
/// Show Flatten Library View
internal static var showFlattenView: String { return L10n.tr("Localizable", "showFlattenView") }
/// Show Missing Episodes
internal static var showMissingEpisodes: String { return L10n.tr("Localizable", "showMissingEpisodes") }
/// Show Missing Seasons

View File

@ -41,6 +41,7 @@ extension Defaults.Keys {
// Customize settings
static let showPosterLabels = Key<Bool>("showPosterLabels", default: true, suite: SwiftfinStore.Defaults.generalSuite)
static let showCastAndCrew = Key<Bool>("showCastAndCrew", default: true, suite: SwiftfinStore.Defaults.generalSuite)
static let showFlattenView = Key<Bool>("showFlattenView", default: true, suite: SwiftfinStore.Defaults.generalSuite)
// Video player / overlay settings
static let overlayType = Key<OverlayType>("overlayType", default: .normal, suite: SwiftfinStore.Defaults.generalSuite)

View File

@ -7,6 +7,7 @@
//
import Combine
import Defaults
import Foundation
import JellyfinAPI
import SwiftUICollection
@ -94,10 +95,16 @@ final class LibraryViewModel: ViewModel {
genreIDs = filters.withGenres.compactMap(\.id)
}
let sortBy = filters.sortBy.map(\.rawValue)
let queryRecursive = filters.filters.contains(.isFavorite) ||
let queryRecursive = Defaults[.showFlattenView] || filters.filters.contains(.isFavorite) ||
self.person != nil ||
self.genre != nil ||
self.studio != nil
let includeItemTypes: [String]
if filters.filters.contains(.isFavorite) {
includeItemTypes = ["Movie", "Series", "Season", "Episode", "BoxSet"]
} else {
includeItemTypes = ["Movie", "Series", "BoxSet"] + (Defaults[.showFlattenView] ? [] : ["Folder"])
}
ItemsAPI.getItemsByUserId(userId: SessionManager.main.currentLogin.user.id, startIndex: currentPage * pageItemSize,
limit: pageItemSize,
@ -114,9 +121,7 @@ final class LibraryViewModel: ViewModel {
.people,
.chapters,
],
includeItemTypes: filters.filters
.contains(.isFavorite) ? ["Movie", "Series", "Season", "Episode", "BoxSet"] :
["Movie", "Series", "BoxSet", "Folder"],
includeItemTypes: includeItemTypes,
filters: filters.filters,
sortBy: sortBy,
tags: filters.tags,

View File

@ -15,6 +15,8 @@ struct CustomizeViewsSettings: View {
var showPosterLabels
@Default(.showCastAndCrew)
var showCastAndCrew
@Default(.showFlattenView)
var showFlattenView
var body: some View {
Form {
@ -24,6 +26,7 @@ struct CustomizeViewsSettings: View {
// TODO: Uncomment when cast and crew implemented in item views
// Toggle(L10n.showCastAndCrew, isOn: $showCastAndCrew)
Toggle(L10n.showFlattenView, isOn: $showFlattenView)
} header: {
L10n.customize.text

View File

@ -15,6 +15,8 @@ struct CustomizeViewsSettings: View {
var showPosterLabels
@Default(.showCastAndCrew)
var showCastAndCrew
@Default(.showFlattenView)
var showFlattenView
var body: some View {
Form {
@ -22,6 +24,7 @@ struct CustomizeViewsSettings: View {
Toggle(L10n.showPosterLabels, isOn: $showPosterLabels)
Toggle(L10n.showCastAndCrew, isOn: $showCastAndCrew)
Toggle(L10n.showFlattenView, isOn: $showFlattenView)
} header: {
L10n.customize.text