选择图片分享功能
This commit is contained in:
62
Jetson Media/cache/ReadingProgressManager.swift
vendored
62
Jetson Media/cache/ReadingProgressManager.swift
vendored
@@ -0,0 +1,62 @@
|
||||
import Foundation
|
||||
|
||||
class ReadingProgressManager {
|
||||
static let shared = ReadingProgressManager()
|
||||
private let userDefaults = UserDefaults.standard
|
||||
|
||||
private init() {}
|
||||
|
||||
/// 保存阅读进度(直接存储图片索引,确保准确性)
|
||||
func saveProgress(albumId: String, imageIndex: Int) {
|
||||
userDefaults.set(imageIndex, forKey: progressKey(albumId: albumId))
|
||||
print("已保存进度 - 漫画ID: \(albumId), 图片索引: \(imageIndex)")
|
||||
}
|
||||
|
||||
/// 获取保存的阅读进度(返回图片索引)
|
||||
func getProgress(albumId: String) -> Int {
|
||||
return userDefaults.integer(forKey: progressKey(albumId: albumId))
|
||||
}
|
||||
|
||||
/// 清除指定漫画的阅读进度
|
||||
func clearProgress(albumId: String) {
|
||||
userDefaults.removeObject(forKey: progressKey(albumId: albumId))
|
||||
}
|
||||
|
||||
/// 生成唯一存储键
|
||||
private func progressKey(albumId: String) -> String {
|
||||
return "readingProgress_\(albumId)"
|
||||
}
|
||||
}
|
||||
|
||||
/// 收藏管理工具
|
||||
class FavoriteManager {
|
||||
static let shared = FavoriteManager()
|
||||
private let userDefaults = UserDefaults.standard
|
||||
private let favoriteKey = "favoriteAlbumIds"
|
||||
|
||||
private init() {}
|
||||
|
||||
/// 获取所有收藏的漫画ID
|
||||
var favoriteAlbumIds: [String] {
|
||||
userDefaults.array(forKey: favoriteKey) as? [String] ?? []
|
||||
}
|
||||
|
||||
/// 切换漫画的收藏状态
|
||||
/// - Parameter albumId: 漫画ID
|
||||
func toggleFavorite(albumId: String) {
|
||||
var favorites = favoriteAlbumIds
|
||||
if favorites.contains(albumId) {
|
||||
favorites.removeAll { $0 == albumId }
|
||||
} else {
|
||||
favorites.append(albumId)
|
||||
}
|
||||
userDefaults.set(favorites, forKey: favoriteKey)
|
||||
}
|
||||
|
||||
/// 检查漫画是否已收藏
|
||||
/// - Parameter albumId: 漫画ID
|
||||
/// - Returns: 是否收藏
|
||||
func isFavorite(albumId: String) -> Bool {
|
||||
return favoriteAlbumIds.contains(albumId)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user