Skip to content

Commit 68d9359

Browse files
committed
appbar + list + feed over
1 parent 6d2fc53 commit 68d9359

20 files changed

+839
-608
lines changed

iosApp/iosApp/Data/FLTabSettings.swift

Lines changed: 51 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ public struct FLTabSettings {
279279
]
280280
}
281281

282-
private static func defaultBlueskySecondaryItems(accountKey: FLMicroBlogKey) -> [FLTabItem] {
282+
private static func defaultBlueskySecondaryItems(accountKey _: FLMicroBlogKey) -> [FLTabItem] {
283283
[
284-
// FLAllListTabItem(
284+
// FLAllListTabItem(
285285
// metaData: FLTabMetaData(
286286
// title: .localized(.list),
287287
// icon: .mixed(.list, userKey: accountKey)
@@ -1174,11 +1174,11 @@ public struct FLProfileMediaTabItem: FLTabItem {
11741174
// - AppBar统一存储数据结构
11751175
// AppBar项目配置结构
11761176
public struct AppBarItemConfig: Codable {
1177-
public let key: String // 项目唯一标识
1178-
public let type: AppBarItemType // 项目类型
1179-
public let addedTime: Date // 添加时间
1180-
public var metadata: [String: String] // 元数据
1181-
1177+
public let key: String // 项目唯一标识
1178+
public let type: AppBarItemType // 项目类型
1179+
public let addedTime: Date // 添加时间
1180+
public var metadata: [String: String] // 元数据
1181+
11821182
public init(key: String, type: AppBarItemType, addedTime: Date = Date(), metadata: [String: String] = [:]) {
11831183
self.key = key
11841184
self.type = type
@@ -1189,36 +1189,36 @@ public struct AppBarItemConfig: Codable {
11891189

11901190
// 项目类型枚举
11911191
public enum AppBarItemType: String, Codable {
1192-
case main // 主标签
1193-
case secondary // 次要标签
1194-
case list // 固定列表
1195-
case feed // 固定Feed
1192+
case main // 主标签
1193+
case secondary // 次要标签
1194+
case list // 固定列表
1195+
case feed // 固定Feed
11961196
}
11971197

11981198
// 平台配置结构
11991199
public struct PlatformAppBarConfig: Codable {
12001200
public var enabledItems: [AppBarItemConfig]
1201-
public let version: Int = 1 // 添加版本字段便于未来扩展
1202-
1201+
public let version: Int = 1 // 添加版本字段便于未来扩展
1202+
12031203
public init(enabledItems: [AppBarItemConfig] = []) {
12041204
self.enabledItems = enabledItems
12051205
}
12061206
}
12071207

12081208
// 扩展FLTabSettingsStorage添加AppBar配置相关方法
1209-
extension FLTabSettingsStorage {
1209+
public extension FLTabSettingsStorage {
12101210
// 存储键名前缀
1211-
private static let appBarConfigKeyPrefix = "appbar_config_3_"
1212-
1211+
private static let appBarConfigKeyPrefix = "appbar_config_4_"
1212+
12131213
// 获取AppBar配置存储键
12141214
private func appBarConfigKey(for platformType: PlatformType, accountKey: MicroBlogKey) -> String {
12151215
let platformString = platformType.name
12161216
let accountString = accountKey.id
12171217
return "\(Self.appBarConfigKeyPrefix)\(platformString)_\(accountString)"
12181218
}
1219-
1219+
12201220
// 保存AppBar配置
1221-
public func saveAppBarConfig(_ config: PlatformAppBarConfig, for platformType: PlatformType, accountKey: MicroBlogKey) {
1221+
func saveAppBarConfig(_ config: PlatformAppBarConfig, for platformType: PlatformType, accountKey: MicroBlogKey) {
12221222
let key = appBarConfigKey(for: platformType, accountKey: accountKey)
12231223
do {
12241224
let data = try JSONEncoder().encode(config)
@@ -1227,90 +1227,90 @@ extension FLTabSettingsStorage {
12271227
NSLog("保存AppBar配置失败: \(error.localizedDescription)")
12281228
}
12291229
}
1230-
1230+
12311231
// 读取AppBar配置
1232-
public func loadAppBarConfig(for platformType: PlatformType, accountKey: MicroBlogKey) -> PlatformAppBarConfig? {
1232+
func loadAppBarConfig(for platformType: PlatformType, accountKey: MicroBlogKey) -> PlatformAppBarConfig? {
12331233
let key = appBarConfigKey(for: platformType, accountKey: accountKey)
12341234
guard let data = userDefaults.data(forKey: key) else { return nil }
1235-
1235+
12361236
do {
12371237
return try JSONDecoder().decode(PlatformAppBarConfig.self, from: data)
12381238
} catch {
12391239
NSLog("加载AppBar配置失败: \(error.localizedDescription)")
12401240
return nil
12411241
}
12421242
}
1243-
1243+
12441244
// 清除AppBar配置
1245-
public func clearAppBarConfig(for platformType: PlatformType, accountKey: MicroBlogKey) {
1245+
func clearAppBarConfig(for platformType: PlatformType, accountKey: MicroBlogKey) {
12461246
let key = appBarConfigKey(for: platformType, accountKey: accountKey)
12471247
userDefaults.removeObject(forKey: key)
12481248
}
12491249
}
12501250

12511251
// 扩展FLTabSettingsManager添加AppBar配置相关方法
1252-
extension FLTabSettingsManager {
1252+
public extension FLTabSettingsManager {
12531253
// 保存AppBar配置
1254-
public func saveAppBarConfig(_ config: PlatformAppBarConfig, for user: UiUserV2) {
1254+
func saveAppBarConfig(_ config: PlatformAppBarConfig, for user: UiUserV2) {
12551255
storage.saveAppBarConfig(config, for: user.platformType, accountKey: user.key)
12561256
}
1257-
1257+
12581258
// 读取AppBar配置
1259-
public func getAppBarConfig(for user: UiUserV2) -> PlatformAppBarConfig {
1260-
return storage.loadAppBarConfig(for: user.platformType, accountKey: user.key) ?? PlatformAppBarConfig()
1259+
func getAppBarConfig(for user: UiUserV2) -> PlatformAppBarConfig {
1260+
storage.loadAppBarConfig(for: user.platformType, accountKey: user.key) ?? PlatformAppBarConfig()
12611261
}
1262-
1262+
12631263
// 将FLTabItem转换为AppBarItemConfig
1264-
public func convertTabToConfig(_ tab: FLTabItem, type: AppBarItemType, addedTime: Date = Date()) -> AppBarItemConfig {
1264+
func convertTabToConfig(_ tab: FLTabItem, type: AppBarItemType, addedTime: Date = Date()) -> AppBarItemConfig {
12651265
var metadata: [String: String] = [:]
1266-
1266+
12671267
// 添加标题元数据
12681268
switch tab.metaData.title {
12691269
case let .text(text):
12701270
metadata["title"] = text
12711271
case let .localized(key):
12721272
metadata["title"] = NSLocalizedString(key, comment: "")
12731273
}
1274-
1274+
12751275
return AppBarItemConfig(
12761276
key: tab.key,
12771277
type: type,
12781278
addedTime: addedTime,
12791279
metadata: metadata
12801280
)
12811281
}
1282-
1282+
12831283
// 将AppBarItemConfig转换回FLTabItem数组
1284-
public func convertConfigToTabs(_ config: PlatformAppBarConfig, for user: UiUserV2, accountType: AccountType) -> [FLTabItem] {
1284+
func convertConfigToTabs(_ config: PlatformAppBarConfig, for user: UiUserV2, accountType: AccountType) -> [FLTabItem] {
12851285
// 获取默认标签以便查找
12861286
let defaultItems = FLTabSettings.defaultSecondary(user: user)
12871287
let mainItems = FLTabSettings.defaultPrimary(user: user)
12881288
let allDefaultItems = mainItems + defaultItems
1289-
1289+
12901290
// 按添加时间排序
12911291
let sortedItems = config.enabledItems.sorted { $0.addedTime < $1.addedTime }
1292-
1292+
12931293
// 转换为FLTabItem
12941294
var result: [FLTabItem] = []
1295-
1295+
12961296
for item in sortedItems {
12971297
// 首先尝试从默认项中查找
12981298
if let tab = allDefaultItems.first(where: { $0.key == item.key }) {
12991299
result.append(tab)
13001300
continue
13011301
}
1302-
1302+
13031303
// 特殊处理列表和Feed标签
13041304
if item.type == .list, let components = item.key.split(separator: "_").last {
13051305
let listId = String(components)
13061306
let title = item.metadata["title"] ?? "List"
1307-
1307+
13081308
let listTab = FLListTimelineTabItem(
13091309
metaData: FLTabMetaData(
13101310
title: .text(title),
13111311
icon: .material(.list)
13121312
),
1313-
account: accountType, // 使用传入的accountType
1313+
account: accountType, // 使用传入的accountType
13141314
listKey: listId
13151315
)
13161316
result.append(listTab)
@@ -1319,32 +1319,32 @@ extension FLTabSettingsManager {
13191319
if user.platformType == .bluesky {
13201320
let feedId = String(components)
13211321
let title = item.metadata["title"] ?? "Feed"
1322-
1322+
13231323
let feedTab = FLBlueskyFeedTabItem(
13241324
metaData: FLTabMetaData(
13251325
title: .text(title),
13261326
icon: .material(.feeds)
13271327
),
1328-
account: accountType, // 使用传入的accountType
1328+
account: accountType, // 使用传入的accountType
13291329
feedKey: feedId
13301330
)
13311331
result.append(feedTab)
13321332
}
13331333
}
13341334
}
1335-
1335+
13361336
// 确保至少有主页标签
13371337
if result.isEmpty, let homeItem = mainItems.first {
13381338
result.append(homeItem)
13391339
}
1340-
1340+
13411341
return result
13421342
}
1343-
1343+
13441344
// 创建默认配置
1345-
public func createDefaultAppBarConfig(for user: UiUserV2) -> PlatformAppBarConfig {
1345+
func createDefaultAppBarConfig(for user: UiUserV2) -> PlatformAppBarConfig {
13461346
var items: [AppBarItemConfig] = []
1347-
1347+
13481348
// 添加主标签,使用1970年确保始终排在最前
13491349
if let homeItem = FLTabSettings.defaultPrimary(user: user).first {
13501350
items.append(convertTabToConfig(
@@ -1353,7 +1353,7 @@ extension FLTabSettingsManager {
13531353
addedTime: Date(timeIntervalSince1970: 0)
13541354
))
13551355
}
1356-
1356+
13571357
// 添加默认次要标签
13581358
let secondaryItems = FLTabSettings.defaultSecondary(user: user).prefix(3)
13591359
for (index, item) in secondaryItems.enumerated() {
@@ -1363,12 +1363,12 @@ extension FLTabSettingsManager {
13631363
addedTime: Date().addingTimeInterval(Double(index) * 60)
13641364
))
13651365
}
1366-
1366+
13671367
return PlatformAppBarConfig(enabledItems: items)
13681368
}
1369-
1369+
13701370
// 重置为默认AppBar配置
1371-
public func resetToDefaultAppBarConfig(for user: UiUserV2) {
1371+
func resetToDefaultAppBarConfig(for user: UiUserV2) {
13721372
let defaultConfig = createDefaultAppBarConfig(for: user)
13731373
saveAppBarConfig(defaultConfig, for: user)
13741374
}

iosApp/iosApp/Data/UserManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@ class UserManager {
3333
if case let .success(data) = onEnum(of: state.user) {
3434
self.currentUser = data.data
3535
isInitialized = true
36-
36+
3737
// 初始化AppBarTabSettingStore
3838
let account = AccountTypeSpecific(accountKey: data.data.key)
3939
AppBarTabSettingStore.shared.initialize(with: account, user: data.data)
40-
40+
4141
// 发送通知
4242
NotificationCenter.default.post(name: .userDidUpdate, object: data.data)
4343
os_log("[UserManager] 初始化完成,用户: %{public}@", log: .default, type: .debug, data.data.name.raw)

iosApp/iosApp/FlareApp.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ struct FlareApp: SwiftUI.App {
1010
#endif
1111
init() {
1212
KoinHelper.shared.start(inAppNotification: SwitUIInAppNotification())
13-
13+
1414
// 初始化UserManager
1515
UserManager.shared.initialize()
16-
16+
1717
// 初始化AppBarTabSettingStore(使用游客模式)
1818
// UserManager初始化完成后会自动更新为正确的账号
1919
AppBarTabSettingStore.shared.initialize(with: AccountTypeGuest(), user: nil)
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import Foundation
2+
import os
3+
import shared
4+
import SwiftUI
5+
6+
// 配置管理服务
7+
class AppBarConfigService {
8+
private let logger = Logger(subsystem: "com.flare.app", category: "AppBarConfigService")
9+
private let settingsManager = FLTabSettingsManager()
10+
private let storageLock = NSLock()
11+
12+
// 加载AppBar配置
13+
func loadAppBarConfig(for user: UiUserV2) -> [AppBarItemConfig] {
14+
storageLock.lock()
15+
defer { storageLock.unlock() }
16+
17+
// 通过settingsManager加载配置
18+
let config = settingsManager.getAppBarConfig(for: user)
19+
let items = config.enabledItems
20+
21+
logger.debug("加载到\(items.count)个配置项")
22+
return items
23+
}
24+
25+
// 保存AppBar配置
26+
func saveAppBarConfig(_ items: [AppBarItemConfig], for user: UiUserV2) {
27+
storageLock.lock()
28+
defer { storageLock.unlock() }
29+
30+
// 通过settingsManager保存配置
31+
let config = PlatformAppBarConfig(enabledItems: items)
32+
settingsManager.saveAppBarConfig(config, for: user)
33+
34+
logger.debug("保存\(items.count)个配置项")
35+
}
36+
37+
// 创建默认配置
38+
func createDefaultAppBarConfig(for user: UiUserV2) -> [AppBarItemConfig] {
39+
let defaultConfig = settingsManager.createDefaultAppBarConfig(for: user)
40+
let items = defaultConfig.enabledItems
41+
logger.debug("创建默认AppBar配置")
42+
return items
43+
}
44+
45+
// 将配置转换为标签
46+
func convertConfigToTabs(_ items: [AppBarItemConfig], for user: UiUserV2, accountType: AccountType) -> [FLTabItem] {
47+
settingsManager.convertConfigToTabs(
48+
PlatformAppBarConfig(enabledItems: items),
49+
for: user,
50+
accountType: accountType
51+
)
52+
}
53+
54+
// 将标签转换为配置
55+
func convertTabToConfig(_ tab: FLTabItem, type: AppBarItemType, addedTime: Date) -> AppBarItemConfig {
56+
settingsManager.convertTabToConfig(
57+
tab,
58+
type: type,
59+
addedTime: addedTime
60+
)
61+
}
62+
}

0 commit comments

Comments
 (0)