修改举报和UI
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
//
|
||||
|
||||
#import "AIReportVC.h"
|
||||
#import "AiVM.h"
|
||||
|
||||
#pragma mark - AIReportOptionCell
|
||||
|
||||
@@ -116,6 +117,8 @@
|
||||
/// 提交按钮
|
||||
@property (nonatomic, strong) UIButton *submitButton;
|
||||
|
||||
@property (nonatomic, strong) AiVM *viewModel;
|
||||
|
||||
@end
|
||||
|
||||
@implementation AIReportVC
|
||||
@@ -134,6 +137,8 @@
|
||||
[self setupUI];
|
||||
/// 3:绑定事件
|
||||
[self bindActions];
|
||||
/// 4:其他(通知/键盘等)
|
||||
[self bindKeyboardNotifications];
|
||||
}
|
||||
|
||||
#pragma mark - 1:初始化数据
|
||||
@@ -286,6 +291,59 @@
|
||||
[self.view endEditing:YES];
|
||||
}
|
||||
|
||||
#pragma mark - 4:键盘处理
|
||||
|
||||
- (void)bindKeyboardNotifications {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleKeyboardWillChange:)
|
||||
name:UIKeyboardWillChangeFrameNotification
|
||||
object:nil];
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(handleKeyboardWillHide:)
|
||||
name:UIKeyboardWillHideNotification
|
||||
object:nil];
|
||||
}
|
||||
|
||||
- (void)handleKeyboardWillChange:(NSNotification *)notification {
|
||||
NSDictionary *userInfo = notification.userInfo ?: @{};
|
||||
CGRect endFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
|
||||
NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
||||
NSInteger curve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
|
||||
|
||||
CGRect endFrameInView = [self.view convertRect:endFrame fromView:nil];
|
||||
CGFloat keyboardHeight = MAX(0, CGRectGetMaxY(self.view.bounds) - CGRectGetMinY(endFrameInView));
|
||||
|
||||
UIEdgeInsets inset = self.scrollView.contentInset;
|
||||
inset.bottom = keyboardHeight;
|
||||
|
||||
UIViewAnimationOptions options = (UIViewAnimationOptions)(curve << 16);
|
||||
[UIView animateWithDuration:duration delay:0 options:options animations:^{
|
||||
self.scrollView.contentInset = inset;
|
||||
self.scrollView.scrollIndicatorInsets = inset;
|
||||
if ([self.descriptionTextView isFirstResponder]) {
|
||||
CGRect rect = [self.descriptionTextView convertRect:self.descriptionTextView.bounds toView:self.scrollView];
|
||||
rect = CGRectInset(rect, 0, -12);
|
||||
[self.scrollView scrollRectToVisible:rect animated:NO];
|
||||
}
|
||||
} completion:nil];
|
||||
}
|
||||
|
||||
- (void)handleKeyboardWillHide:(NSNotification *)notification {
|
||||
NSDictionary *userInfo = notification.userInfo ?: @{};
|
||||
NSTimeInterval duration = [userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue];
|
||||
NSInteger curve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
|
||||
UIViewAnimationOptions options = (UIViewAnimationOptions)(curve << 16);
|
||||
|
||||
[UIView animateWithDuration:duration delay:0 options:options animations:^{
|
||||
self.scrollView.contentInset = UIEdgeInsetsZero;
|
||||
self.scrollView.scrollIndicatorInsets = UIEdgeInsetsZero;
|
||||
} completion:nil];
|
||||
}
|
||||
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
#pragma mark - UITableViewDataSource
|
||||
|
||||
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
||||
@@ -351,6 +409,11 @@
|
||||
#pragma mark - Actions
|
||||
|
||||
- (void)submitButtonTapped {
|
||||
if (self.personaId <= 0) {
|
||||
[KBHUD showError:KBLocalized(@"Invalid parameter")];
|
||||
return;
|
||||
}
|
||||
|
||||
if (self.selectedReasonIndexes.count == 0) {
|
||||
[KBHUD showError:KBLocalized(@"Please select at least one report reason")];
|
||||
return;
|
||||
@@ -373,19 +436,53 @@
|
||||
[selectedContents addObject:self.contentOptions[index.integerValue]];
|
||||
}
|
||||
|
||||
NSString *description = self.descriptionTextView.text ?: @"";
|
||||
NSString *reportDesc = [self.descriptionTextView.text ?: @"" stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
|
||||
|
||||
NSLog(@"[AIReportVC] 举报人设 ID: %ld", (long)self.personaId);
|
||||
NSLog(@"[AIReportVC] 举报原因: %@", selectedReasons);
|
||||
NSLog(@"[AIReportVC] 内容类型: %@", selectedContents);
|
||||
NSLog(@"[AIReportVC] 描述: %@", description);
|
||||
|
||||
// TODO: 调用举报接口
|
||||
[KBHUD showSuccess:KBLocalized(@"Report submitted")];
|
||||
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[self.navigationController popViewControllerAnimated:YES];
|
||||
});
|
||||
NSLog(@"[AIReportVC] 描述: %@", reportDesc);
|
||||
|
||||
// 组装举报类型(从上到下 1-12:举报原因 1-9,内容类型 10-12)
|
||||
NSMutableArray<NSNumber *> *reportTypes = [NSMutableArray array];
|
||||
NSArray<NSNumber *> *sortedReasonIndexes = [[self.selectedReasonIndexes allObjects]
|
||||
sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES]]];
|
||||
for (NSNumber *index in sortedReasonIndexes) {
|
||||
NSInteger type = index.integerValue + 1;
|
||||
if (type > 0) {
|
||||
[reportTypes addObject:@(type)];
|
||||
}
|
||||
}
|
||||
NSArray<NSNumber *> *sortedContentIndexes = [[self.selectedContentIndexes allObjects]
|
||||
sortedArrayUsingDescriptors:@[[NSSortDescriptor sortDescriptorWithKey:@"self" ascending:YES]]];
|
||||
for (NSNumber *index in sortedContentIndexes) {
|
||||
NSInteger type = self.reportReasons.count + index.integerValue + 1;
|
||||
if (type > 0) {
|
||||
[reportTypes addObject:@(type)];
|
||||
}
|
||||
}
|
||||
|
||||
[KBHUD show];
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.viewModel reportCompanionWithCompanionId:self.personaId
|
||||
reportTypes:reportTypes
|
||||
reportDesc:reportDesc
|
||||
chatContext:nil
|
||||
evidenceImageUrl:nil
|
||||
completion:^(BOOL success, NSError * _Nullable error) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[KBHUD dismiss];
|
||||
if (!success) {
|
||||
NSString *msg = error.localizedDescription ?: KBLocalized(@"Network error");
|
||||
[KBHUD showError:msg];
|
||||
return;
|
||||
}
|
||||
[KBHUD showSuccess:KBLocalized(@"Report submitted")];
|
||||
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
||||
[weakSelf.navigationController popViewControllerAnimated:YES];
|
||||
});
|
||||
});
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Lazy Load
|
||||
@@ -395,6 +492,7 @@
|
||||
_scrollView = [[UIScrollView alloc] init];
|
||||
_scrollView.showsVerticalScrollIndicator = NO;
|
||||
_scrollView.alwaysBounceVertical = YES;
|
||||
_scrollView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag;
|
||||
}
|
||||
return _scrollView;
|
||||
}
|
||||
@@ -536,4 +634,11 @@
|
||||
return _submitButton;
|
||||
}
|
||||
|
||||
- (AiVM *)viewModel {
|
||||
if (!_viewModel) {
|
||||
_viewModel = [[AiVM alloc] init];
|
||||
}
|
||||
return _viewModel;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user