yattee/Shared/EnvironmentValues.swift

116 lines
2.9 KiB
Swift
Raw Permalink Normal View History

2022-12-12 00:18:29 +00:00
import Defaults
import Foundation
import SwiftUI
2021-10-28 17:14:55 +00:00
private struct InChannelViewKey: EnvironmentKey {
static let defaultValue = false
}
private struct InChannelPlaylistViewKey: EnvironmentKey {
static let defaultValue = false
}
2021-09-18 20:36:42 +00:00
private struct HorizontalCellsKey: EnvironmentKey {
static let defaultValue = false
}
2021-09-19 12:42:47 +00:00
enum NavigationStyle {
case tab, sidebar
}
private struct NavigationStyleKey: EnvironmentKey {
static let defaultValue = NavigationStyle.tab
}
2022-12-12 00:18:29 +00:00
private struct ListingStyleKey: EnvironmentKey {
static let defaultValue = ListingStyle.cells
}
2022-12-13 00:50:26 +00:00
private struct InNavigationViewKey: EnvironmentKey {
static let defaultValue = true
}
2022-12-18 23:09:54 +00:00
private struct InQueueListingKey: EnvironmentKey {
static let defaultValue = false
}
2022-12-18 23:10:05 +00:00
private struct NoListingDividersKey: EnvironmentKey {
static let defaultValue = false
}
2022-12-12 00:18:29 +00:00
enum ListingStyle: String, CaseIterable, Defaults.Serializable {
case cells
case list
var systemImage: String {
switch self {
case .cells:
return "rectangle.grid.2x2"
case .list:
return "list.dash"
}
}
}
2021-10-24 21:36:24 +00:00
private struct CurrentPlaylistID: EnvironmentKey {
static let defaultValue: String? = nil
}
2022-02-04 17:38:29 +00:00
typealias LoadMoreContentHandlerType = () -> Void
private struct LoadMoreContentHandler: EnvironmentKey {
2022-01-09 15:05:05 +00:00
static let defaultValue: LoadMoreContentHandlerType = {}
}
extension EnvironmentValues {
2021-10-28 17:14:55 +00:00
var inChannelView: Bool {
get { self[InChannelViewKey.self] }
set { self[InChannelViewKey.self] = newValue }
}
var inChannelPlaylistView: Bool {
get { self[InChannelPlaylistViewKey.self] }
set { self[InChannelPlaylistViewKey.self] = newValue }
}
2021-09-18 20:36:42 +00:00
var horizontalCells: Bool {
get { self[HorizontalCellsKey.self] }
set { self[HorizontalCellsKey.self] = newValue }
}
2021-09-19 12:42:47 +00:00
var navigationStyle: NavigationStyle {
get { self[NavigationStyleKey.self] }
set { self[NavigationStyleKey.self] = newValue }
}
2021-10-24 21:36:24 +00:00
var currentPlaylistID: String? {
get { self[CurrentPlaylistID.self] }
set { self[CurrentPlaylistID.self] = newValue }
}
2022-01-09 14:47:24 +00:00
var loadMoreContentHandler: LoadMoreContentHandlerType {
get { self[LoadMoreContentHandler.self] }
set { self[LoadMoreContentHandler.self] = newValue }
}
2022-02-04 17:38:29 +00:00
2022-12-12 00:18:29 +00:00
var listingStyle: ListingStyle {
get { self[ListingStyleKey.self] }
set { self[ListingStyleKey.self] = newValue }
}
2022-12-13 00:50:26 +00:00
var inNavigationView: Bool {
get { self[InNavigationViewKey.self] }
set { self[InNavigationViewKey.self] = newValue }
}
2022-12-18 23:09:54 +00:00
var inQueueListing: Bool {
get { self[InQueueListingKey.self] }
set { self[InQueueListingKey.self] = newValue }
}
2022-12-18 23:10:05 +00:00
var noListingDividers: Bool {
get { self[NoListingDividersKey.self] }
set { self[NoListingDividersKey.self] = newValue }
}
}