WallPaperHome722/WallpaperHD_Live/Tool/historyManager.swift
2024-07-23 11:43:02 +08:00

215 lines
6.2 KiB
Swift

//
// historyManager.swift
// wallpaper_project
import Foundation
class HistoryManager {
static let shared = HistoryManager()
private let historyKey = "com.example.app.history"
//
var history: [WP_4KModel] {
get {
if let data = UserDefaults.standard.data(forKey: historyKey),
let history = try? JSONDecoder().decode([WP_4KModel].self, from: data) {
return history
}
return []
}
set {
let data = try? JSONEncoder().encode(newValue)
UserDefaults.standard.set(data, forKey: historyKey)
}
}
//
func addHistoryItem(item: WP_4KModel) {
//
if history.contains(where: { $0.title == item.title }) {
return
}
var updatedHistory = history
updatedHistory.append(item)
history = updatedHistory
}
//
func clearHistory() {
UserDefaults.standard.removeObject(forKey: historyKey)
}
}
class liveManager {
static let shared = liveManager()
private let historyKey = "com.example.app.live"
//
var history: [WP_4KModel] {
get {
if let data = UserDefaults.standard.data(forKey: historyKey),
let history = try? JSONDecoder().decode([WP_4KModel].self, from: data) {
return history
}
return []
}
set {
let data = try? JSONEncoder().encode(newValue)
UserDefaults.standard.set(data, forKey: historyKey)
}
}
//
func addHistoryItem(item: WP_4KModel) {
//
if history.contains(where: { $0.title == item.title }) {
return
}
var updatedHistory = history
updatedHistory.append(item)
history = updatedHistory
}
//
func clearHistory() {
UserDefaults.standard.removeObject(forKey: historyKey)
}
}
class HistoryjpgManager {
static let shared = HistoryjpgManager()
private let historyKey = "com.example.app.jpg"
//
var history: [WallpaperData] {
get {
if let data = UserDefaults.standard.data(forKey: historyKey),
let history = try? JSONDecoder().decode([WallpaperData].self, from: data) {
return history
}
return []
}
set {
let data = try? JSONEncoder().encode(newValue)
UserDefaults.standard.set(data, forKey: historyKey)
}
}
//
func addHistoryItem(item: WallpaperData) {
//
if history.contains(where: { $0.previewThumb == item.previewThumb }) {
return
}
var updatedHistory = history
updatedHistory.append(item)
history = updatedHistory
}
//
func clearHistory() {
UserDefaults.standard.removeObject(forKey: historyKey)
}
}
class scjpgManager {
static let shared = scjpgManager()
private let historyKey = "com.example.app.scjpg"
//
var history: [WallpaperData] {
get {
if let data = UserDefaults.standard.data(forKey: historyKey),
let history = try? JSONDecoder().decode([WallpaperData].self, from: data) {
return history
}
return []
}
set {
let data = try? JSONEncoder().encode(newValue)
UserDefaults.standard.set(data, forKey: historyKey)
}
}
//
func addHistoryItem(item: WallpaperData) {
//
if history.contains(where: { $0.previewThumb == item.previewThumb }) {
return
}
var updatedHistory = history
updatedHistory.append(item)
history = updatedHistory
}
//
func clearHistory() {
UserDefaults.standard.removeObject(forKey: historyKey)
}
}
class sc4kManager {
static let shared = sc4kManager()
private let historyKey = "com.example.app.sc4k"
//
var history: [WP_4KModel] {
get {
if let data = UserDefaults.standard.data(forKey: historyKey),
let history = try? JSONDecoder().decode([WP_4KModel].self, from: data) {
return history
}
return []
}
set {
let data = try? JSONEncoder().encode(newValue)
UserDefaults.standard.set(data, forKey: historyKey)
}
}
//
func addHistoryItem(item: WP_4KModel) {
//
if history.contains(where: { $0.title == item.title }) {
return
}
var updatedHistory = history
updatedHistory.append(item)
history = updatedHistory
}
//
func clearHistory() {
UserDefaults.standard.removeObject(forKey: historyKey)
}
}
//
func setLoggedIn(_ value: Bool) {
UserDefaults.standard.set(value, forKey: "isLoggedIn")
}
///
func isLoggedIn() -> Bool {
if UserDefaults.standard.object(forKey: "isLoggedIn") != nil {
return UserDefaults.standard.bool(forKey: "isLoggedIn")
} else {
//
return false
}
}
//func issave(_ value: Bool) {
// UserDefaults.standard.set(value, forKey: "issave")
//}
//
//func issure(_ value: Bool) {
// UserDefaults.standard.set(value, forKey: "issure")
//}