2021-03-05 15:50:20 +01:00
|
|
|
//
|
|
|
|
// PickServerItem.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Cirno MainasuK on 2021/3/5.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2021-05-19 11:40:09 +02:00
|
|
|
import Combine
|
2021-03-05 15:50:20 +01:00
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
/// Note: update Equatable when change case
|
|
|
|
enum PickServerItem {
|
|
|
|
case header
|
|
|
|
case server(server: Mastodon.Entity.Server, attribute: ServerItemAttribute)
|
2021-05-13 11:50:37 +02:00
|
|
|
case loader(attribute: LoaderItemAttribute)
|
2021-03-05 15:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension PickServerItem {
|
|
|
|
final class ServerItemAttribute: Equatable, Hashable {
|
2021-05-19 11:40:09 +02:00
|
|
|
var isLast: CurrentValueSubject<Bool, Never>
|
2021-03-05 15:50:20 +01:00
|
|
|
var isExpand: Bool
|
|
|
|
|
2021-03-06 06:29:45 +01:00
|
|
|
init(isLast: Bool, isExpand: Bool) {
|
2021-05-19 11:40:09 +02:00
|
|
|
self.isLast = CurrentValueSubject(isLast)
|
2021-03-05 15:50:20 +01:00
|
|
|
self.isExpand = isExpand
|
|
|
|
}
|
|
|
|
|
|
|
|
static func == (lhs: PickServerItem.ServerItemAttribute, rhs: PickServerItem.ServerItemAttribute) -> Bool {
|
|
|
|
return lhs.isExpand == rhs.isExpand
|
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(isExpand)
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 11:50:37 +02:00
|
|
|
|
|
|
|
final class LoaderItemAttribute: Equatable, Hashable {
|
|
|
|
let id = UUID()
|
|
|
|
|
|
|
|
var isLast: Bool
|
|
|
|
var isNoResult: Bool
|
|
|
|
|
|
|
|
init(isLast: Bool, isEmptyResult: Bool) {
|
|
|
|
self.isLast = isLast
|
|
|
|
self.isNoResult = isEmptyResult
|
|
|
|
}
|
|
|
|
|
|
|
|
static func == (lhs: PickServerItem.LoaderItemAttribute, rhs: PickServerItem.LoaderItemAttribute) -> Bool {
|
|
|
|
return lhs.id == rhs.id
|
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
hasher.combine(id)
|
|
|
|
}
|
|
|
|
}
|
2021-03-05 15:50:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension PickServerItem: Equatable {
|
|
|
|
static func == (lhs: PickServerItem, rhs: PickServerItem) -> Bool {
|
|
|
|
switch (lhs, rhs) {
|
|
|
|
case (.header, .header):
|
|
|
|
return true
|
|
|
|
case (.server(let serverLeft, _), .server(let serverRight, _)):
|
|
|
|
return serverLeft.domain == serverRight.domain
|
2021-05-13 11:50:37 +02:00
|
|
|
case (.loader(let attributeLeft), loader(let attributeRight)):
|
|
|
|
return attributeLeft == attributeRight
|
2021-03-05 15:50:20 +01:00
|
|
|
default:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PickServerItem: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
switch self {
|
|
|
|
case .header:
|
|
|
|
hasher.combine(String(describing: PickServerItem.header.self))
|
|
|
|
case .server(let server, _):
|
|
|
|
hasher.combine(server.domain)
|
2021-05-13 11:50:37 +02:00
|
|
|
case .loader(let attribute):
|
|
|
|
hasher.combine(attribute)
|
2021-03-05 15:50:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|