574 lines
26 KiB
Mathematica
574 lines
26 KiB
Mathematica
|
|
//
|
|||
|
|
// BottlePublishViewController.m
|
|||
|
|
// TreeHole
|
|||
|
|
//
|
|||
|
|
// Created by mambaxie on 2022/4/28.
|
|||
|
|
//
|
|||
|
|
|
|||
|
|
#import "BottlePublishViewController.h"
|
|||
|
|
#import "FSTextInputView.h"
|
|||
|
|
#import "BottleService.h"
|
|||
|
|
#import "BottleTypePickerViewController.h"
|
|||
|
|
#import "BottlePhotoCollectionCell.h"
|
|||
|
|
#import "TZImagePickerController+MTImagePicker.h"
|
|||
|
|
#import "KSPhotoBrowser.h"
|
|||
|
|
#import "MTActionSheet.h"
|
|||
|
|
#import "UIImage+Scale.h"
|
|||
|
|
#import "BottlePhotoCollectionView.h"
|
|||
|
|
#import "MTGridSelectView.h"
|
|||
|
|
#import "MTChatRecordInputView.h"
|
|||
|
|
#import "AudioPlayerView.h"
|
|||
|
|
|
|||
|
|
@interface BottlePublishViewController () <UICollectionViewDataSource, UICollectionViewDelegate, KSPhotoBrowserDelegate>
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UIView *topView;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UIImageView *iconImageView;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UILabel *typeLabel;
|
|||
|
|
@property (nonatomic, strong) UILabel *contentTypeLabel;
|
|||
|
|
@property (nonatomic, strong) UILabel *contentNumberLabel;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UIImageView *smallArrwoRightImageView;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) NSMutableArray<UIImage *> *photosM;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) KSPhotoBrowser *browser;
|
|||
|
|
@property (nonatomic, strong) UICollectionView *photosCollectionView;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) UIButton *sendButton;
|
|||
|
|
@property (nonatomic, strong) FSTextInputView *contentInputView;
|
|||
|
|
|
|||
|
|
@property (nonatomic, assign) int price;
|
|||
|
|
@property (nonatomic, strong) zhPopupController *pricePicker;
|
|||
|
|
|
|||
|
|
@property (nonatomic, strong) AudioPlayerView *audioPlayerView;
|
|||
|
|
@property (nonatomic, strong) PYThemeTextField *weChatTextFiled;
|
|||
|
|
|
|||
|
|
@end
|
|||
|
|
|
|||
|
|
@implementation BottlePublishViewController
|
|||
|
|
|
|||
|
|
- (void)viewDidLoad {
|
|||
|
|
[super viewDidLoad];
|
|||
|
|
|
|||
|
|
[self setupUI];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)setInfo:(BottleTypeInfo *)info {
|
|||
|
|
_info = info;
|
|||
|
|
|
|||
|
|
[self.iconImageView sd_setImageWithURL:[NSURL URLWithString:info.bottle_type_img2 ?: @""]];
|
|||
|
|
self.contentTypeLabel.text = self.typeLabel.text = info.bottle_type_name;
|
|||
|
|
[self.typeLabel sizeToFit];
|
|||
|
|
self.smallArrwoRightImageView.centerY = self.typeLabel.centerY = self.iconImageView.centerY;
|
|||
|
|
self.smallArrwoRightImageView.x = self.typeLabel.right;
|
|||
|
|
self.topView.right = self.smallArrwoRightImageView.right + FIX_SIZE(20);
|
|||
|
|
self.title = [NSString stringWithFormat:@"%@瓶", info.bottle_type_name];
|
|||
|
|
self.contentNumberLabel.text = [NSString stringWithFormat:@"No.%d", self.info.bottle_next_num];
|
|||
|
|
[self.contentNumberLabel sizeToFit];
|
|||
|
|
self.contentNumberLabel.x = self.contentTypeLabel.right + FIX_SIZE(4);
|
|||
|
|
self.contentNumberLabel.centerY = self.contentTypeLabel.centerY;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (BOOL)mt_nagationBarTransparent {
|
|||
|
|
return YES;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)setupUI {
|
|||
|
|
//#if DEBUG
|
|||
|
|
// self.info.content_min_image_num = 1;
|
|||
|
|
//#endif
|
|||
|
|
|
|||
|
|
[self.view removeSubviews];
|
|||
|
|
|
|||
|
|
UIImageView *bgImageView = [[UIImageView alloc] init];
|
|||
|
|
bgImageView.frame = self.view.bounds;
|
|||
|
|
bgImageView.image = ImageNamed(@"TH_bottle_bg");
|
|||
|
|
bgImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|||
|
|
[self.view addSubview:bgImageView];
|
|||
|
|
|
|||
|
|
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"TH_down_btn") style:UIBarButtonItemStyleDone target:self action:@selector(close)];
|
|||
|
|
|
|||
|
|
UIView *topView = [[UIView alloc] init];
|
|||
|
|
topView.width = SCREEN_WIDTH;
|
|||
|
|
topView.height = FIX_SIZE(45);
|
|||
|
|
topView.y = NAVIGATION_BAR_HEIGHT + FIX_SIZE(20);
|
|||
|
|
[self.view addSubview:topView];
|
|||
|
|
WeakSelf(self);
|
|||
|
|
[topView addTapWithAction:^{
|
|||
|
|
BottleTypePickerViewController *picker = [BottleTypePickerViewController pickerViewControllerWithCompletion:^(BottleTypePickerViewController * _Nonnull picker, BottleTypeInfo * _Nonnull info) {
|
|||
|
|
weakself.info = info;
|
|||
|
|
[weakself setupUI];
|
|||
|
|
[picker.navigationController dismissViewControllerAnimated:YES completion:nil];
|
|||
|
|
}];
|
|||
|
|
[weakself presentViewController:[[PYNavigationViewController alloc] initWithRootViewController:picker] animated:YES completion:nil];
|
|||
|
|
}];
|
|||
|
|
self.topView = topView;
|
|||
|
|
|
|||
|
|
PYImageView *iconImageView = [[PYImageView alloc] init];
|
|||
|
|
iconImageView.backgroundColor = [UIColor clearColor];
|
|||
|
|
iconImageView.size = CGSizeMake(FIX_SIZE(30), FIX_SIZE(30));
|
|||
|
|
iconImageView.x = FIX_SIZE(20);
|
|||
|
|
iconImageView.centerY = topView.height * 0.5;
|
|||
|
|
iconImageView.imageUrl = self.info.bottle_type_img;
|
|||
|
|
[topView addSubview:iconImageView];
|
|||
|
|
self.iconImageView = iconImageView;
|
|||
|
|
|
|||
|
|
UILabel *typeLabel = [[UILabel alloc] init];
|
|||
|
|
typeLabel.font = MT_FONT_REGULAR_SIZE(15);
|
|||
|
|
typeLabel.textColor = COLOR_WITH_RGB(0xC0C6C9);
|
|||
|
|
typeLabel.text = self.info.bottle_type_name;
|
|||
|
|
[typeLabel sizeToFit];
|
|||
|
|
typeLabel.centerY = iconImageView.centerY;
|
|||
|
|
typeLabel.x = iconImageView.right + FIX_SIZE(5);
|
|||
|
|
[topView addSubview:typeLabel];
|
|||
|
|
self.typeLabel = typeLabel;
|
|||
|
|
|
|||
|
|
UIImageView *smallArrwoRightImageView = [[UIImageView alloc] init];
|
|||
|
|
smallArrwoRightImageView.image = ImageNamed(@"TH_arrow_icon_small");
|
|||
|
|
smallArrwoRightImageView.size = CGSizeMake(FIX_SIZE(15), FIX_SIZE(15));
|
|||
|
|
smallArrwoRightImageView.centerY = typeLabel.centerY;
|
|||
|
|
smallArrwoRightImageView.left = typeLabel.right;
|
|||
|
|
self.smallArrwoRightImageView = smallArrwoRightImageView;
|
|||
|
|
[topView addSubview:smallArrwoRightImageView];
|
|||
|
|
topView.width = smallArrwoRightImageView.right + FIX_SIZE(20);
|
|||
|
|
|
|||
|
|
UIImageView *contentBgImageView = [[UIImageView alloc] init];
|
|||
|
|
contentBgImageView.image = ImageNamed(@"TH_pop_bottle_bg_white");
|
|||
|
|
contentBgImageView.width = self.view.width;
|
|||
|
|
contentBgImageView.height = self.view.width * contentBgImageView.image.size.height / contentBgImageView.image.size.width;
|
|||
|
|
contentBgImageView.y = topView.bottom;
|
|||
|
|
[self.view addSubview:contentBgImageView];
|
|||
|
|
contentBgImageView.userInteractionEnabled = YES;
|
|||
|
|
|
|||
|
|
UILabel *contentTypeLabel = [[UILabel alloc] init];
|
|||
|
|
contentTypeLabel.font = MT_FONT_BOLD_SIZE(30);
|
|||
|
|
contentTypeLabel.text = self.info.bottle_type_name;
|
|||
|
|
contentTypeLabel.textColor = COLOR_WITH_RGB_A(0xFFFFFF, 1.0);
|
|||
|
|
[contentTypeLabel sizeToFit];
|
|||
|
|
contentTypeLabel.x = FIX_SIZE(52);
|
|||
|
|
contentTypeLabel.y = FIX_SIZE(35);
|
|||
|
|
[contentBgImageView addSubview:contentTypeLabel];
|
|||
|
|
self.contentTypeLabel = contentTypeLabel;
|
|||
|
|
|
|||
|
|
UILabel *contentSubTypeLabel = [[UILabel alloc] init];
|
|||
|
|
contentSubTypeLabel.font = MT_FONT_BOLD_SIZE(20);
|
|||
|
|
contentSubTypeLabel.textColor = COLOR_WITH_RGB_A(0xFFFFFF, 1.0);
|
|||
|
|
[contentSubTypeLabel sizeToFit];
|
|||
|
|
contentSubTypeLabel.x = contentTypeLabel.right + FIX_SIZE(4);
|
|||
|
|
contentSubTypeLabel.centerY = contentTypeLabel.centerY;
|
|||
|
|
[contentBgImageView addSubview:contentSubTypeLabel];
|
|||
|
|
self.contentNumberLabel = contentSubTypeLabel;
|
|||
|
|
|
|||
|
|
UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeSystem];
|
|||
|
|
sendButton.width = FIX_SIZE(140);
|
|||
|
|
sendButton.height = FIX_SIZE(48);
|
|||
|
|
sendButton.backgroundColor = [UIColor whiteColor];
|
|||
|
|
sendButton.layer.cornerRadius = FIX_SIZE(16);
|
|||
|
|
sendButton.clipsToBounds = YES;
|
|||
|
|
[sendButton setTitleColor:COLOR_WITH_RGB(0x151032) forState:UIControlStateNormal];
|
|||
|
|
sendButton.titleLabel.font = MT_FONT_REGULAR_SIZE(15);
|
|||
|
|
[sendButton setTitle:@"🍾️ 放到酒柜" forState:UIControlStateNormal];
|
|||
|
|
sendButton.centerX = contentBgImageView.width * 0.5;
|
|||
|
|
sendButton.bottom = contentBgImageView.height - FIX_SIZE(40);
|
|||
|
|
[contentBgImageView addSubview:sendButton];
|
|||
|
|
sendButton.enabled = YES;
|
|||
|
|
// sendButton.alpha = 0.3;
|
|||
|
|
self.sendButton = sendButton;
|
|||
|
|
|
|||
|
|
UIView *lastBottomView = sendButton;
|
|||
|
|
|
|||
|
|
if (self.info.isPhotoAttachement) {
|
|||
|
|
BottlePhotoCollectionView *photosCollectionView = [BottlePhotoCollectionView collectionView];
|
|||
|
|
[contentBgImageView addSubview:photosCollectionView];
|
|||
|
|
lastBottomView = photosCollectionView;
|
|||
|
|
photosCollectionView.delegate = self;
|
|||
|
|
photosCollectionView.dataSource = self;
|
|||
|
|
photosCollectionView.x = FIX_SIZE(52.5);
|
|||
|
|
photosCollectionView.y = FIX_SIZE(95) + FIX_SIZE(123);
|
|||
|
|
photosCollectionView.width = SCREEN_WIDTH - FIX_SIZE(32.5) - photosCollectionView.x;
|
|||
|
|
self.photosM = [NSMutableArray array];
|
|||
|
|
self.photosCollectionView = photosCollectionView;
|
|||
|
|
} else if (self.info.isVoiceAttachement) {
|
|||
|
|
UIButton *voiceRecordButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|||
|
|
[voiceRecordButton setTitle:@"点击添加语音" forState:UIControlStateNormal];
|
|||
|
|
[voiceRecordButton setTitleColor:COLOR_WITH_RGB(0x333333) forState:UIControlStateNormal];
|
|||
|
|
[voiceRecordButton setBackgroundColor:[UIColor whiteColor]];
|
|||
|
|
voiceRecordButton.layer.cornerRadius = 3;
|
|||
|
|
voiceRecordButton.layer.borderWidth = 0.5;
|
|||
|
|
voiceRecordButton.layer.borderColor = COLOR_WITH_RGB(0x979797).CGColor;
|
|||
|
|
voiceRecordButton.clipsToBounds = YES;
|
|||
|
|
voiceRecordButton.titleLabel.font = MT_FONT_REGULAR_SIZE(13);
|
|||
|
|
voiceRecordButton.size = CGSizeMake(FIX_SIZE(180), FIX_SIZE(34));
|
|||
|
|
voiceRecordButton.x = FIX_SIZE(52.5);
|
|||
|
|
voiceRecordButton.y = FIX_SIZE(248);
|
|||
|
|
[contentBgImageView addSubview:voiceRecordButton];
|
|||
|
|
lastBottomView = voiceRecordButton;
|
|||
|
|
|
|||
|
|
UILabel *tipsLabel = [[UILabel alloc] init];
|
|||
|
|
tipsLabel.x = voiceRecordButton.x;
|
|||
|
|
tipsLabel.y = voiceRecordButton.bottom + FIX_SIZE(8);
|
|||
|
|
tipsLabel.width = contentBgImageView.width - tipsLabel.x - FIX_SIZE(52.5);
|
|||
|
|
tipsLabel.textColor = COLOR_WITH_RGB(0xF0D399);
|
|||
|
|
tipsLabel.font = MT_FONT_REGULAR_SIZE(14);
|
|||
|
|
tipsLabel.text = @"你可以打个招呼:陌生人你好,你在干什么呢?也可以唱首歌~~~不能低于5s哦~";
|
|||
|
|
tipsLabel.numberOfLines = 0;
|
|||
|
|
[tipsLabel sizeToFit];
|
|||
|
|
[contentBgImageView addSubview:tipsLabel];
|
|||
|
|
|
|||
|
|
AudioPlayerView *audioPlayerView = [[AudioPlayerView alloc] initWithFrame:voiceRecordButton.frame];
|
|||
|
|
audioPlayerView.hidden = YES;
|
|||
|
|
[contentBgImageView addSubview:audioPlayerView];
|
|||
|
|
self.audioPlayerView = audioPlayerView;
|
|||
|
|
|
|||
|
|
UIButton *deleteAudioButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|||
|
|
[deleteAudioButton setImageEdgeInsets:UIEdgeInsetsMake(8, 8, 8, 8)];
|
|||
|
|
deleteAudioButton.size = CGSizeMake(30, 30);
|
|||
|
|
deleteAudioButton.centerY = audioPlayerView.centerY;
|
|||
|
|
deleteAudioButton.x = audioPlayerView.right + 2;
|
|||
|
|
[deleteAudioButton setImage:ImageNamed(@"TH_square_icon_close") forState:UIControlStateNormal];
|
|||
|
|
[contentBgImageView addSubview:deleteAudioButton];
|
|||
|
|
deleteAudioButton.hidden = YES;
|
|||
|
|
|
|||
|
|
[voiceRecordButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
MTChatRecordInputView *voiceRecordView = [[MTChatRecordInputView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, FIX_SIZE(218) + homeIndicatorHeight())];
|
|||
|
|
zhPopupController *popupVC = [MTAlertView showActionSheetWithCustomView:voiceRecordView];
|
|||
|
|
WeakSelf(popupVC);
|
|||
|
|
voiceRecordView.backgroundColor = BG_COLOR;
|
|||
|
|
voiceRecordView.completion = ^(NSString *path, int second) {
|
|||
|
|
[audioPlayerView updateWithAudioUrl:path seconds:second];
|
|||
|
|
button.hidden = YES;
|
|||
|
|
tipsLabel.hidden = button.hidden;
|
|||
|
|
audioPlayerView.hidden = deleteAudioButton.hidden = !button.hidden;
|
|||
|
|
[weakpopupVC dismiss];
|
|||
|
|
};
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
[deleteAudioButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
[audioPlayerView updateWithAudioUrl:@"" seconds:0];
|
|||
|
|
button.hidden = YES;
|
|||
|
|
audioPlayerView.hidden = button.hidden;
|
|||
|
|
tipsLabel.hidden = voiceRecordButton.hidden = !button.hidden;
|
|||
|
|
}];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (self.info.isShellPhotos) {
|
|||
|
|
[self.sendButton setTitle:@"下一步" forState:UIControlStateNormal];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
FSTextInputView *contentInputView = [[FSTextInputView alloc] init];
|
|||
|
|
contentInputView.padding = UIEdgeInsetsZero;
|
|||
|
|
contentInputView.backgroundColor = [UIColor clearColor];
|
|||
|
|
contentInputView.x = FIX_SIZE(52.5);
|
|||
|
|
contentInputView.width = contentBgImageView.width - contentInputView.x - FIX_SIZE(52.5);
|
|||
|
|
contentInputView.y = FIX_SIZE(95);
|
|||
|
|
contentInputView.textview.tintColor = COLOR_WITH_RGB(0xFFBE00);
|
|||
|
|
contentInputView.height = lastBottomView.y - FIX_SIZE(10) - contentInputView.y;
|
|||
|
|
contentInputView.textview.font = contentInputView.placeHolderLabel.font = MT_FONT_REGULAR_SIZE(14);
|
|||
|
|
contentInputView.textview.textColor = [UIColor whiteColor];
|
|||
|
|
contentInputView.placeHolderLabel.textColor = COLOR_WITH_RGB(0xD6D5DF);
|
|||
|
|
contentInputView.placeHolderLabel.text = _info.send_content_tip.length ? _info.send_content_tip : @"\n「放瓶子须知」\n1.你放置的瓶子7日后会自动消失\n2.瓶子被超过3人举报,也会自动消失\n3.瓶子内如果包含违规违规内容,轻则被警告,重则会被封号(人工巡查)";
|
|||
|
|
[contentBgImageView addSubview:contentInputView];
|
|||
|
|
// contentInputView.didChangeText = ^(FSTextInputView *inputView) {
|
|||
|
|
// [weakself updateSendButton];
|
|||
|
|
// };
|
|||
|
|
self.contentInputView = contentInputView;
|
|||
|
|
self.info = self.info;
|
|||
|
|
// self.info.content_max_image_num = 9;
|
|||
|
|
[sendButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
if (weakself.contentInputView.textview.text.length <= 0) {
|
|||
|
|
[SVProgressHUD showInfoWithStatus:@"请输入文字"];
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (weakself.info.isPhotoAttachement && weakself.photosM.count < weakself.info.content_min_image_num) {
|
|||
|
|
[SVProgressHUD showInfoWithStatus:[NSString stringWithFormat:@"请放入至少%d张照片", weakself.info.content_min_image_num]];
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (weakself.info.isVoiceAttachement && weakself.audioPlayerView.audioUrl.length <= 0) {
|
|||
|
|
[SVProgressHUD showInfoWithStatus:@"请放入语音"];
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (weakself.info.isShellPhotos) {
|
|||
|
|
[weakself showPricePicker];
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
[weakself sendBottle];
|
|||
|
|
}];
|
|||
|
|
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.35 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
|
|||
|
|
// [contentInputView.textview becomeFirstResponder];
|
|||
|
|
// });
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)sendBottle {
|
|||
|
|
[AudioPlayerView stopPlay];
|
|||
|
|
[SVProgressHUD showWithStatus:@"发布中..."];
|
|||
|
|
__block NSArray *imageURLs = nil;
|
|||
|
|
__block NSString *voiceURL = nil;
|
|||
|
|
__block int voiceSec = 0;
|
|||
|
|
void (^publishAction)(void) = ^{
|
|||
|
|
[BottleService publishBottleWithGroupType:self.info.bottle_group_type
|
|||
|
|
type:self.info.bottle_type
|
|||
|
|
content:self.contentInputView.textview.text
|
|||
|
|
images:imageURLs
|
|||
|
|
voice:voiceURL
|
|||
|
|
voiceSec:voiceSec
|
|||
|
|
price:self.price
|
|||
|
|
weChat:self.weChatTextFiled.text
|
|||
|
|
completion:^(id _Nullable rsp, NSError * _Nullable error) {
|
|||
|
|
if (!error) {
|
|||
|
|
[SVProgressHUD showSuccessWithStatus:@"发布成功"];
|
|||
|
|
if (self.audioPlayerView.audioUrl.length > 0) {
|
|||
|
|
[[NSFileManager defaultManager] removeItemAtPath:self.audioPlayerView.audioUrl error:nil];
|
|||
|
|
}
|
|||
|
|
if (self.publishSucceedAction) {
|
|||
|
|
self.publishSucceedAction();
|
|||
|
|
}
|
|||
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
|||
|
|
[self.pricePicker dismiss];
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
};
|
|||
|
|
if (self.info.isPhotoAttachement) {
|
|||
|
|
NSMutableArray *datasM = [NSMutableArray array];
|
|||
|
|
for (UIImage *image in self.photosM) {
|
|||
|
|
[datasM addObject:compressImageToDataIfNeed(image)];
|
|||
|
|
}
|
|||
|
|
[PYHTTPManager uploadFileWithScene:AliOSSUploadSceneBottlePhoto datas:datasM completion:^(id _Nullable rsp, NSError * _Nullable error) {
|
|||
|
|
if (!error) {
|
|||
|
|
imageURLs = rsp;
|
|||
|
|
publishAction();
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
} else if (self.info.isVoiceAttachement) {
|
|||
|
|
[PYHTTPManager uploadFileWithScene:AliOSSUploadSceneBottleVoice data:[[NSData alloc] initWithContentsOfFile:self.audioPlayerView.audioUrl] completion:^(id _Nullable rsp, NSError * _Nullable error) {
|
|||
|
|
if (!error) {
|
|||
|
|
voiceURL = rsp;
|
|||
|
|
voiceSec = (int)self.audioPlayerView.seconds;
|
|||
|
|
publishAction();
|
|||
|
|
}
|
|||
|
|
}];
|
|||
|
|
} else {
|
|||
|
|
publishAction();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//- (void)updateSendButton {
|
|||
|
|
// BOOL hasContent = self.contentInputView.textview.text.length > 0;
|
|||
|
|
// BOOL canPublish = NO;
|
|||
|
|
// if ([self.info isPhotoAttachement]) {
|
|||
|
|
// canPublish = self.photosM.count >= self.info.content_min_image_num && hasContent;
|
|||
|
|
// } else if ([self.info isVoiceAttachement]) {
|
|||
|
|
// canPublish = self.audioPlayerView.audioUrl.length > 0 && hasContent;
|
|||
|
|
// } else {
|
|||
|
|
// canPublish = hasContent;
|
|||
|
|
// }
|
|||
|
|
// self.sendButton.alpha = canPublish ? 1.0 : 0.3;
|
|||
|
|
//}
|
|||
|
|
|
|||
|
|
- (void)close {
|
|||
|
|
[self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (BOOL)canAddPhoto {
|
|||
|
|
return self.photosM.count < self.info.content_max_image_num;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)showPricePicker {
|
|||
|
|
//todo
|
|||
|
|
UIView *pricePickerView = [[UIView alloc] init];
|
|||
|
|
pricePickerView.backgroundColor = SUB_BG_COLOR;
|
|||
|
|
pricePickerView.width = SCREEN_WIDTH;
|
|||
|
|
// pricePickerView.height = FIX_SIZE(217);
|
|||
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|||
|
|
titleLabel.text = @"微信号";
|
|||
|
|
titleLabel.font = MT_FONT_REGULAR_SIZE(16);
|
|||
|
|
titleLabel.textColor = [UIColor whiteColor];
|
|||
|
|
[titleLabel sizeToFit];
|
|||
|
|
titleLabel.y = FIX_SIZE(20);
|
|||
|
|
titleLabel.x = FIX_SIZE(15);
|
|||
|
|
[pricePickerView addSubview:titleLabel];
|
|||
|
|
|
|||
|
|
UIButton *tipsButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|||
|
|
[tipsButton setBackgroundImage:ImageNamed(@"TH_icon_question") forState:UIControlStateNormal];
|
|||
|
|
tipsButton.size = CGSizeMake(FIX_SIZE(32), FIX_SIZE(32));
|
|||
|
|
tipsButton.y = FIX_SIZE(15);
|
|||
|
|
tipsButton.right = SCREEN_WIDTH - FIX_SIZE(10);
|
|||
|
|
[pricePickerView addSubview:tipsButton];
|
|||
|
|
[tipsButton addTouchUpInsideWithAction:^(UIButton * _Nullable button) {
|
|||
|
|
[MTAlertView showWithSetupBlcok:^(MTAlertViewConfig *config) {
|
|||
|
|
config.message = @"1)该瓶子会在人工审核OK后才会发布到小酒馆\n2)平台收取50%手续费\n3)10酒币 = 1元";
|
|||
|
|
config.otherTitle = @"确认";
|
|||
|
|
}];
|
|||
|
|
}];
|
|||
|
|
|
|||
|
|
PYThemeTextField *weChatTextFiled = [PYThemeTextField fieldWithPlaceholder:self.info.wx_tips maxLength:30];
|
|||
|
|
weChatTextFiled.textField.font = MT_FONT_REGULAR_SIZE(13);
|
|||
|
|
weChatTextFiled.y = titleLabel.bottom + FIX_SIZE(15);
|
|||
|
|
weChatTextFiled.x = FIX_SIZE(15);
|
|||
|
|
weChatTextFiled.height = FIX_SIZE(48);
|
|||
|
|
weChatTextFiled.backgroundColor = COLOR_WITH_RGB(0x2D2943);
|
|||
|
|
weChatTextFiled.width = pricePickerView.width - weChatTextFiled.x * 2;
|
|||
|
|
[pricePickerView addSubview:weChatTextFiled];
|
|||
|
|
self.weChatTextFiled = weChatTextFiled;
|
|||
|
|
|
|||
|
|
|
|||
|
|
UILabel *priceTitleLabel = [[UILabel alloc] init];
|
|||
|
|
priceTitleLabel.text = @"价格";
|
|||
|
|
priceTitleLabel.font = MT_FONT_REGULAR_SIZE(16);
|
|||
|
|
priceTitleLabel.textColor = [UIColor whiteColor];
|
|||
|
|
[priceTitleLabel sizeToFit];
|
|||
|
|
priceTitleLabel.y = weChatTextFiled.bottom + FIX_SIZE(20);
|
|||
|
|
priceTitleLabel.x = FIX_SIZE(15);
|
|||
|
|
[pricePickerView addSubview:priceTitleLabel];
|
|||
|
|
|
|||
|
|
UILabel *priceTipsLabel = [[UILabel alloc] init];
|
|||
|
|
priceTipsLabel.text = @"(10酒币=1元)";
|
|||
|
|
priceTipsLabel.font = MT_FONT_REGULAR_SIZE(11);
|
|||
|
|
priceTipsLabel.textColor = COLOR_WITH_RGB(0xA5A5A5);
|
|||
|
|
[priceTipsLabel sizeToFit];
|
|||
|
|
priceTipsLabel.bottom = priceTitleLabel.bottom;
|
|||
|
|
priceTipsLabel.x = priceTitleLabel.right + FIX_SIZE(2);
|
|||
|
|
[pricePickerView addSubview:priceTipsLabel];
|
|||
|
|
|
|||
|
|
WeakSelf(self);
|
|||
|
|
NSMutableArray *pricesM = [NSMutableArray array];
|
|||
|
|
for (NSNumber *price in self.info.prices) {
|
|||
|
|
[pricesM addObject:[NSString stringWithFormat:@"%d酒币", price.intValue]];
|
|||
|
|
}
|
|||
|
|
CGFloat maxColumn = 3;
|
|||
|
|
MTGridSelectView *gridSelectView = [MTGridSelectView gridSelectViewWithItemModels:pricesM setupConfig:^(MTGridSelectConfig * _Nonnull config) {
|
|||
|
|
config.rowSpacing = 9;
|
|||
|
|
config.contentInset = UIEdgeInsetsMake(15, 15, 15, 15);
|
|||
|
|
CGFloat width = (SCREEN_WIDTH - 30 - config.rowSpacing * maxColumn - 1) / maxColumn;
|
|||
|
|
config.itemSize = CGSizeMake(width, 55);
|
|||
|
|
config.multiple = NO;
|
|||
|
|
} didSetupItemContentView:^UIView *(UIView * _Nonnull itemContentView, NSString * _Nonnull itemModel) {
|
|||
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|||
|
|
titleLabel.frame = itemContentView.bounds;
|
|||
|
|
titleLabel.layer.cornerRadius = 8;
|
|||
|
|
titleLabel.clipsToBounds = YES;
|
|||
|
|
titleLabel.font = MT_FONT_REGULAR_SIZE(15);
|
|||
|
|
titleLabel.backgroundColor = COLOR_WITH_RGB(0x2D2943);
|
|||
|
|
titleLabel.textAlignment = NSTextAlignmentCenter;
|
|||
|
|
titleLabel.textColor = UIColor.whiteColor;
|
|||
|
|
titleLabel.text = itemModel;
|
|||
|
|
return titleLabel;
|
|||
|
|
} itemStateChanged:^(UIView * _Nonnull itemView, id _Nonnull itemModel, MTGridItemState state, BOOL changeByInner) {
|
|||
|
|
itemView.layer.borderWidth = state == MTGridItemStateSelected ? 2.0 : 0.0;
|
|||
|
|
itemView.layer.borderColor = state == MTGridItemStateSelected ? THEME_COLOR.CGColor : nil;
|
|||
|
|
} selectValueChanged:^(NSArray * _Nonnull selectedModels) {
|
|||
|
|
weakself.price = [[[selectedModels firstObject] stringByReplacingOccurrencesOfString:@"酒币" withString:@""] intValue];
|
|||
|
|
}];
|
|||
|
|
gridSelectView.y = priceTipsLabel.bottom;
|
|||
|
|
CGFloat maxRow = ceil(pricesM.count / maxColumn);
|
|||
|
|
gridSelectView.height = 55 * maxRow + 9 * (maxRow - 1) + 30;
|
|||
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|||
|
|
[gridSelectView selectItemAtIndex:0];
|
|||
|
|
});
|
|||
|
|
[pricePickerView addSubview:gridSelectView];
|
|||
|
|
PYThemeButton *sendButton = [PYThemeButton normalButtonWithTitle:@"放到酒柜" action:^(UIButton * _Nonnull button) {
|
|||
|
|
if (weakself.weChatTextFiled.text.length <= 0) {
|
|||
|
|
[SVProgressHUD showInfoWithStatus:@"请输入微信号"];
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
[weakself sendBottle];
|
|||
|
|
}];
|
|||
|
|
sendButton.height = 48;
|
|||
|
|
sendButton.layer.cornerRadius = 20;
|
|||
|
|
sendButton.x = 15;
|
|||
|
|
sendButton.width = SCREEN_WIDTH - 30;
|
|||
|
|
sendButton.backgroundColor = THEME_COLOR;
|
|||
|
|
sendButton.y = gridSelectView.bottom;
|
|||
|
|
pricePickerView.height = sendButton.bottom + FIX_SIZE(27);
|
|||
|
|
[pricePickerView addSubview:sendButton];
|
|||
|
|
[pricePickerView setCorners:UIRectCornerTopLeft | UIRectCornerTopRight radius:FIX_SIZE(20)];
|
|||
|
|
self.pricePicker = [MTAlertView showActionSheetWithCustomView:pricePickerView];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - UICollectionViewDataSource
|
|||
|
|
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
|
|||
|
|
return 1;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
|
|||
|
|
// [self updateSendButton];
|
|||
|
|
return self.photosM.count + ([self canAddPhoto] ? 1 : 0);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|||
|
|
BottlePhotoCollectionCell *cell = (BottlePhotoCollectionCell *)[collectionView dequeueReusableCellWithReuseIdentifier:BottlePhotoCollectionCellReuseID forIndexPath:indexPath];
|
|||
|
|
|
|||
|
|
if (indexPath.item == 0 && [self canAddPhoto]) { // Add
|
|||
|
|
cell.photo = ImageNamed(@"TH_sel_photo_add_icon");
|
|||
|
|
cell.isAdd = YES;
|
|||
|
|
cell.deleBtn.hidden = YES;
|
|||
|
|
} else {
|
|||
|
|
cell.isAdd = NO;
|
|||
|
|
cell.deleBtn.hidden = NO;
|
|||
|
|
cell.photo = self.photosM[indexPath.item - ([self canAddPhoto] ? 1 : 0)];
|
|||
|
|
}
|
|||
|
|
return cell;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - UICollectionViewDelegate
|
|||
|
|
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
|
|||
|
|
BottlePhotoCollectionCell *cell = (BottlePhotoCollectionCell *)[collectionView cellForItemAtIndexPath:indexPath];
|
|||
|
|
if (cell.isAdd) { // Add
|
|||
|
|
TZImagePickerController *imagePicker = [TZImagePickerController mt_imagePickerWithMaxImagesCount:self.info.content_max_image_num - self.photosM.count didFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
|
|||
|
|
[self.photosM addObjectsFromArray:photos];
|
|||
|
|
[collectionView reloadData];
|
|||
|
|
}];
|
|||
|
|
[self.navigationController presentViewController:imagePicker animated:YES completion:nil];
|
|||
|
|
} else { // Preview
|
|||
|
|
NSMutableArray *items = @[].mutableCopy;
|
|||
|
|
NSUInteger index = [self canAddPhoto] ? indexPath.item - 1 : indexPath.item;
|
|||
|
|
for (int i = 0; i < self.photosM.count; i++) {
|
|||
|
|
KSPhotoItem *item = [KSPhotoItem itemWithSourceView:nil image:self.photosM[i]];
|
|||
|
|
[items addObject:item];
|
|||
|
|
}
|
|||
|
|
KSPhotoBrowser *browser = [KSPhotoBrowser browserWithPhotoItems:items selectedIndex:index];
|
|||
|
|
browser.delegate = self;
|
|||
|
|
browser.pageindicatorStyle = KSPhotoBrowserPageIndicatorStyleText;
|
|||
|
|
browser.backgroundStyle = KSPhotoBrowserBackgroundStyleBlack;
|
|||
|
|
[KSPhotoBrowser setImageViewBackgroundColor:[UIColor clearColor]];
|
|||
|
|
browser.dismissalStyle = KSPhotoBrowserInteractiveDismissalStyleScale;
|
|||
|
|
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:browser];
|
|||
|
|
self.browser = browser;
|
|||
|
|
|
|||
|
|
nav.modalPresentationStyle = UIModalPresentationOverFullScreen;
|
|||
|
|
browser.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"TH_bottle_btn_delete") style:UIBarButtonItemStyleDone target:self action:@selector(deletePhoto)];
|
|||
|
|
browser.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:ImageNamed(@"TH_bottle_alert_back_icon") style:UIBarButtonItemStyleDone target:self action:@selector(dismiss)];
|
|||
|
|
[self.navigationController presentViewController:nav animated:NO completion:nil];
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)dismiss {
|
|||
|
|
[self.browser showDismissalAnimation];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
- (void)deletePhoto {
|
|||
|
|
MTActionSheet *sheet = [[MTActionSheet alloc] initWithTitle:@"要删除这张照片吗?" delegate:nil cancelButtonTitle:@"取消" destructiveButtonTitle:@"删除" otherButtonTitles:nil];
|
|||
|
|
sheet.onClickAction = ^(MTActionSheet *sheet, NSInteger buttonIndex) {
|
|||
|
|
if (buttonIndex == 0) { // 删除
|
|||
|
|
NSUInteger index = self.browser.currentPage;
|
|||
|
|
[self.photosM removeObjectAtIndex:index];
|
|||
|
|
[self.photosCollectionView reloadData];
|
|||
|
|
[self.browser deleteImageForIndex:index];
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
[sheet show];
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
#pragma mark - KSPhotoBrowserDelegate
|
|||
|
|
- (void)ks_photoBrowser:(KSPhotoBrowser *)browser didSelectItem:(KSPhotoItem *)item atIndex:(NSUInteger)index {
|
|||
|
|
browser.pageLabel.hidden = YES;
|
|||
|
|
self.browser.title = self.browser.pageLabel.text;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
@end
|