Files
peko-ios/YuMi/Modules/YMLogin/View/FeedBackViewController.m
eggmanQQQ 0544a6b8d0 #1217
新功能:反馈页
2024-07-04 10:18:42 +08:00

777 lines
31 KiB
Objective-C

//
// FeedBackViewController.m
// YuMi
//
// Created by P on 2024/7/2.
//
#import "FeedBackViewController.h"
#import "LoginPresenter.h"
#import "UploadFile.h"
#import "FeedBackConfigModel.h"
@interface FeedBackContactPopUpCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *content;
@property (nonatomic, strong) UIImageView *icon;
//@
@end
@implementation FeedBackContactPopUpCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
_content = [UILabel labelInitWithText:@""
font:[UIFont systemFontOfSize:16 weight:UIFontWeightBold]
textColor:UIColorFromRGB(0x333333)];
_icon = [[UIImageView alloc] initWithImage:kImage(@"user_card_copy_id1")];
[self.contentView addSubview:_content];
[self.contentView addSubview:_icon];
[_content mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.mas_equalTo(0);
}];
[_icon mas_makeConstraints:^(MASConstraintMaker *make) {
make.width.height.mas_equalTo(12);
make.centerY.mas_equalTo(self.content);
make.left.mas_equalTo(self.content.mas_right).offset(2);
}];
}
return self;
}
@end
@interface FeedBackContactPopUp : UIView<UICollectionViewDelegateFlowLayout, UICollectionViewDataSource>
@property (nonatomic, copy) NSArray *contactArray;
@property (nonatomic, strong) UICollectionView *collectionView;
@end
@implementation FeedBackContactPopUp
+ (CGFloat)popUpHeight:(NSDictionary *)dataSource {
return 32 + 75 + 14 * dataSource.count + 18 * dataSource.count;
}
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
self.backgroundColor = [UIColor whiteColor];
self.layer.cornerRadius = 15.5;
self.clipsToBounds = YES;
self.layer.masksToBounds = YES;
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
b.layer.cornerRadius = 19;
b.layer.masksToBounds = YES;
[b setTitle:YMLocalizedString(@"XPRoomViewController16") forState:UIControlStateNormal];
[b setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0x57e193),UIColorFromRGB(0x14d2a6)]
gradientType:GradientTypeLeftToRight
imgSize:CGSizeMake(120, 38)]
forState:UIControlStateNormal];
[b addTarget:self action:@selector(didTapButton) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:b];
[b mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self);
make.bottom.mas_equalTo(self).offset(-16);
make.height.mas_equalTo(38);
}];
UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
layout.scrollDirection = UICollectionViewScrollDirectionVertical;
_collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
_collectionView.backgroundColor = [UIColor clearColor];
_collectionView.scrollEnabled = NO;
_collectionView.delegate = self;
_collectionView.dataSource = self;
[_collectionView registerClass:[FeedBackContactPopUpCell class] forCellWithReuseIdentifier:@"cell"];
[self addSubview:_collectionView];
[_collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self).insets(UIEdgeInsetsMake(32, 0, 75, 0));
}];
}
- (void)setContactDic:(NSDictionary *)contactDic {
NSMutableArray *tempArr = @[].mutableCopy;
[contactDic enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) {
[tempArr addObject:@[key, obj]];
}];
_contactArray = tempArr;
[self.collectionView reloadData];
}
- (void)didTapButton {
[TTPopup dismiss];
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.contactArray.count;
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout *)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat padding = 24.0;
CGFloat totalPadding = padding * 2; // 左右两边的间距 + 中间两个间距
CGFloat availableWidth = collectionView.frame.size.width - totalPadding;
NSArray *subArray = [self.contactArray xpSafeObjectAtIndex:indexPath.row];
return CGSizeMake(availableWidth, subArray.count > 1 ? 14 : 0);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 18.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 18.0;
}
// 返回 cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
FeedBackContactPopUpCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
NSArray *subArray = [self.contactArray xpSafeObjectAtIndex:indexPath.row];
if (subArray.count > 1) {
cell.content.text = [NSString stringWithFormat:@"%@: %@", [subArray firstObject], [subArray lastObject]];
}
return cell;
}
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
NSArray *subArray = [self.contactArray xpSafeObjectAtIndex:indexPath.row];
if (subArray.count > 1) {
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:[subArray lastObject]];
[XNDJTDDLoadingTool showSuccessWithMessage:YMLocalizedString(@"XPShareView0")];
}
}
@end
@interface TypeCollectionCell : UICollectionViewCell
@property (nonatomic, strong) UILabel *titleLabel;
@end
@implementation TypeCollectionCell
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.contentView.userInteractionEnabled = YES;
_titleLabel = [UILabel labelInitWithText:@""
font:[UIFont systemFontOfSize:14 weight:UIFontWeightMedium] textColor:UIColorFromRGB(0x22252c)];
_titleLabel.layer.cornerRadius = 15.5;
_titleLabel.layer.masksToBounds = YES;
_titleLabel.textAlignment = NSTextAlignmentCenter;
_titleLabel.backgroundColor = UIColorFromRGB(0xf3f5fa);
_titleLabel.userInteractionEnabled = NO;
_titleLabel.minimumScaleFactor = 0.7;
_titleLabel.numberOfLines = 2;
[self.contentView addSubview:_titleLabel];
[_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.contentView);
}];
}
return self;
}
- (void)setSelected:(BOOL)selected {
if (selected) {
self.titleLabel.backgroundColor = UIColorFromRGB(0x85f6d3);
} else {
self.titleLabel.backgroundColor = UIColorFromRGB(0xf3f5fa);
}
}
@end
@interface FeedBackViewController ()<UITextViewDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout>
@property (nonatomic, strong) UIView *fakeTopBar;
@property (nonatomic, copy) NSString *uploadPhotoURLString;
@property (nonatomic, strong) UIImage *selectedImage;
@property (nonatomic, strong) FeedBackConfigModel *configModel;
@property (nonatomic, strong) FeedBackTypeModel *selectTypeModel;
@end
@implementation FeedBackViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self setup];
[self customLayout];
[self loadFeedbackConfig];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self addNavigationItemWithImageNames:@[@"login_custom_servise"]
isLeft:NO
target:self
action:@selector(rightButtonTapped) tags:nil];
}
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
}
- (LoginPresenter *)createPresenter {
return [[LoginPresenter alloc] init];
}
- (BOOL)isHiddenNavBar {
return YES;
}
- (void)setup {
self.title = YMLocalizedString(@"XPMineFeedbackViewController0");
self.view.backgroundColor = [UIColor whiteColor];
[self setupFakeTopBar];
[self.closeKeyboardButton setTitle:@"" forState:UIControlStateNormal];
self.typeCollectionView.delegate = self;
self.typeCollectionView.dataSource = self;
self.typeCollectionView.allowsSelection = YES;
[self.typeCollectionView registerClass:[TypeCollectionCell class] forCellWithReuseIdentifier:@"cell"];
self.feedbackTextView.delegate = self;
self.feedbackTextView.textContainerInset = UIEdgeInsetsMake(8, 8, 20, 8);
self.title_1.textColor = [UIColor blackColor];
self.title_2.textColor = [UIColor blackColor];
self.title_3.textColor = [UIColor blackColor];
self.title_4.textColor = [UIColor blackColor];
self.title_2.text = YMLocalizedString(@"FeedBackViewController2");
NSAttributedString *redMark = [[NSAttributedString alloc] initWithString:@"* "
attributes:@{NSForegroundColorAttributeName: UIColorFromRGB(0xeb5c2c),
NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightBold]}];
NSDictionary *defaultAttributes = @{NSForegroundColorAttributeName: UIColorFromRGB(0x000000),
NSFontAttributeName: [UIFont systemFontOfSize:16 weight:UIFontWeightBold]};
NSMutableAttributedString *attributedTitle_1 = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"FeedBackViewController0") attributes:defaultAttributes];
[attributedTitle_1 insertAttributedString:redMark atIndex:0];
NSMutableAttributedString *attributedTitle_2 = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"FeedBackViewController1") attributes:defaultAttributes];
[attributedTitle_2 insertAttributedString:redMark atIndex:0];
NSMutableAttributedString *attributedTitle_4 = [[NSMutableAttributedString alloc] initWithString:YMLocalizedString(@"FeedBackViewController3") attributes:defaultAttributes];
[attributedTitle_4 insertAttributedString:redMark atIndex:0];
self.title_1.attributedText = attributedTitle_1;
self.title_2.attributedText = attributedTitle_2;
self.title_4.attributedText = attributedTitle_4;
self.feedbackPlaceholderLabel.text = YMLocalizedString(@"FeedBackViewController4");
self.feedbackCharCountLabel.text = @"0";
if (isMSRTL()) {
self.feedbackCharCountLabel.textAlignment = NSTextAlignmentRight;
self.feedbackCharLimitLabel.textAlignment = NSTextAlignmentRight;
self.feedbackCharLimitLabel.text = @"300/";
} else {
self.feedbackCharCountLabel.textAlignment = NSTextAlignmentLeft;
self.feedbackCharLimitLabel.textAlignment = NSTextAlignmentLeft ;
self.feedbackCharLimitLabel.text = @"/300";
}
[self.uploadImageButton setTitle:@"" forState:UIControlStateNormal];
UIColor *placeholderColor = UIColorFromRGB(0xacb0b7);
self.contactTextField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:YMLocalizedString(@"FeedBackViewController5")
attributes:@{NSForegroundColorAttributeName: placeholderColor}];
[self.submitButton setTitle:YMLocalizedString(@"LoginForgetPasswordViewController6") forState:UIControlStateNormal];
[self.submitButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorFromRGB(0xa5eec8),UIColorFromRGB(0xabf5e3)]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(300, 50)]
forState:UIControlStateNormal];
[self.submitButton setBackgroundImage:[UIImage gradientColorImageFromColors:@[UIColorRGBAlpha(0x57e193, 0.5),UIColorRGBAlpha(0x1402a6, 0.5)]
gradientType:GradientTypeTopToBottom
imgSize:CGSizeMake(300, 50)]
forState:UIControlStateSelected];
}
- (void)setupFakeTopBar {
UIView *fakeTopBar = [[UIView alloc] init];
fakeTopBar.backgroundColor = UIColorFromRGB(0xebecf3);
[self.view addSubview:fakeTopBar];
_fakeTopBar = fakeTopBar;
CGFloat navigationBarHeight = self.navigationController.navigationBar.frame.size.height + [UIApplication sharedApplication].keyWindow.safeAreaInsets.top;
[fakeTopBar mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_top);
make.left.equalTo(self.view.mas_left);
make.right.equalTo(self.view.mas_right);
make.height.mas_equalTo(navigationBarHeight);
}];
UILabel *title = [UILabel labelInitWithText:YMLocalizedString(@"XPMineFeedbackViewController0")
font:[UIFont systemFontOfSize:17 weight:UIFontWeightMedium]
textColor:UIColorFromRGB(0x010101)];
[fakeTopBar addSubview:title];
[title mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(-16);
make.centerX.mas_equalTo(0);
}];
UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
[back enlargeTouchArea:UIEdgeInsetsMake(10, 10, 10, 10)];
[back.imageView setContentMode:UIViewContentModeScaleAspectFill];
[back setImage:kImage(@"room_info_back") forState:UIControlStateNormal];
[back addTarget:self
action:@selector(didTapBackButton)
forControlEvents:UIControlEventTouchUpInside];
if (isMSRTL()) {
back.imageView.transform = CGAffineTransformMakeScale(-1.0, 1.0);
}
[fakeTopBar addSubview:back];
[back mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(title);
make.width.height.mas_equalTo(15);
if (isMSRTL()) {
make.right.mas_equalTo(-16);
} else {
make.left.mas_equalTo(16);
}
}];
UIButton *cs = [UIButton buttonWithType:UIButtonTypeCustom];
[cs enlargeTouchArea:UIEdgeInsetsMake(10, 10, 10, 10)];
[cs setImage:kImage(@"login_custom_servise") forState:UIControlStateNormal];
[cs addTarget:self
action:@selector(rightButtonTapped)
forControlEvents:UIControlEventTouchUpInside];
[fakeTopBar addSubview:cs];
[cs mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.mas_equalTo(title);
make.width.height.mas_equalTo(18);
if (isMSRTL()) {
make.left.mas_equalTo(fakeTopBar).offset(16);
} else {
make.right.mas_equalTo(fakeTopBar).offset(-16);
}
}];
}
- (void)customLayout {
[self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.view).offset(-40);
make.left.mas_equalTo(36);
make.right.mas_equalTo(-36);
make.height.mas_equalTo(49);
}];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.fakeTopBar.mas_bottom).offset(0);
make.left.right.mas_equalTo(self.view);
make.bottom.mas_equalTo(self.submitButton.mas_top).offset(-8);
}];
[self.scrollContentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.scrollView);
}];
[self.title_1 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.scrollContentView).offset(30);
if (isMSRTL()) {
make.right.mas_equalTo(self.scrollContentView).offset(-16);
} else {
make.left.mas_equalTo(self.scrollContentView).offset(16);
}
}];
[self.typeCollectionView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.title_1.mas_bottom).offset(18);
make.left.mas_equalTo(self.scrollContentView).offset(16);
make.right.mas_equalTo(self.scrollContentView).offset(-16);
make.height.mas_equalTo(31);
make.width.mas_equalTo(KScreenWidth - 32);
}];
[self.closeKeyboardButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.typeCollectionView.mas_bottom);
make.bottom.left.right.mas_equalTo(self.scrollContentView);
}];
[self.title_2 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.typeCollectionView.mas_bottom).offset(31);
if (isMSRTL()) {
make.right.mas_equalTo(self.scrollContentView).offset(-16);
} else {
make.left.mas_equalTo(self.scrollContentView).offset(16);
}
}];
[self.feedbackTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.title_2.mas_bottom).offset(18);
make.left.mas_equalTo(self.scrollContentView).offset(16);
make.right.mas_equalTo(self.scrollContentView).offset(-16);
make.height.mas_equalTo(150);
}];
[self.feedbackPlaceholderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.feedbackTextView).offset(8);
if (isMSRTL()) {
make.right.mas_equalTo(self.feedbackTextView).offset(-8);
} else {
make.left.mas_equalTo(self.feedbackTextView).offset(8);
}
}];
[self.feedbackCharLimitLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.feedbackTextView).offset(-8);
make.width.mas_equalTo(40);
if (isMSRTL()) {
make.left.mas_equalTo(self.feedbackTextView).offset(8);
} else {
make.right.mas_equalTo(self.feedbackTextView).offset(-8);
}
}];
[self.feedbackCharCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.mas_equalTo(self.feedbackTextView).offset(-8);
if (isMSRTL()) {
make.left.mas_equalTo(self.feedbackCharLimitLabel.mas_right).offset(0);
} else {
make.right.mas_equalTo(self.feedbackCharLimitLabel.mas_left).offset(0);
}
}];
[self.title_3 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.feedbackTextView.mas_bottom).offset(31);
if (isMSRTL()) {
make.right.mas_equalTo(self.scrollContentView).offset(-16);
} else {
make.left.mas_equalTo(self.scrollContentView).offset(16);
}
}];
[self.uploadImageButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.title_3.mas_bottom).offset(18);
make.width.height.mas_equalTo(76);
if (isMSRTL()) {
make.right.mas_equalTo(self.scrollContentView).offset(-16);
} else {
make.left.mas_equalTo(self.scrollContentView).offset(16);
}
}];
[self.uploadImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(self.uploadImageButton);
}];
[self.title_4 mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.uploadImageButton.mas_bottom).offset(31);
if (isMSRTL()) {
make.right.mas_equalTo(self.scrollContentView).offset(-16);
} else {
make.left.mas_equalTo(self.scrollContentView).offset(16);
}
}];
[self.contactTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.mas_equalTo(self.scrollContentView).offset(16);
make.right.mas_equalTo(self.scrollContentView).offset(-16);
make.top.mas_equalTo(self.title_4.mas_bottom).offset(17.5);
make.bottom.mas_equalTo(self.scrollContentView).offset (-30);
make.height.mas_equalTo(43.5);
}];
}
- (void)updateSubmitButtonStatus {
if (self.selectTypeModel == nil) {
[self.submitButton setSelected:NO];
} else if(self.feedbackTextView.text.length == 0) {
[self.submitButton setSelected:NO];
} else if(self.contactTextField.text.length == 0) {
[self.submitButton setSelected:NO];
} else {
[self.submitButton setSelected:YES];
}
}
- (void)showPhotoSelectionSheet {
@kWeakify(self);
TTActionSheetConfig *cameraConfig = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineUserInfoEditViewController1") clickAction:^{
[YYUtility checkCameraAvailable:^{
@kStrongify(self);
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:NULL];
} denied:^{
@kStrongify(self);
[self showNotPhoto:YMLocalizedString(@"XPMineUserInfoEditViewController2") content:YMLocalizedString(@"XPMineUserInfoEditViewController3")];
} restriction:^{
@kStrongify(self);
[self showNotPhoto:YMLocalizedString(@"XPMineUserInfoEditViewController4") content:YMLocalizedString(@"XPMineUserInfoEditViewController5")];
}];
}];
TTActionSheetConfig *photoLibrayConfig = [TTActionSheetConfig normalTitle:YMLocalizedString(@"XPMineUserInfoEditViewController6") clickAction:^{
[YYUtility checkAssetsLibrayAvailable:^{
@kStrongify(self);
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.modalPresentationCapturesStatusBarAppearance = YES;
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.allowsEditing = NO;
[self presentViewController:imagePicker animated:YES completion:NULL];
} denied:^{
@kStrongify(self);
[self showNotPhoto:YMLocalizedString(@"XPMineUserInfoEditViewController7") content:YMLocalizedString(@"XPMineUserInfoEditViewController8")];
} restriction:^{
@kStrongify(self);
[self showNotPhoto:YMLocalizedString(@"XPMineUserInfoEditViewController9") content:YMLocalizedString(@"XPMineUserInfoEditViewController10")];
}];
}];
[TTPopup actionSheetWithItems:@[cameraConfig, photoLibrayConfig]];
}
- (void)showNotPhoto:(NSString *)title content:(NSString *)content {
TTAlertConfig *config = [[TTAlertConfig alloc] init];
config.title = title;
config.message = content;
[TTPopup alertWithConfig:config confirmHandler:^{
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
}];
}
} cancelHandler:^{
}];
}
#pragma mark - UX Actions
- (void)didTapBackButton {
[self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)didTapUploadImageButton:(id)sender {
[self showPhotoSelectionSheet];
}
- (IBAction)didTapSubmitButton:(id)sender {
if (self.submitButton.isSelected) {
[self uploadAvatar];
}
}
- (IBAction)didTapCloseKeyboardButton:(id)sender {
[self.view endEditing:YES];
}
- (void)rightButtonTapped {
FeedBackContactPopUp *popUp = [[FeedBackContactPopUp alloc] initWithFrame:CGRectMake(0,
0,
290,
[FeedBackContactPopUp popUpHeight:self.configModel.customContactMap])];
[popUp setContactDic:self.configModel.customContactMap];
[TTPopup popupView:popUp style:TTPopupStyleAlert];
}
#pragma mark - API
- (void)loadFeedbackConfig {
[self showLoading];
@kWeakify(self);
[self.presenter loadFeedbackConfig:^(FeedBackConfigModel * _Nonnull model) {
@kStrongify(self);
[self hideHUD];
self.configModel = model;
[self.typeCollectionView reloadData];
[self updateCollectionViewHeight];
} failure:^(NSString * _Nonnull errorMessage) {
@kStrongify(self);
[self hideHUD];
[TTPopup alertWithMessage:errorMessage confirmHandler:^{
} cancelHandler:^{
}];
}];
}
- (void)uploadAvatar {
[self showLoading];
if (self.selectedImage) {
@kWeakify(self);
NSData *data = UIImageJPEGRepresentation(self.selectedImage, 0.5);
NSString *format = [UIImage getImageTypeWithImageData:data];
NSString *name = [NSString stringWithFormat:@"image/%@.%@",[NSString createUUID],format];
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
@kStrongify(self);
self.uploadPhotoURLString = key;
[self submitFeedBack];
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
@kStrongify(self);
[self showErrorToast:message];
}];
} else {
[self submitFeedBack];
}
}
- (void)submitFeedBack {
@kWeakify(self);
dispatch_async(dispatch_get_main_queue(), ^{
@kStrongify(self);
@kWeakify(self);
[self.presenter submitFeedback:^{
@kStrongify(self);
[self showSuccessToast:YMLocalizedString(@"XPMineFeedbackViewController1")];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
} failure:^(NSString * _Nonnull errorMessage) {
@kStrongify(self);
[self showErrorToast:errorMessage];
}
type:self.selectTypeModel.type
desc:self.feedbackTextView.text
photoURLString:self.uploadPhotoURLString
contact:self.contactTextField.text];
});
}
#pragma mark - UICollectionView Delegate & DataSource
- (void)updateCollectionViewHeight {
[self.typeCollectionView layoutIfNeeded];
CGSize contentSize = self.typeCollectionView.collectionViewLayout.collectionViewContentSize;
[self.typeCollectionView mas_updateConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(contentSize.height);
}];
}
// 返回 section 中的 item 数量
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return self.configModel.typeEnumList.count; // 根据你的需求返回实际数量
}
- (CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
CGFloat padding = 24.0;
CGFloat totalPadding = padding * 2 + padding * 2; // 左右两边的间距 + 中间两个间距
CGFloat availableWidth = collectionView.frame.size.width - totalPadding;
CGFloat itemWidth = availableWidth / 3;
return CGSizeMake(itemWidth, 31);
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section {
return 14.0;
}
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section {
return 24.0;
}
// 返回 cell
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
TypeCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
cell.contentView.layer.cornerRadius = 15.5;
cell.contentView.layer.masksToBounds = YES;
FeedBackTypeModel *model = [self.configModel.typeEnumList xpSafeObjectAtIndex:indexPath.row];
if (model) {
cell.titleLabel.text = model.desc;
}
return cell;
}
// 处理 cell 的选中状态
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
TypeCollectionCell *cell = (TypeCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell setSelected:YES];
// 取消其他 cell 的选中状态
for (NSIndexPath *visibleIndexPath in [collectionView indexPathsForVisibleItems]) {
if (![visibleIndexPath isEqual:indexPath]) {
[collectionView deselectItemAtIndexPath:visibleIndexPath animated:NO];
TypeCollectionCell *otherCell = (TypeCollectionCell *)[collectionView cellForItemAtIndexPath:visibleIndexPath];
[otherCell setSelected:NO];
}
}
FeedBackTypeModel *model = [self.configModel.typeEnumList xpSafeObjectAtIndex:indexPath.row];
if (model) {
self.selectTypeModel = model;
[self updateSubmitButtonStatus];
}
}
// 处理 cell 的取消选中状态
- (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
TypeCollectionCell *cell = (TypeCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
[cell setSelected:NO];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *selectedPhoto = [info objectForKey:UIImagePickerControllerOriginalImage];
if (selectedPhoto) {
if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
UIImageWriteToSavedPhotosAlbum(selectedPhoto, nil, nil, nil);
}
self.selectedImage = selectedPhoto;
self.uploadImageView.hidden = NO;
self.uploadImageView.image = selectedPhoto;
// [self.uploadImageButton setBackgroundImage:selectedPhoto forState:UIControlStateNormal];
// [self.uploadImageButton setImage:selectedPhoto forState:UIControlStateNormal];
}
[picker dismissViewControllerAnimated:YES
completion:^{}];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[picker dismissViewControllerAnimated:YES
completion:^{}];
}
#pragma mark - UITextViewDelegate
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
self.feedbackCharCountLabel.text = [NSString stringWithFormat:@"%ld", (unsigned long)newText.length];
self.feedbackPlaceholderLabel.hidden = newText.length > 0;
self.feedbackCharCountLabel.textColor = newText.length > 0 ?
UIColorFromRGB(0x3fddac) : UIColorFromRGB(0xa7acb3);
[self updateSubmitButtonStatus];
if (newText.length > 300) {
return NO;
}
return YES;
}
@end