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

[WIP] [tvOS] Letter Picker #1177

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct LetterPickerBar: View {
var body: some View {
VStack(spacing: 0) {
Spacer()

ForEach(ItemLetter.allCases, id: \.hashValue) { filterLetter in
LetterPickerButton(
letter: filterLetter,
Expand Down
58 changes: 58 additions & 0 deletions Swiftfin tvOS/Components/LetterPickerButton.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// Swiftfin is subject to the terms of the Mozilla Public
// License, v2.0. If a copy of the MPL was not distributed with this
// file, you can obtain one at https://mozilla.org/MPL/2.0/.
//
// Copyright (c) 2024 Jellyfin & Jellyfin Contributors
//

import Defaults
import SwiftUI

extension LetterPickerBar {

struct LetterPickerButton: View {

@Default(.accentColor)
private var accentColor

@Environment(\.isSelected)
private var isSelected

@FocusState
private var isFocused: Bool

private let letter: ItemLetter
private let viewModel: FilterViewModel

init(letter: ItemLetter, viewModel: FilterViewModel) {
self.letter = letter
self.viewModel = viewModel
}

var body: some View {
Button {
if !viewModel.currentFilters.letter.contains(letter) {
viewModel.currentFilters.letter = [ItemLetter(stringLiteral: letter.value)]
} else {
viewModel.currentFilters.letter = []
}
} label: {
ZStack {
RoundedRectangle(cornerRadius: 5)
.foregroundStyle(isFocused ? .lightGray : (isSelected ? accentColor : .clear))
.shadow(color: isFocused || isSelected ? .black : .clear, radius: 2, x: 0, y: 2)
.frame(width: 40, height: 40)
Text(letter.value)
.font(.headline)
.foregroundStyle(isFocused ? .black : (isSelected ? .white : .white))
.shadow(color: isFocused || isSelected ? .clear : .black, radius: 2, x: 0, y: 2)
}
.frame(width: 40, height: 10)
}
.buttonStyle(.borderless)
.focused($isFocused)
.padding(12.5)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ import SwiftUI

struct PagingLibraryView<Element: Poster>: View {

@Default(.Customization.Library.letterPickerEnabled)
private var letterPickerEnabled
@Default(.Customization.Library.letterPickerOrientation)
private var letterPickerOrientation

@Default(.Customization.Library.cinematicBackground)
private var cinematicBackground
@Default(.Customization.Library.posterType)
Expand All @@ -37,6 +42,8 @@ struct PagingLibraryView<Element: Poster>: View {
private var presentBackground = false
@State
private var layout: CollectionVGridLayout
@State
private var safeArea: EdgeInsets = .zero

@StateObject
private var viewModel: PagingLibraryViewModel<Element>
Expand Down Expand Up @@ -146,6 +153,44 @@ struct PagingLibraryView<Element: Poster>: View {

@ViewBuilder
private var contentView: some View {
if letterPickerEnabled, let filterViewModel = viewModel.filterViewModel {
ZStack(alignment: letterPickerOrientation.alignment) {
innerContent
.padding(letterPickerOrientation.edge, 35)
.frame(maxWidth: .infinity)

LetterPickerBar(viewModel: filterViewModel)
.padding(.top, safeArea.top)
.padding(.bottom, safeArea.bottom)
.padding(letterPickerOrientation.edge, 10)
}
} else {
innerContent
}
}

@ViewBuilder
private var innerContent: some View {
WrappedView {
Group {
switch viewModel.state {
case let .error(error):
Text(error.localizedDescription)
case .initial, .refreshing:
ProgressView()
case .content:
if viewModel.elements.isEmpty {
L10n.noResults.text
} else {
gridView
}
}
}
}
}

@ViewBuilder
private var gridView: some View {
CollectionVGrid(
$viewModel.elements,
layout: layout
Expand All @@ -171,23 +216,7 @@ struct PagingLibraryView<Element: Poster>: View {
.visible(presentBackground)
.blurred()
}

WrappedView {
Group {
switch viewModel.state {
case let .error(error):
Text(error.localizedDescription)
case .initial, .refreshing:
ProgressView()
case .content:
if viewModel.elements.isEmpty {
L10n.noResults.text
} else {
contentView
}
}
}
}
contentView
}
.ignoresSafeArea()
.navigationTitle(viewModel.parent?.displayTitle ?? "")
Expand Down
39 changes: 28 additions & 11 deletions Swiftfin tvOS/Views/SettingsView/CustomizeViewsSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ struct CustomizeViewsSettings: View {
@Default(.Customization.shouldShowMissingEpisodes)
private var shouldShowMissingEpisodes

@Default(.Customization.Library.letterPickerEnabled)
var letterPickerEnabled
@Default(.Customization.Library.letterPickerOrientation)
var letterPickerOrientation

@Default(.Customization.showPosterLabels)
private var showPosterLabels
@Default(.Customization.nextUpPosterType)
Expand Down Expand Up @@ -53,6 +58,29 @@ struct CustomizeViewsSettings: View {
}
.contentView {

Section(L10n.library) {

Toggle(L10n.cinematicBackground, isOn: $cinematicBackground)

Toggle(L10n.randomImage, isOn: $libraryRandomImage)

Toggle(L10n.showFavorites, isOn: $showFavorites)

Toggle(L10n.showRecentlyAdded, isOn: $showRecentlyAdded)
}

Section {

Toggle(L10n.letterPicker, isOn: $letterPickerEnabled)

if letterPickerEnabled {
InlineEnumToggle(title: L10n.orientation, selection: $letterPickerOrientation)
}

} header: {
L10n.filters.text
}

Section(L10n.missingItems) {

Toggle(L10n.showMissingSeasons, isOn: $shouldShowMissingSeasons)
Expand Down Expand Up @@ -81,17 +109,6 @@ struct CustomizeViewsSettings: View {

InlineEnumToggle(title: L10n.library, selection: $libraryViewType)
}

Section(L10n.library) {

Toggle(L10n.cinematicBackground, isOn: $cinematicBackground)

Toggle(L10n.randomImage, isOn: $libraryRandomImage)

Toggle(L10n.showFavorites, isOn: $showFavorites)

Toggle(L10n.showRecentlyAdded, isOn: $showRecentlyAdded)
}
}
.withDescriptionTopPadding()
.navigationTitle(L10n.customize)
Expand Down
40 changes: 19 additions & 21 deletions Swiftfin.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
091B5A8A2683142E00D78B61 /* ServerDiscovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A872683142E00D78B61 /* ServerDiscovery.swift */; };
091B5A8D268315D400D78B61 /* ServerDiscovery.swift in Sources */ = {isa = PBXBuildFile; fileRef = 091B5A872683142E00D78B61 /* ServerDiscovery.swift */; };
4E16FD512C0183DB00110147 /* LetterPickerButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD502C0183DB00110147 /* LetterPickerButton.swift */; };
4E16FD532C01840C00110147 /* LetterPickerBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD522C01840C00110147 /* LetterPickerBar.swift */; };
4E16FD572C01A32700110147 /* LetterPickerOrientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD562C01A32700110147 /* LetterPickerOrientation.swift */; };
4E16FD582C01A32700110147 /* LetterPickerOrientation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD562C01A32700110147 /* LetterPickerOrientation.swift */; };
4E204E592C574FD9004D22A2 /* CustomizeSettingsCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E204E582C574FD9004D22A2 /* CustomizeSettingsCoordinator.swift */; };
Expand All @@ -21,6 +20,9 @@
4E73E2B02C4211CA002D2A78 /* MaximumBitrateSettingsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E73E2AF2C4211CA002D2A78 /* MaximumBitrateSettingsView.swift */; };
4E762AAE2C3A1A95004D1579 /* PlaybackBitrate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E762AAD2C3A1A95004D1579 /* PlaybackBitrate.swift */; };
4E762AAF2C3A1A95004D1579 /* PlaybackBitrate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E762AAD2C3A1A95004D1579 /* PlaybackBitrate.swift */; };
4E7B41222C6328720008E5AC /* LetterPickerButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E7B41212C6328720008E5AC /* LetterPickerButton.swift */; };
4E7B41232C6328950008E5AC /* LetterPickerBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD522C01840C00110147 /* LetterPickerBar.swift */; };
4E7B41252C6328C10008E5AC /* LetterPickerBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E16FD522C01840C00110147 /* LetterPickerBar.swift */; };
4E8B34EA2AB91B6E0018F305 /* ItemFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8B34E92AB91B6E0018F305 /* ItemFilter.swift */; };
4E8B34EB2AB91B6E0018F305 /* ItemFilter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4E8B34E92AB91B6E0018F305 /* ItemFilter.swift */; };
531690E7267ABD79005D8AB9 /* HomeView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 531690E6267ABD79005D8AB9 /* HomeView.swift */; };
Expand Down Expand Up @@ -943,6 +945,7 @@
4E73E2AD2C420207002D2A78 /* MaximumBitrateSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaximumBitrateSettingsView.swift; sourceTree = "<group>"; };
4E73E2AF2C4211CA002D2A78 /* MaximumBitrateSettingsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MaximumBitrateSettingsView.swift; sourceTree = "<group>"; };
4E762AAD2C3A1A95004D1579 /* PlaybackBitrate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PlaybackBitrate.swift; sourceTree = "<group>"; };
4E7B41212C6328720008E5AC /* LetterPickerButton.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LetterPickerButton.swift; sourceTree = "<group>"; };
4E8B34E92AB91B6E0018F305 /* ItemFilter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ItemFilter.swift; sourceTree = "<group>"; };
531690E6267ABD79005D8AB9 /* HomeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HomeView.swift; sourceTree = "<group>"; };
531AC8BE26750DE20091C7EB /* ImageView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1666,30 +1669,22 @@
path = ServerDiscovery;
sourceTree = "<group>";
};
4E16FD4E2C0183B500110147 /* LetterPickerBar */ = {
isa = PBXGroup;
children = (
4E16FD4F2C0183C500110147 /* Components */,
4E16FD522C01840C00110147 /* LetterPickerBar.swift */,
);
path = LetterPickerBar;
sourceTree = "<group>";
};
4E16FD4F2C0183C500110147 /* Components */ = {
4E3A785D2C3B87A400D33C11 /* PlaybackBitrate */ = {
isa = PBXGroup;
children = (
4E16FD502C0183DB00110147 /* LetterPickerButton.swift */,
4E762AAD2C3A1A95004D1579 /* PlaybackBitrate.swift */,
4E73E2A52C41CFD3002D2A78 /* PlaybackBitrateTestSize.swift */,
);
path = Components;
path = PlaybackBitrate;
sourceTree = "<group>";
};
4E3A785D2C3B87A400D33C11 /* PlaybackBitrate */ = {
4E7B41242C6328A80008E5AC /* LetterPicker */ = {
isa = PBXGroup;
children = (
4E762AAD2C3A1A95004D1579 /* PlaybackBitrate.swift */,
4E73E2A52C41CFD3002D2A78 /* PlaybackBitrateTestSize.swift */,
4E16FD522C01840C00110147 /* LetterPickerBar.swift */,
4E16FD562C01A32700110147 /* LetterPickerOrientation.swift */,
);
path = PlaybackBitrate;
path = LetterPicker;
sourceTree = "<group>";
};
5310694F2684E7EE00CFFDBA /* VideoPlayer */ = {
Expand Down Expand Up @@ -1868,9 +1863,9 @@
E1763A652BF3CA83004DF6AB /* FullScreenMenu.swift */,
E1549677296CB22B00C4EF88 /* InlineEnumToggle.swift */,
E1A42E5028CBE44500A14DCB /* LandscapePosterProgressBar.swift */,
4E7B41212C6328720008E5AC /* LetterPickerButton.swift */,
E1763A632BF3C9AA004DF6AB /* ListRowButton.swift */,
E10E842B29A589860064EA49 /* NonePosterButton.swift */,
E111D8F928D0400900400001 /* PagingLibraryView.swift */,
E1C92617288756BD002A7A66 /* PosterButton.swift */,
E1C92619288756BD002A7A66 /* PosterHStack.swift */,
E12CC1C428D12D9B00678D5D /* SeeAllPosterButton.swift */,
Expand Down Expand Up @@ -2104,7 +2099,7 @@
E178B0752BE435D70023651B /* HourMinutePicker.swift */,
E1DC7AC92C63337C00AEE368 /* iOS15View.swift */,
E1FE69A928C29CC20021BC93 /* LandscapePosterProgressBar.swift */,
4E16FD4E2C0183B500110147 /* LetterPickerBar */,
4E16FD502C0183DB00110147 /* LetterPickerButton.swift */,
E1A8FDEB2C0574A800D0A51C /* ListRow.swift */,
E1AEFA362BE317E200CFAFD8 /* ListRowButton.swift */,
E1FE69AF28C2DA4A0021BC93 /* NavigationBarFilterDrawer */,
Expand Down Expand Up @@ -2602,6 +2597,7 @@
E193D54E271942C000900D82 /* ItemView */,
E158C8D02A31947500C527C5 /* MediaSourceInfoView.swift */,
E103DF932BCF31C5000229B2 /* MediaView */,
E111D8F928D0400900400001 /* PagingLibraryView.swift */,
E10231572BCF8AF8009D71FC /* ProgramsView */,
E10B1E8C2BD7708900A92EAF /* QuickConnectView.swift */,
E1E1643928BAC2EF00323B0A /* SearchView.swift */,
Expand Down Expand Up @@ -3235,7 +3231,7 @@
E145EB212BDCCA43003BF6F3 /* BulletedList.swift */,
E1153DCB2BBB633B00424D36 /* FastSVGView.swift */,
531AC8BE26750DE20091C7EB /* ImageView.swift */,
4E16FD562C01A32700110147 /* LetterPickerOrientation.swift */,
4E7B41242C6328A80008E5AC /* LetterPicker */,
E1D37F472B9C648E00343D2B /* MaxHeightText.swift */,
E1DC983F296DEBA500982F06 /* PosterIndicators */,
E1FE69A628C29B720021BC93 /* ProgressBar.swift */,
Expand Down Expand Up @@ -4112,6 +4108,7 @@
091B5A8D268315D400D78B61 /* ServerDiscovery.swift in Sources */,
E1575E66293E77B5001665B1 /* Poster.swift in Sources */,
E18E021F2887492B0022598C /* SystemImageContentView.swift in Sources */,
4E7B41232C6328950008E5AC /* LetterPickerBar.swift in Sources */,
E19D41B42BF2C0020082B8B2 /* StoredValues+Temp.swift in Sources */,
E11BDF7B2B85529D0045C54A /* SupportedCaseIterable.swift in Sources */,
4E204E592C574FD9004D22A2 /* CustomizeSettingsCoordinator.swift in Sources */,
Expand Down Expand Up @@ -4230,6 +4227,7 @@
E1FE69A828C29B720021BC93 /* ProgressBar.swift in Sources */,
E1A16C9D2889AF1E00EA4679 /* AboutView.swift in Sources */,
E193D553271943D500900D82 /* tvOSMainTabCoordinator.swift in Sources */,
4E7B41222C6328720008E5AC /* LetterPickerButton.swift in Sources */,
4E8B34EB2AB91B6E0018F305 /* ItemFilter.swift in Sources */,
E174121029AE9D94003EF3B5 /* NavigationCoordinatable.swift in Sources */,
E1763A662BF3CA83004DF6AB /* FullScreenMenu.swift in Sources */,
Expand Down Expand Up @@ -4432,7 +4430,6 @@
6334175B287DDFB9000603CE /* QuickConnectAuthorizeView.swift in Sources */,
E13F05F128BC9016003499D2 /* LibraryRow.swift in Sources */,
E168BD10289A4162001A6922 /* HomeView.swift in Sources */,
4E16FD532C01840C00110147 /* LetterPickerBar.swift in Sources */,
E1BE1CEA2BDB5AFE008176A9 /* UserGridButton.swift in Sources */,
E1401CB129386C9200E8B599 /* UIColor.swift in Sources */,
E1E2F8452B757E3400B75998 /* SinceLastDisappearModifier.swift in Sources */,
Expand Down Expand Up @@ -4674,6 +4671,7 @@
E145EB4D2BE1688E003BF6F3 /* SwiftinStore+UserState.swift in Sources */,
53EE24E6265060780068F029 /* SearchView.swift in Sources */,
E164A8152BE58C2F00A54B18 /* V2AnyData.swift in Sources */,
4E7B41252C6328C10008E5AC /* LetterPickerBar.swift in Sources */,
E1D37F522B9CEF1E00343D2B /* DeviceProfile+SharedCodecProfiles.swift in Sources */,
E1DC9841296DEBD800982F06 /* WatchedIndicator.swift in Sources */,
);
Expand Down