2020-07-01 03:23:22 +02:00
|
|
|
//
|
|
|
|
// SidebarExpandedContainers.swift
|
|
|
|
// NetNewsWire
|
|
|
|
//
|
|
|
|
// Created by Maurice Parker on 6/30/20.
|
|
|
|
// Copyright © 2020 Ranchero Software. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
import Combine
|
|
|
|
import Account
|
|
|
|
|
2020-07-26 22:31:32 +02:00
|
|
|
struct SidebarExpandedContainers {
|
2020-07-01 03:23:22 +02:00
|
|
|
|
2020-07-26 22:31:32 +02:00
|
|
|
var expandedTable = [ContainerIdentifier: Bool]()
|
2020-07-01 03:23:22 +02:00
|
|
|
|
|
|
|
var data: Data {
|
|
|
|
get {
|
|
|
|
let encoder = PropertyListEncoder()
|
|
|
|
encoder.outputFormat = .binary
|
|
|
|
return (try? encoder.encode(expandedTable)) ?? Data()
|
|
|
|
}
|
|
|
|
set {
|
|
|
|
let decoder = PropertyListDecoder()
|
2020-07-04 16:18:56 +02:00
|
|
|
expandedTable = (try? decoder.decode([ContainerIdentifier: Bool].self, from: newValue)) ?? [ContainerIdentifier: Bool]()
|
2020-07-01 03:23:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 23:00:00 +02:00
|
|
|
func contains(_ containerID: ContainerIdentifier) -> Bool {
|
|
|
|
return expandedTable.keys.contains(containerID)
|
|
|
|
}
|
|
|
|
|
2020-07-01 03:23:22 +02:00
|
|
|
subscript(_ containerID: ContainerIdentifier) -> Bool {
|
|
|
|
get {
|
2020-07-04 16:18:56 +02:00
|
|
|
if let result = expandedTable[containerID] {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
switch containerID {
|
|
|
|
case .smartFeedController, .account:
|
|
|
|
return true
|
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
2020-07-01 03:23:22 +02:00
|
|
|
}
|
|
|
|
set(newValue) {
|
2020-07-04 16:18:56 +02:00
|
|
|
expandedTable[containerID] = newValue
|
2020-07-01 03:23:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|