2021-03-05 15:50:20 +01:00
|
|
|
//
|
|
|
|
// PickServerItem.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Cirno MainasuK on 2021/3/5.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
|
|
|
|
/// Note: update Equatable when change case
|
|
|
|
enum PickServerItem {
|
|
|
|
case header
|
|
|
|
case categoryPicker(items: [CategoryPickerItem])
|
|
|
|
case search
|
|
|
|
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-03-06 06:29:45 +01:00
|
|
|
var isLast: Bool
|
2021-03-05 15:50:20 +01:00
|
|
|
var isExpand: Bool
|
|
|
|
|
2021-03-06 06:29:45 +01:00
|
|
|
init(isLast: Bool, isExpand: Bool) {
|
|
|
|
self.isLast = 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 (.categoryPicker(let itemsLeft), .categoryPicker(let itemsRight)):
|
|
|
|
return itemsLeft == itemsRight
|
|
|
|
case (.search, .search):
|
|
|
|
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 .categoryPicker(let items):
|
|
|
|
hasher.combine(items)
|
|
|
|
case .search:
|
|
|
|
hasher.combine(String(describing: PickServerItem.search.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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|