2021-03-02 09:27:11 +01:00
|
|
|
//
|
|
|
|
// PollItem.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK Cirno on 2021-3-2.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import CoreData
|
|
|
|
|
2021-03-23 11:47:21 +01:00
|
|
|
/// Note: update Equatable when change case
|
2021-03-02 09:27:11 +01:00
|
|
|
enum PollItem {
|
2021-07-05 10:07:17 +02:00
|
|
|
case option(objectID: NSManagedObjectID, attribute: Attribute)
|
2021-03-02 09:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension PollItem {
|
|
|
|
class Attribute: Hashable {
|
|
|
|
|
2021-03-03 12:34:29 +01:00
|
|
|
enum SelectState: Equatable, Hashable {
|
|
|
|
case none
|
|
|
|
case off
|
|
|
|
case on
|
|
|
|
}
|
|
|
|
|
|
|
|
enum VoteState: Equatable, Hashable {
|
|
|
|
case hidden
|
2021-03-05 06:41:48 +01:00
|
|
|
case reveal(voted: Bool, percentage: Double, animated: Bool)
|
2021-03-03 12:34:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
var selectState: SelectState
|
|
|
|
var voteState: VoteState
|
|
|
|
|
|
|
|
init(selectState: SelectState, voteState: VoteState) {
|
|
|
|
self.selectState = selectState
|
|
|
|
self.voteState = voteState
|
2021-03-02 12:10:45 +01:00
|
|
|
}
|
|
|
|
|
2021-03-02 09:27:11 +01:00
|
|
|
static func == (lhs: PollItem.Attribute, rhs: PollItem.Attribute) -> Bool {
|
2021-03-03 12:34:29 +01:00
|
|
|
return lhs.selectState == rhs.selectState &&
|
|
|
|
lhs.voteState == rhs.voteState
|
2021-03-02 09:27:11 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func hash(into hasher: inout Hasher) {
|
2021-03-03 12:34:29 +01:00
|
|
|
hasher.combine(selectState)
|
|
|
|
hasher.combine(voteState)
|
2021-03-02 09:27:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension PollItem: Equatable {
|
|
|
|
static func == (lhs: PollItem, rhs: PollItem) -> Bool {
|
|
|
|
switch (lhs, rhs) {
|
2021-07-05 10:07:17 +02:00
|
|
|
case (.option(let objectIDLeft, _), .option(let objectIDRight, _)):
|
2021-03-02 09:27:11 +01:00
|
|
|
return objectIDLeft == objectIDRight
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension PollItem: Hashable {
|
|
|
|
func hash(into hasher: inout Hasher) {
|
|
|
|
switch self {
|
2021-07-05 10:07:17 +02:00
|
|
|
case .option(let objectID, _):
|
2021-03-02 09:27:11 +01:00
|
|
|
hasher.combine(objectID)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|