Files
peko-ios/YuMi/Modules/YMNewHome/View/CreateEventViewControllerV2.m

873 lines
37 KiB
Objective-C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// CreateEventViewControllerV2.m
// YuMi
//
// Created by P on 2025/5/9.
//
#import "CreateEventViewControllerV2.h"
#import <Masonry/Masonry.h>
#import <PhotosUI/PhotosUI.h>
#import <TZImagePickerController/TZImagePickerController.h>
#import "UploadFile.h"
#import "CreateEventPresenter.h"
#import "CreateEventPickerContainerView.h"
#import "CreateEventSelectRoomViewController.h"
#import "UIImage+Utils.h"
#define MAX_EVENT_TITLE_LENGTH 20
#define MAX_EVENT_CONTENT_LENGTH 100
@interface CreateEventViewControllerV2 () <UITextViewDelegate, UITextFieldDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate, PHPickerViewControllerDelegate, UIScrollViewDelegate, CreateEventPresenterProcotol, TZImagePickerControllerDelegate>
@property (nonatomic, strong) EventConfigModel *configModel;
@property (nonatomic, strong) EventRoomModel *selectRoomModel;
@property (nonatomic, strong) UIImage *selectedImage;
//@property (nonatomic, strong) UIView *durationPickerContainerView;
@property (nonatomic, strong) CreateEventPickerContainerView *durationPickerView;
@property (nonatomic, strong) UILabel *durationPickerTitleLabel;
@property (nonatomic, strong) UIButton *durationPickerOkButton;
@property (nonatomic, assign) NSInteger selectedHour;
@property (nonatomic, assign) NSInteger selectedMin;
// 添加私有方法声明
- (UIButton *)createUploadBannerButtonWithTitle:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName tag:(NSInteger)tag;
- (void)setupDatePicker; // 新增:设置日期选择器
- (void)hideDatePicker; // 新增:隐藏日期选择器
- (void)datePickerDoneTapped; // 新增:日期选择器确定按钮点击事件
- (void)datePickerCancelTapped; // 新增:日期选择器取消按钮点击事件
// 新增:时长选择器相关方法声明
- (void)setupDurationPicker;
- (void)showDurationPicker;
- (void)hideDurationPicker;
- (void)durationPickerOkTapped;
@end
@implementation CreateEventViewControllerV2
static const CGFloat kHorizontalPadding = 16.0;
static const CGFloat kVerticalPadding = 10.0;
static const CGFloat kSectionSpacing = 20.0;
- (CreateEventPresenter *)createPresenter {
return [CreateEventPresenter new];
}
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.title = @"Create Event";
[self setupUI];
[self updateEventTitleCharCount];
[self updateEventContentCharCount];
self.selectedDurationInMinutes = 120; // Default to 2 hours
[self updateDurationLabel];
// 键盘通知
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
// 点击空白收起键盘
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissKeyboard)];
tap.cancelsTouchesInView = NO;
[self.view addGestureRecognizer:tap];
// 设置 scrollView delegate
self.scrollView.delegate = self;
[self.presenter loadConfig];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)keyboardWillShow:(NSNotification *)notification {
NSDictionary *userInfo = notification.userInfo;
CGRect keyboardFrame = [userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
CGFloat keyboardHeight = keyboardFrame.size.height;
UIEdgeInsets insets = self.scrollView.contentInset;
insets.bottom = keyboardHeight + 20;
self.scrollView.contentInset = insets;
self.scrollView.scrollIndicatorInsets = insets;
}
- (void)keyboardWillHide:(NSNotification *)notification {
UIEdgeInsets insets = self.scrollView.contentInset;
insets.bottom = 0;
self.scrollView.contentInset = insets;
self.scrollView.scrollIndicatorInsets = insets;
}
- (void)dismissKeyboard {
[self.view endEditing:YES];
}
- (void)backButtonTapped {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)setupUI {
// ScrollView and ContentView
self.scrollView = [[UIScrollView alloc] init];
[self.view addSubview:self.scrollView];
self.contentView = [[UIView alloc] init];
[self.scrollView addSubview:self.contentView];
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
UIVisualEffectView *visualView = [[UIVisualEffectView alloc]initWithEffect:blurEffect];
[self.view addSubview:visualView];
// Create Event Button (fixed at bottom)
self.createEventButton = [UIButton buttonWithType:UIButtonTypeSystem];
[self.createEventButton setTitle:YMLocalizedString(@"20.20.59_text_8") forState:UIControlStateNormal];
[self.createEventButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; // Adjust color as needed
[self.createEventButton addGradientBackgroundWithColors:@[
UIColorFromRGB(0xe29030),
UIColorFromRGB(0xfcc074),
] startPoint:CGPointMake(0, 0.5) endPoint:CGPointMake(1, 0.5) cornerRadius:23];
[self.createEventButton setCornerRadius:23];
self.createEventButton.userInteractionEnabled = NO;
self.createEventButton.alpha = 0.3;
[self.createEventButton addTarget:self action:@selector(createEventButtonTapped) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.createEventButton];
[self.createEventButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(self.view).offset(20);
make.trailing.equalTo(self.view).offset(-20);
make.bottom.equalTo(self.view.mas_safeAreaLayoutGuideBottom).offset(-20);
make.height.mas_equalTo(46);
}];
[visualView mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.view);
make.top.mas_equalTo(self.createEventButton.mas_top).offset(-20);
}];
[self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.view.mas_safeAreaLayoutGuideTop);
make.bottom.leading.trailing.equalTo(self.view);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.scrollView);
make.width.equalTo(self.scrollView);
}];
[self setupEventTitleSection];
[self setupEventBannerSection];
[self setupUploadBannerSection];
[self setupSelectRoomSection];
[self setupStartTimeSection];
[self setupDurationSection];
[self setupEventContentSection];
[self setupNotifyMyFansSection];
}
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
}
#pragma mark - CreateEventPresenterProcotol
- (void)loadCongfigSuccess:(EventConfigModel *)model {
_configModel = model;
self.uploadBannerLabel.text = [NSString stringWithFormat:YMLocalizedString(@"20.20.59_text_11"),
@(model.goldNum)];
}
- (void)loadCongfigFailure:(NSString *)msg {
[self.navigationController popViewControllerAnimated:YES];
}
- (void)createEventSuccess {
[XNDJTDDLoadingTool hideHUD];
[self.navigationController popViewControllerAnimated:NO];
}
- (void)createEventFailure:(NSString *)msg {
[XNDJTDDLoadingTool hideHUD];
}
#pragma mark - Helper Methods
- (UIButton *)createUploadBannerButtonWithTitle:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString *)selectedImageName tag:(NSInteger)tag {
UIButton *b = [UIButton buttonWithType:UIButtonTypeCustom];
[b setImage:kImage(imageName) forState:UIControlStateNormal];
[b setImage:kImage(selectedImageName) forState:UIControlStateSelected];
[b setTitle:title forState:UIControlStateNormal];
[b setTitleColor:UIColorFromRGB(0x313131) forState:UIControlStateNormal];
[b.titleLabel setFont:kFontMedium(14)];
b.tag = tag;
return b;
}
- (UILabel *)createLabelWithText:(NSString *)text {
UILabel *label = [[UILabel alloc] init];
label.text = text;
label.font = kFontMedium(14);
label.textColor = UIColorFromRGB(0x313131);
return label;
}
- (UITextField *)createTextFieldWithPlaceholder:(NSString *)placeholder {
UITextField *textField = [[UITextField alloc] init];
textField.placeholder = placeholder;
textField.font = kFontRegular(14);
textField.textColor = UIColorFromRGB(0x313131);
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.layer.cornerRadius = 8;
textField.backgroundColor = UIColorFromRGB(0xf2f3f7);
return textField;
}
- (UILabel *)createCharCountLabel {
UILabel *label = [[UILabel alloc] init];
label.font = kFontRegular(12);
label.textColor = UIColorFromRGB(0x7b7b7d);
return label;
}
- (UIView *)createSelectionViewWithPlaceholder:(NSString *)placeholder target:(id)target action:(SEL)action {
UIView *view = [[UIView alloc] init];
view.backgroundColor = UIColorFromRGB(0xf2f3f7);
view.layer.cornerRadius = 8;
UILabel *label = [[UILabel alloc] init];
label.text = placeholder;
label.font = kFontRegular(14);
label.textColor = UIColorFromRGB(0x7b7b7d);
[view addSubview:label];
UIImageView *arrowImageView = [[UIImageView alloc] initWithImage:kImage(@"event_arrow")];
[view addSubview:arrowImageView];
[label mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.equalTo(view).offset(10);
make.centerY.equalTo(view);
}];
[arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.trailing.equalTo(view).offset(-10);
make.centerY.equalTo(view);
make.width.height.mas_equalTo(22);
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:target action:action];
[view addGestureRecognizer:tap];
view.userInteractionEnabled = YES;
if ([placeholder isEqualToString:YMLocalizedString(@"XPAnchorPKTableViewCell2")]) { // Store placeholder label for later update
if (action == @selector(selectRoomTapped)) self.selectRoomPlaceholderLabel = label;
else if (action == @selector(selectStartTimeTapped)) self.startTimePlaceholderLabel = label;
else if (action == @selector(selectDurationTapped)) self.durationPlaceholderLabel = label;
}
return view;
}
- (void)updateEventTitleCharCount {
NSInteger currentLength = self.eventTitleTextField.text.length;
self.eventTitleCharCountLabel.text = [NSString stringWithFormat:@"%ld/%d", (long)currentLength, MAX_EVENT_TITLE_LENGTH];
}
- (void)updateEventContentCharCount {
NSInteger currentLength = self.eventContentTextView.text.length;
self.eventContentCharCountLabel.text = [NSString stringWithFormat:@"%ld/%d", (long)currentLength, MAX_EVENT_CONTENT_LENGTH];
}
#pragma mark - Actions
- (void)eventBannerTapped {
NSLog(@"Event Banner Tapped");
if (@available(iOS 14, *)) {
// 使用TZImagePickerController来选择并裁剪图片
TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:self];
imagePickerVc.allowCrop = YES;
// 获取eventBannerImageView的实际尺寸比例
CGFloat viewWidth = self.view.frame.size.width - (kHorizontalPadding * 2 - 2);
CGFloat viewHeight = kGetScaleWidth(118);
CGFloat cropWidth = MIN(viewWidth, KScreenWidth);
CGFloat cropHeight = (viewHeight / viewWidth) * cropWidth;
// 设置裁剪框的尺寸
imagePickerVc.cropRect = CGRectMake((KScreenWidth-cropWidth)/2, (KScreenHeight - cropHeight) / 2, cropWidth, cropHeight);
[self presentViewController:imagePickerVc animated:YES completion:nil];
} else {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
}
- (void)selectRoomTapped {
NSLog(@"Select Room Tapped");
CreateEventSelectRoomViewController *vc = [[CreateEventSelectRoomViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
@kWeakify(self);
[vc setDidSelectedRoom:^(EventRoomModel * _Nonnull roomModel) {
@kStrongify(self);
self.selectRoomModel = roomModel;
self.selectRoomPlaceholderLabel.text = roomModel.roomName;
self.selectRoomPlaceholderLabel.textColor = [UIColor blackColor];
[self checkCreateEventButtonState];
}];
}
- (void)selectStartTimeTapped {
CreateEventPickerContainerView *view = [CreateEventPickerContainerView new];
__weak typeof(self) weakSelf = self;
[view showInView:self.view
initialDate:[NSDate date]
config:self.configModel
pickerType:CreateEventPickerTypeStartTime
onConfirm:^(NSDate *date, NSString *resultString) {
weakSelf.startTimePlaceholderLabel.text = resultString;
[weakSelf checkCreateEventButtonState];
}];
}
- (void)selectDurationTapped {
CreateEventPickerContainerView *view = [CreateEventPickerContainerView new];
__weak typeof(self) weakSelf = self;
[view showInView:self.view
initialDate:[NSDate date]
config:self.configModel
pickerType:CreateEventPickerTypeDuration
onConfirm:^(NSDate *date, NSString *resultString) {
weakSelf.durationPlaceholderLabel.text = resultString;
[weakSelf checkCreateEventButtonState];
}];
}
- (void)createEventButtonTapped {
NSLog(@"Create Event Tapped");
// Gather all data and proceed with event creation logic
NSString *title = self.eventTitleTextField.text;
UIImage *bannerImage = self.eventBannerImageView.image;
BOOL uploadToHomepage = self.uploadBannerYesButton.selected;
NSString *selectedRoom = self.selectRoomPlaceholderLabel.text; // This is a placeholder, get actual ID
NSString *startTime = self.startTimePlaceholderLabel.text; // This is a placeholder, get actual NSDate
NSString *duration = self.durationPlaceholderLabel.text; // This is a placeholder, get actual duration value
NSString *content = self.eventContentTextView.text;
BOOL notifyFans = self.notifyFansSwitch.isOn;
// Basic Validation (can be expanded)
if (title.length == 0) {
NSLog(@"Event title is missing");
return;
}
if (!bannerImage) {
NSLog(@"Event banner is missing");
// return; // Allow creating event without banner for now, or enforce
}
// ... more validations
NSLog(@"Title: %@, Upload: %d, Room: %@, Start: %@, Duration: %@, Content: %@, Notify: %d",
title, uploadToHomepage, selectedRoom, startTime, duration, content, notifyFans);
// TODO: 1. 补充 loading; 2. duration 使用 config 内容3. start time 使用 picker 内容
@kWeakify(self);
[self uploadCover:bannerImage
finish:^(NSString *path) {
@kStrongify(self);
[self.presenter createEventWithTitle:title
image:path
uploadToHome:uploadToHomepage
startTime:startTime
duration:30
content:content
notifyFans:notifyFans];
}];
}
- (void)uploadCover:(UIImage *)cover finish:(void(^)(NSString *path))finish {
[XNDJTDDLoadingTool showLoading];
NSData *data = UIImageJPEGRepresentation(cover, 0.7);
NSString *format = [UIImage getImageTypeWithImageData:data];
NSString *name = [NSString stringWithFormat:@"banner/%@.%@",[NSString createUUID],format];
[[UploadFile share]QCloudUploadImage:data named:name success:^(NSString * _Nonnull key, NSDictionary * _Nonnull resp) {
[XNDJTDDLoadingTool hideHUD];
if (finish) {
finish(key);
}
} failure:^(NSNumber * _Nonnull resCode, NSString * _Nonnull message) {
[XNDJTDDLoadingTool showErrorWithMessage:message];
}];
}
#pragma mark - UITextFieldDelegate
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if (textField == self.eventTitleTextField) {
NSString *newString = [textField.text stringByReplacingCharactersInRange:range withString:string];
if (newString.length > MAX_EVENT_TITLE_LENGTH) {
return NO;
}
}
return YES;
}
- (void)textFieldDidChangeSelection:(UITextField *)textField {
if (textField == self.eventTitleTextField) {
[self updateEventTitleCharCount];
[self checkCreateEventButtonState];
}
}
#pragma mark - UITextViewDelegate
- (void)textViewDidChange:(UITextView *)textView {
if (textView == self.eventContentTextView) {
[self updateEventContentCharCount];
[self checkCreateEventButtonState];
// Optional: Add placeholder behavior for UITextView if needed
}
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text {
if (textView == self.eventContentTextView) {
NSString *newText = [textView.text stringByReplacingCharactersInRange:range withString:text];
if (newText.length > MAX_EVENT_CONTENT_LENGTH) {
return NO;
}
}
return YES;
}
- (void)uploadBannerButtonTapped:(UIButton *)sender {
// TODO: 补充钱包判断
if (sender == self.uploadBannerYesButton) {
if (!self.uploadBannerYesButton.selected) { // 避免重复设置
self.uploadBannerYesButton.selected = YES;
self.uploadBannerNoButton.selected = NO;
// 可在此处处理横幅上传状态的逻辑,例如: self.shouldUploadBanner = YES;
}
} else if (sender == self.uploadBannerNoButton) {
if (!self.uploadBannerNoButton.selected) { // 避免重复设置
self.uploadBannerYesButton.selected = NO;
self.uploadBannerNoButton.selected = YES;
// 可在此处处理横幅上传状态的逻辑,例如: self.shouldUploadBanner = NO;
}
}
[self checkCreateEventButtonState];
}
#pragma mark - UIImagePickerControllerDelegate (Legacy)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
UIImage *selectedImage = info[UIImagePickerControllerOriginalImage];
if (selectedImage) {
// 对于iOS 14以下版本选择图片后手动裁剪
CGFloat viewWidth = self.view.frame.size.width - (kHorizontalPadding * 2 - 2);
CGFloat viewHeight = kGetScaleWidth(118);
CGSize cropSize = CGSizeMake(viewWidth, viewHeight);
UIImage *croppedImage = [selectedImage cutImage:cropSize];
self.selectedImage = croppedImage;
self.eventBannerImageView.image = croppedImage;
self.eventBannerCamearImageView.hidden = NO;
}
[picker dismissViewControllerAnimated:YES completion:nil];
[self checkCreateEventButtonState];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark - PHPickerViewControllerDelegate (iOS 14+)
- (void)picker:(PHPickerViewController *)picker didFinishPicking:(NSArray<PHPickerResult *> *)results API_AVAILABLE(ios(14)) {
[picker dismissViewControllerAnimated:YES completion:nil];
// 我们使用TZImagePickerController代替了PHPickerViewController这个方法不再需要
[self checkCreateEventButtonState];
}
#pragma mark - Date Picker Methods
- (void)setupDatePicker {
// Container View
self.datePickerContainerView = [[UIView alloc] init];
self.datePickerContainerView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.5]; // Semi-transparent background
[self.view addSubview:self.datePickerContainerView];
self.datePickerContainerView.hidden = YES; // Initially hidden
[self.datePickerContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
// Picker Toolbar
self.pickerToolbar = [[UIToolbar alloc] init];
self.pickerToolbar.barStyle = UIBarStyleDefault;
[self.pickerToolbar sizeToFit];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc] initWithTitle:@"Cancel" style:UIBarButtonItemStylePlain target:self action:@selector(datePickerCancelTapped)];
UIBarButtonItem *doneButton = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStyleDone target:self action:@selector(datePickerDoneTapped)];
UIBarButtonItem *flexibleSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.pickerToolbar setItems:@[cancelButton, flexibleSpace, doneButton]];
[self.datePickerContainerView addSubview:self.pickerToolbar];
// Date Picker
self.datePicker = [[UIDatePicker alloc] init];
self.datePicker.datePickerMode = UIDatePickerModeDateAndTime;
if (@available(iOS 13.4, *)) {
self.datePicker.preferredDatePickerStyle = UIDatePickerStyleWheels;
}
self.datePicker.backgroundColor = [UIColor whiteColor];
[self.datePickerContainerView addSubview:self.datePicker];
self.pickerToolbar.translatesAutoresizingMaskIntoConstraints = NO;
self.datePicker.translatesAutoresizingMaskIntoConstraints = NO;
// Constraints for Toolbar and DatePicker
[self.pickerToolbar mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.equalTo(self.datePickerContainerView);
make.bottom.equalTo(self.datePicker.mas_top);
make.height.mas_equalTo(44);
}];
[self.datePicker mas_makeConstraints:^(MASConstraintMaker *make) {
make.leading.trailing.bottom.equalTo(self.datePickerContainerView);
make.height.mas_equalTo(216);
}];
}
- (void)hideDatePicker {
[UIView animateWithDuration:0.3 animations:^{
self.datePickerContainerView.alpha = 0;
} completion:^(BOOL finished) {
self.datePickerContainerView.hidden = YES;
}];
}
- (void)datePickerDoneTapped {
self.selectedStartTime = self.datePicker.date;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; // Customize format as needed
NSString *formattedDate = [dateFormatter stringFromDate:self.selectedStartTime];
self.startTimePlaceholderLabel.text = formattedDate;
[self hideDatePicker];
}
- (void)datePickerCancelTapped {
[self hideDatePicker];
}
- (void)updateDurationLabel {
NSInteger hours = self.selectedDurationInMinutes / 60;
NSInteger minutes = self.selectedDurationInMinutes % 60;
NSString *durationString;
if (hours > 0 && minutes > 0) {
durationString = [NSString stringWithFormat:@"%ldh %ldm", (long)hours, (long)minutes];
} else if (hours > 0) {
durationString = [NSString stringWithFormat:@"%ldh", (long)hours];
} else if (minutes > 0) {
durationString = [NSString stringWithFormat:@"%ldm", (long)minutes];
} else {
durationString = @"Select"; // Or some default placeholder
}
UILabel *label = (UILabel *)[self.durationView viewWithTag:100];
if (label) {
label.text = durationString;
}
}
#pragma mark - Event Title Section
- (void)setupEventTitleSection {
self.eventTitleLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_9")];
[self.contentView addSubview:self.eventTitleLabel];
self.eventTitleTextField = [self createTextFieldWithPlaceholder:@""];
self.eventTitleTextField.delegate = self;
[self.contentView addSubview:self.eventTitleTextField];
self.eventTitleCharCountLabel = [self createCharCountLabel];
[self.contentView addSubview:self.eventTitleCharCountLabel];
[self.eventTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.contentView.mas_top).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.eventTitleTextField mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventTitleLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(40);
}];
[self.eventTitleCharCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY
.equalTo(self.eventTitleLabel);
make.trailing.equalTo(self.eventTitleTextField);
}];
}
#pragma mark - Event Banner Section
- (void)setupEventBannerSection {
self.eventBannerLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_10")];
[self.contentView addSubview:self.eventBannerLabel];
self.eventBannerImageView = [[UIImageView alloc] initWithImage:kImage(@"event_take_photo")];
self.eventBannerImageView.contentMode = UIViewContentModeScaleAspectFill;
self.eventBannerImageView.clipsToBounds = YES;
self.eventBannerImageView.layer.cornerRadius = 8;
self.eventBannerImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *bannerTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(eventBannerTapped)];
[self.eventBannerImageView addGestureRecognizer:bannerTap];
[self.contentView addSubview:self.eventBannerImageView];
self.eventBannerCamearImageView = [[UIImageView alloc] initWithImage:kImage(@"event_camear")];
self.eventBannerCamearImageView.hidden = YES;
[self.eventBannerImageView addSubview:self.eventBannerCamearImageView];
[self.eventBannerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventTitleTextField.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.eventBannerImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventBannerLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding-1);
make.height.mas_equalTo(kGetScaleWidth(118)); // Adjust height as needed
}];
[self.eventBannerCamearImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.trailing.equalTo(self.eventBannerImageView);
make.width.height.mas_equalTo(32);
}];
}
#pragma mark - Upload Banner Section
- (void)setupUploadBannerSection {
self.uploadBannerLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_11")];
[self.contentView addSubview:self.uploadBannerLabel];
self.uploadBannerYesButton = [self createUploadBannerButtonWithTitle:YMLocalizedString(@"20.20.59_text_12") imageName:@"event_non_select" selectedImageName:@"event_selected" tag:0];
self.uploadBannerYesButton.selected = NO;
[self.uploadBannerYesButton addTarget:self action:@selector(uploadBannerButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.uploadBannerYesButton];
self.uploadBannerNoButton = [self createUploadBannerButtonWithTitle:YMLocalizedString(@"20.20.59_text_13") imageName:@"event_non_select" selectedImageName:@"event_selected" tag:1];
self.uploadBannerNoButton.selected = YES;
[self.uploadBannerNoButton addTarget:self action:@selector(uploadBannerButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.uploadBannerNoButton];
[self.uploadBannerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventBannerImageView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.uploadBannerYesButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.uploadBannerLabel.mas_bottom).offset(kVerticalPadding);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
make.height.mas_equalTo(20);
}];
[self.uploadBannerNoButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.uploadBannerLabel.mas_bottom).offset(kVerticalPadding);
make.leading.equalTo(self.uploadBannerYesButton.mas_trailing).offset(70);
make.trailing.lessThanOrEqualTo(self.contentView).offset(-16);
make.height.height.equalTo(self.uploadBannerYesButton);
}];
}
#pragma mark - Select Room Section
- (void)setupSelectRoomSection {
self.selectRoomLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_14")];
[self.contentView addSubview:self.selectRoomLabel];
self.selectRoomView = [self createSelectionViewWithPlaceholder:YMLocalizedString(@"XPAnchorPKTableViewCell2") target:self action:@selector(selectRoomTapped)];
[self.contentView addSubview:self.selectRoomView];
[self.selectRoomLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.uploadBannerYesButton.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.selectRoomView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.selectRoomLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(44);
}];
}
#pragma mark - Start Time Section
- (void)setupStartTimeSection {
self.startTimeLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_15")];
[self.contentView addSubview:self.startTimeLabel];
self.startTimeView = [self createSelectionViewWithPlaceholder:YMLocalizedString(@"XPAnchorPKTableViewCell2")
target:self
action:@selector(selectStartTimeTapped)];
[self.contentView addSubview:self.startTimeView];
[self.startTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.selectRoomView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.startTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.startTimeLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(40);
}];
}
#pragma mark - Duration Section
- (void)setupDurationSection {
self.durationLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_16")];
[self.contentView addSubview:self.durationLabel];
self.durationView = [self createSelectionViewWithPlaceholder:YMLocalizedString(@"XPAnchorPKTableViewCell2") target:self action:@selector(selectDurationTapped)];
[self.contentView addSubview:self.durationView];
[self.durationLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.startTimeView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.durationView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.durationLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(40);
}];
}
#pragma mark - Event Content Section
- (void)setupEventContentSection {
self.eventContentLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_17")];
[self.contentView addSubview:self.eventContentLabel];
self.eventContentTextView = [[UITextView alloc] init];
self.eventContentTextView.backgroundColor = UIColorFromRGB(0xf2f3f7);
self.eventContentTextView.font = kFontRegular(14);
self.eventContentTextView.textColor = UIColorFromRGB(0x313131);
self.eventContentTextView.layer.cornerRadius = 8;
self.eventContentTextView.delegate = self;
[self.contentView addSubview:self.eventContentTextView];
self.eventContentCharCountLabel = [self createCharCountLabel];
[self.contentView addSubview:self.eventContentCharCountLabel];
[self.eventContentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.durationView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.eventContentTextView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventContentLabel.mas_bottom).offset(kVerticalPadding);
make.leading.trailing.equalTo(self.contentView).inset(kHorizontalPadding);
make.height.mas_equalTo(152);
}];
[self.eventContentCharCountLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.eventContentLabel);
make.trailing.equalTo(self.eventContentTextView.mas_trailing);
}];
}
#pragma mark - Notify My Fans Section
- (void)setupNotifyMyFansSection {
self.notifyFansLabel = [self createLabelWithText:YMLocalizedString(@"20.20.59_text_18")];
[self.contentView addSubview:self.notifyFansLabel];
self.notifyFansSwitch = [[UISwitch alloc] init];
[self.contentView addSubview:self.notifyFansSwitch];
[self.notifyFansLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.eventContentTextView.mas_bottom).offset(kSectionSpacing);
make.leading.equalTo(self.contentView).offset(kHorizontalPadding);
}];
[self.notifyFansSwitch mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(self.notifyFansLabel);
make.trailing.equalTo(self.contentView).offset(-kHorizontalPadding);
make.bottom.equalTo(self.contentView).offset(-kSectionSpacing*5);
}];
[self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.bottom.greaterThanOrEqualTo(self.notifyFansSwitch.mas_bottom).offset(kSectionSpacing*5);
}];
}
#pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
[self dismissKeyboard];
}
- (void)checkCreateEventButtonState {
NSString *placeholder = YMLocalizedString(@"XPAnchorPKTableViewCell2");
BOOL hasTitle = self.eventTitleTextField.text.length > 0;
BOOL hasBanner = self.selectedImage != nil;
BOOL hasRoom = self.selectRoomPlaceholderLabel.text.length > 0 && ![self.selectRoomPlaceholderLabel.text isEqualToString:placeholder];
BOOL hasStartTime = self.startTimePlaceholderLabel.text.length > 0 && ![self.startTimePlaceholderLabel.text isEqualToString:placeholder];
BOOL hasDuration = self.durationPlaceholderLabel.text.length > 0 && ![self.durationPlaceholderLabel.text isEqualToString:placeholder];
BOOL hasContent = self.eventContentTextView.text.length > 0;
if (hasTitle && hasBanner && hasRoom && hasStartTime && hasDuration && hasContent) {
self.createEventButton.alpha = 1.0;
self.createEventButton.userInteractionEnabled = YES;
} else {
self.createEventButton.alpha = 0.3;
self.createEventButton.userInteractionEnabled = NO;
}
}
#pragma mark - Duration Picker Methods
- (void)setupDurationPicker {
if (!self.durationPickerView) {
self.durationPickerView = [[CreateEventPickerContainerView alloc] init];
}
__weak typeof(self) weakSelf = self;
[self.durationPickerView showInView:self.view
initialDate:[NSDate date]
config:self.configModel
pickerType:CreateEventPickerTypeDuration
onConfirm:^(NSDate *date, NSString *resultString) {
weakSelf.durationPlaceholderLabel.text = resultString;
[weakSelf checkCreateEventButtonState];
}];
}
- (void)showDurationPicker {
[self setupDurationPicker];
[self.view bringSubviewToFront:self.durationPickerView];
self.durationPickerView.hidden = NO;
self.durationPickerView.alpha = 0;
[UIView animateWithDuration:0.25 animations:^{
self.durationPickerView.alpha = 1;
}];
}
- (void)hideDurationPicker {
[UIView animateWithDuration:0.25 animations:^{
self.durationPickerView.alpha = 0;
} completion:^(BOOL finished) {
self.durationPickerView.hidden = YES;
}];
}
- (void)durationPickerOkTapped {
[self hideDurationPicker];
// 更新 label
NSString *hourStr = [NSString stringWithFormat:@"%ldHours", (long)self.selectedHour];
NSString *minStr = [NSString stringWithFormat:@"%ldMins", (long)self.selectedMin];
if (self.selectedHour == 0 && self.selectedMin == 0) {
self.durationPlaceholderLabel.text = YMLocalizedString(@"XPAnchorPKTableViewCell2");
} else if (self.selectedMin == 0) {
self.durationPlaceholderLabel.text = hourStr;
} else if (self.selectedHour == 0) {
self.durationPlaceholderLabel.text = minStr;
} else {
self.durationPlaceholderLabel.text = [NSString stringWithFormat:@"%@ & %@", hourStr, minStr];
}
[self checkCreateEventButtonState];
}
#pragma mark - TZImagePickerControllerDelegate
- (void)imagePickerController:(TZImagePickerController *)picker didFinishPickingPhotos:(NSArray<UIImage *> *)photos sourceAssets:(NSArray *)assets isSelectOriginalPhoto:(BOOL)isSelectOriginalPhoto infos:(NSArray<NSDictionary *> *)infos {
if (photos.count > 0) {
UIImage *croppedImage = photos.firstObject;
self.selectedImage = croppedImage;
self.eventBannerImageView.image = croppedImage;
self.eventBannerCamearImageView.hidden = NO;
[self checkCreateEventButtonState];
}
}
@end