Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter Toggles [iOS] [iPadOS] #847

Merged
merged 11 commits into from
Sep 20, 2023
8 changes: 8 additions & 0 deletions Shared/Services/SwiftfinDefaults.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ extension Defaults.Keys {
static let showFavorites: Key<Bool> = .init("libraryShowFavorites", default: true, suite: .generalSuite)
static let viewType = Key<LibraryViewType>("libraryViewType", default: .grid, suite: .generalSuite)
}

enum Filters {

static let showGenres: Key<Bool> = .init("showGenres", default: true, suite: .generalSuite)
static let showFilters: Key<Bool> = .init("showFilters", default: true, suite: .generalSuite)
static let showOrder: Key<Bool> = .init("showOrder", default: true, suite: .generalSuite)
static let showSort: Key<Bool> = .init("showSort", default: true, suite: .generalSuite)
}
}

enum VideoPlayer {
Expand Down
113 changes: 68 additions & 45 deletions Swiftfin/Components/FilterDrawerHStack/FilterDrawerHStack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,68 +7,91 @@
//

import JellyfinAPI
import Defaults
import SwiftUI

struct FilterDrawerHStack: View {

@Default(.Customization.Filters.showGenres)
private var filterShowGenres

@Default(.Customization.Filters.showFilters)
private var filterShowFilters

@Default(.Customization.Filters.showOrder)
private var filterShowOrder

@Default(.Customization.Filters.showSort)
private var filterShowSort

@ObservedObject
private var viewModel: FilterViewModel

private var onSelect: (FilterCoordinator.Parameters) -> Void

var body: some View {
HStack {
if viewModel.currentFilters.hasFilters {
Menu {
Button(role: .destructive) {
viewModel.currentFilters = .init()
if filterShowGenres || filterShowFilters || filterShowOrder || filterShowSort {
HStack {
if viewModel.currentFilters.hasFilters {
Menu {
Button(role: .destructive) {
viewModel.currentFilters = .init()
} label: {
L10n.reset.text
}
} label: {
L10n.reset.text
FilterDrawerButton(systemName: "line.3.horizontal.decrease.circle.fill", activated: true)
}
} label: {
FilterDrawerButton(systemName: "line.3.horizontal.decrease.circle.fill", activated: true)
}
}

FilterDrawerButton(title: L10n.genres, activated: viewModel.currentFilters.genres != [])
.onSelect {
onSelect(.init(
title: L10n.genres,
viewModel: viewModel,
filter: \.genres,
selectorType: .multi
))

if filterShowGenres {
FilterDrawerButton(title: L10n.genres, activated: viewModel.currentFilters.genres != [])
.onSelect {
onSelect(.init(
title: L10n.genres,
viewModel: viewModel,
filter: \.genres,
selectorType: .multi
))
}
}

FilterDrawerButton(title: L10n.filters, activated: viewModel.currentFilters.filters != [])
.onSelect {
onSelect(.init(
title: L10n.filters,
viewModel: viewModel,
filter: \.filters,
selectorType: .multi
))

if filterShowFilters {
FilterDrawerButton(title: L10n.filters, activated: viewModel.currentFilters.filters != [])
.onSelect {
onSelect(.init(
title: L10n.filters,
viewModel: viewModel,
filter: \.filters,
selectorType: .multi
))
}
}

FilterDrawerButton(title: L10n.order, activated: viewModel.currentFilters.sortOrder != [APISortOrder.ascending.filter])
.onSelect {
onSelect(.init(
title: L10n.order,
viewModel: viewModel,
filter: \.sortOrder,
selectorType: .single
))

if filterShowOrder {
FilterDrawerButton(title: L10n.order, activated: viewModel.currentFilters.sortOrder != [APISortOrder.ascending.filter])
.onSelect {
onSelect(.init(
title: L10n.order,
viewModel: viewModel,
filter: \.sortOrder,
selectorType: .single
))
}
}

FilterDrawerButton(title: L10n.sort, activated: viewModel.currentFilters.sortBy != [SortBy.name.filter])
.onSelect {
onSelect(.init(
title: L10n.sort,
viewModel: viewModel,
filter: \.sortBy,
selectorType: .single
))

if filterShowSort {
FilterDrawerButton(title: L10n.sort, activated: viewModel.currentFilters.sortBy != [SortBy.name.filter])
.onSelect {
onSelect(.init(
title: L10n.sort,
viewModel: viewModel,
filter: \.sortBy,
selectorType: .single
))
}
}
}
}
}
}
Expand Down
18 changes: 18 additions & 0 deletions Swiftfin/Views/SettingsView/CustomizeViewsSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ struct CustomizeViewsSettings: View {
@Default(.Customization.shouldShowMissingEpisodes)
var shouldShowMissingEpisodes

@Default(.Customization.Filters.showGenres)
var showGenres
@Default(.Customization.Filters.showFilters)
var showFilters
@Default(.Customization.Filters.showOrder)
var showOrder
@Default(.Customization.Filters.showSort)
var showSort

@Default(.Customization.showPosterLabels)
var showPosterLabels
@Default(.Customization.nextUpPosterType)
Expand Down Expand Up @@ -85,6 +94,15 @@ struct CustomizeViewsSettings: View {
L10n.missingItems.text
}

Section {
Toggle(L10n.genres, isOn: $showGenres)
Toggle(L10n.filters, isOn: $showFilters)
Toggle(L10n.order, isOn: $showOrder)
Toggle(L10n.sort, isOn: $showSort)
} header: {
L10n.filters.text
}

Section {

ChevronButton(title: L10n.indicators)
Expand Down