1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 23:00:32 +05:30
yattee/Model/FavoriteItem.swift

54 lines
1.9 KiB
Swift
Raw Normal View History

2021-11-02 03:26:18 +05:30
import Defaults
import Foundation
struct FavoriteItem: Codable, Equatable, Identifiable, Defaults.Serializable {
enum Section: Codable, Equatable, Defaults.Serializable {
case subscriptions
case popular
case trending(String, String?)
case channel(String, String)
case playlist(String)
case channelPlaylist(String, String)
2021-11-09 23:13:15 +05:30
case searchQuery(String, String, String, String)
2021-11-02 03:26:18 +05:30
var label: String {
switch self {
case .subscriptions:
return "Subscriptions"
case .popular:
return "Popular"
case let .trending(country, category):
let trendingCountry = Country(rawValue: country)!
2021-11-12 02:37:13 +05:30
let trendingCategory = category.isNil ? nil : TrendingCategory(rawValue: category!)
2021-11-08 05:04:42 +05:30
return "\(trendingCountry.flag) \(trendingCountry.id) \(trendingCategory?.name ?? "Trending")"
2021-11-02 03:26:18 +05:30
case let .channel(_, name):
return name
case let .channelPlaylist(_, name):
return name
2021-11-09 23:13:15 +05:30
case let .searchQuery(text, date, duration, order):
var label = "Search: \"\(text)\""
if !date.isEmpty, let date = SearchQuery.Date(rawValue: date), date != .any {
label += " from \(date == .today ? date.name : " this \(date.name)")"
}
if !order.isEmpty, let order = SearchQuery.SortOrder(rawValue: order), order != .relevance {
label += " by \(order.name)"
}
if !duration.isEmpty {
label += " (\(duration))"
}
return label
2021-11-02 03:26:18 +05:30
default:
return ""
}
}
}
static func == (lhs: FavoriteItem, rhs: FavoriteItem) -> Bool {
lhs.section == rhs.section
}
var id = UUID().uuidString
var section: Section
}