1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Model/Favorites/FavoriteItem.swift

61 lines
2.1 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 {
2023-05-25 17:58:29 +05:30
case history
2021-11-02 03:26:18 +05:30
case subscriptions
case popular
case trending(String, String?)
2022-12-11 20:30:20 +05:30
case channel(String, String, String)
2022-12-12 04:00:28 +05:30
case playlist(String, String)
2022-12-11 20:30:20 +05:30
case channelPlaylist(String, 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 {
2023-05-25 17:58:29 +05:30
case .history:
return "History"
2021-11-02 03:26:18 +05:30
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")"
2022-12-11 20:30:20 +05:30
case let .channel(_, _, name):
2021-11-02 03:26:18 +05:30
return name
2022-12-11 20:30:20 +05:30
case let .channelPlaylist(_, _, name):
2021-11-02 03:26:18 +05:30
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 ""
}
}
}
2023-06-17 17:39:51 +05:30
static func == (lhs: Self, rhs: Self) -> Bool {
2021-11-02 03:26:18 +05:30
lhs.section == rhs.section
}
var id = UUID().uuidString
var section: Section
2023-05-25 17:58:29 +05:30
var widgetSettingsKey: String {
"favorites-\(id)"
}
2021-11-02 03:26:18 +05:30
}