feat: 添加情绪颜色选择功能及相关存储管理
主要变更: 1. 在 EPMomentPublishViewController 中添加情绪颜色选择按钮,用户可通过色轮选择情绪颜色。 2. 新增 EPEmotionColorStorage 类,提供情绪颜色的保存、获取和删除功能,支持动态 ID 的关联。 3. 新增 EPEmotionColorPicker 视图,提供环形布局的颜色选择器,增强用户体验。 4. 更新 EPMomentCell 和 EPMomentListView,以支持情绪颜色的显示和处理,确保动态展示的情绪效果。 此更新旨在提升用户交互体验,丰富动态发布功能,确保情绪颜色的有效管理和展示。
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#import "EPMomentCell.h"
|
||||
#import <MJRefresh/MJRefresh.h>
|
||||
#import "YuMi-Swift.h"
|
||||
#import "EPEmotionColorStorage.h"
|
||||
|
||||
|
||||
@interface EPMomentListView () <UITableViewDelegate, UITableViewDataSource>
|
||||
@@ -91,6 +92,9 @@
|
||||
@kStrongify(self);
|
||||
[self endLoading];
|
||||
if (list.count > 0) {
|
||||
// 处理情绪颜色
|
||||
[self processEmotionColors:list isFirstPage:(self.nextID.length == 0)];
|
||||
|
||||
self.nextID = nextMomentID;
|
||||
[self.mutableRawList addObjectsFromArray:list];
|
||||
[self.tableView reloadData];
|
||||
@@ -120,6 +124,41 @@
|
||||
[self.refreshControl endRefreshing];
|
||||
}
|
||||
|
||||
/// 处理动态的情绪颜色(从 UserDefaults 匹配 + 处理临时颜色)
|
||||
- (void)processEmotionColors:(NSArray<MomentsInfoModel *> *)list isFirstPage:(BOOL)isFirstPage {
|
||||
// 检查是否有待处理的临时情绪颜色
|
||||
NSString *pendingColor = [[NSUserDefaults standardUserDefaults] stringForKey:@"EP_Pending_Emotion_Color"];
|
||||
NSNumber *pendingTimestamp = [[NSUserDefaults standardUserDefaults] objectForKey:@"EP_Pending_Emotion_Timestamp"];
|
||||
|
||||
for (NSInteger i = 0; i < list.count; i++) {
|
||||
MomentsInfoModel *model = list[i];
|
||||
|
||||
// 优先检查临时颜色(仅第一页第一条)
|
||||
if (isFirstPage && i == 0 && pendingColor && pendingTimestamp) {
|
||||
// 检查时间戳(5秒内有效,避免误匹配)
|
||||
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
|
||||
NSTimeInterval pending = pendingTimestamp.doubleValue;
|
||||
if ((now - pending) < 5.0) {
|
||||
model.emotionColor = pendingColor;
|
||||
// 保存到持久化存储
|
||||
[EPEmotionColorStorage saveColor:pendingColor forDynamicId:model.dynamicId];
|
||||
// 清除临时数据
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"EP_Pending_Emotion_Color"];
|
||||
[[NSUserDefaults standardUserDefaults] removeObjectForKey:@"EP_Pending_Emotion_Timestamp"];
|
||||
[[NSUserDefaults standardUserDefaults] synchronize];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// 从持久化存储中匹配
|
||||
NSString *savedColor = [EPEmotionColorStorage colorForDynamicId:model.dynamicId];
|
||||
if (savedColor) {
|
||||
model.emotionColor = savedColor;
|
||||
}
|
||||
// 不设置则保持 nil,Cell 渲染时会随机生成
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - UITableView
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
|
||||
Reference in New Issue
Block a user