模块化 AppStore 并完善素材管理与个人空间设置。
将会话、权限、位置、收款与排队存储拆分为独立模块,同步更新各 ViewModel 与单元测试,并补充素材管理 UI 与个人空间设置交互。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
57
suixinkan/DataStore/AppLocationStore.swift
Normal file
57
suixinkan/DataStore/AppLocationStore.swift
Normal file
@ -0,0 +1,57 @@
|
||||
//
|
||||
// AppLocationStore.swift
|
||||
// suixinkan
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
/// 管理当前账号的位置上报会话与提醒偏好。
|
||||
final class AppLocationStore {
|
||||
|
||||
private enum Key: String, CaseIterable {
|
||||
case onlineStatus = "key_online_status"
|
||||
case lastReportTime = "key_last_location_report_time"
|
||||
case reminderMinutes = "key_location_reminder_minutes"
|
||||
}
|
||||
|
||||
private let defaults: UserDefaults
|
||||
private let session: AppSessionStore
|
||||
|
||||
/// 使用指定持久化容器和会话创建位置存储。
|
||||
init(defaults: UserDefaults, session: AppSessionStore) {
|
||||
self.defaults = defaults
|
||||
self.session = session
|
||||
}
|
||||
|
||||
/// 是否处于位置上报在线状态。
|
||||
var onlineStatus: Bool {
|
||||
get { defaults.bool(forKey: scopedKey(.onlineStatus)) }
|
||||
set { defaults.set(newValue, forKey: scopedKey(.onlineStatus)) }
|
||||
}
|
||||
|
||||
/// 上次位置上报时间戳,单位为毫秒。
|
||||
var lastReportTime: Int64 {
|
||||
get { Int64(defaults.integer(forKey: scopedKey(.lastReportTime))) }
|
||||
set { defaults.set(Int(newValue), forKey: scopedKey(.lastReportTime)) }
|
||||
}
|
||||
|
||||
/// 位置超时提前提醒分钟数,0 表示不提醒。
|
||||
var reminderMinutes: Int {
|
||||
get { defaults.integer(forKey: scopedKey(.reminderMinutes)) }
|
||||
set { defaults.set(newValue, forKey: scopedKey(.reminderMinutes)) }
|
||||
}
|
||||
|
||||
/// 清除上次位置上报时间。
|
||||
func clearLastReportTime() {
|
||||
defaults.removeObject(forKey: scopedKey(.lastReportTime))
|
||||
}
|
||||
|
||||
/// 清除当前账号的位置上报状态和偏好。
|
||||
func clear() {
|
||||
Key.allCases.forEach { defaults.removeObject(forKey: scopedKey($0)) }
|
||||
}
|
||||
|
||||
private func scopedKey(_ key: Key) -> String {
|
||||
"\(session.accountCachePrefix)_\(key.rawValue)"
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user