|
|
@@ -1,13 +1,28 @@
|
|
|
//
|
|
|
-// MOCountryAndRecommendVC.m
|
|
|
+// MOCountryAndRecommendVC.h
|
|
|
// MiMoLive
|
|
|
//
|
|
|
// Created by SuperC on 2025/3/10.
|
|
|
//
|
|
|
|
|
|
#import "MOCountryAndRecommendVC.h"
|
|
|
+#import "MOLanguageItemView.h"
|
|
|
+#import "MORecommendFlowLayout.h"
|
|
|
+#import "MORecommendAnchorCell.h"
|
|
|
|
|
|
-@interface MOCountryAndRecommendVC ()
|
|
|
+@interface MOCountryAndRecommendVC ()<UICollectionViewDelegate, UICollectionViewDataSource>
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIImageView *bgImgView;
|
|
|
+@property (nonatomic, strong) UIImageView *topImgView;
|
|
|
+@property (nonatomic, strong) UIScrollView *scrollView;
|
|
|
+@property (nonatomic, strong) UIView *scrollContainerView;
|
|
|
+@property (nonatomic, strong) MOLanguageItemView *countryView;
|
|
|
+@property (nonatomic, strong) NSMutableArray *countryArr;
|
|
|
+@property (nonatomic, strong) MOCountryList *selectModel;
|
|
|
+@property (nonatomic, strong) UILabel *recommendTitle;
|
|
|
+@property (nonatomic, strong) UICollectionView *collectionView;
|
|
|
+@property (nonatomic, strong) NSMutableArray *dataArr;
|
|
|
+@property (nonatomic, strong) UIButton *finishBtn;
|
|
|
|
|
|
@end
|
|
|
|
|
|
@@ -15,17 +30,337 @@
|
|
|
|
|
|
- (void)viewDidLoad {
|
|
|
[super viewDidLoad];
|
|
|
- // Do any additional setup after loading the view from its nib.
|
|
|
+
|
|
|
+ [self setupUI];
|
|
|
+ [self getHttpDataAboutCountry];
|
|
|
+ [self getAnchorRecommendListData];
|
|
|
+}
|
|
|
+
|
|
|
+/// 推荐主播
|
|
|
+- (void)getAnchorRecommendListData{
|
|
|
+ WEAKSELF
|
|
|
+ [kHttpManager getAnchorRecommendListWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
|
|
|
+ if(kCode_Success){
|
|
|
+
|
|
|
+ NSLog(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
|
|
|
+ MOUserRecomList *baseModle = [MOUserRecomList modelObjectWithDictionary:data[@"data"]];
|
|
|
+
|
|
|
+ for (MOUserProfile *object in baseModle.userBase) {
|
|
|
+ object.isSelect = YES;
|
|
|
+ }
|
|
|
+
|
|
|
+ weakSelf.dataArr = [baseModle.userBase mutableCopy];
|
|
|
+ [weakSelf.collectionView reloadData];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ kShowNetError(data)
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+//获取国家列表
|
|
|
+- (void)getHttpDataAboutCountry{
|
|
|
+ WEAKSELF
|
|
|
+ [kHttpManager getCountryAndRegionListWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
|
|
|
+ __strong typeof(weakSelf) self = weakSelf;
|
|
|
+
|
|
|
+ if(kCode_Success){
|
|
|
+ NSLog(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
|
|
|
+
|
|
|
+ MOCountryBaseData *countryBase = [MOCountryBaseData modelObjectWithDictionary:data[@"data"]];
|
|
|
+
|
|
|
+ if(countryBase.countryList.count > 0){
|
|
|
+ MOCountryList *firstObject = countryBase.countryList.firstObject;
|
|
|
+ firstObject.isChoose = YES;
|
|
|
+
|
|
|
+ self.selectModel = firstObject;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ self.countryArr = [countryBase.countryList mutableCopy];
|
|
|
+
|
|
|
+ self.countryView.dataArr = [self.countryArr mutableCopy];
|
|
|
+
|
|
|
+ [self updataUIWithProperty];
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ kShowNetError(data)
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)updataUIWithProperty{
|
|
|
+ CGFloat height = 155.0;
|
|
|
+ if(self.countryArr.count > 0){
|
|
|
+ height = ceil(self.countryArr.count / 2.0) * 50 + 55.0;
|
|
|
+ }
|
|
|
+ [self.countryView mas_updateConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.height.mas_equalTo(height);
|
|
|
+ }];
|
|
|
}
|
|
|
|
|
|
-/*
|
|
|
-#pragma mark - Navigation
|
|
|
|
|
|
-// In a storyboard-based application, you will often want to do a little preparation before navigation
|
|
|
-- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
|
|
- // Get the new view controller using [segue destinationViewController].
|
|
|
- // Pass the selected object to the new view controller.
|
|
|
+- (void)setupUI{
|
|
|
+ [self.view addSubview:self.bgImgView];
|
|
|
+ [self.bgImgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.edges.mas_equalTo(0);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.view addSubview:self.topImgView];
|
|
|
+ [self.topImgView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.left.right.mas_equalTo(0);
|
|
|
+ make.height.mas_equalTo(kScaleWidth(285));
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.view addSubview:self.scrollView];
|
|
|
+ [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.mas_equalTo(STATUS_BAR_HEIGHT + 17);
|
|
|
+ make.left.right.mas_equalTo(0);
|
|
|
+ make.bottom.mas_equalTo(HOME_KEY_HEIGHT - 74);
|
|
|
+ make.width.mas_equalTo(SCREENWIDTH);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.scrollView addSubview:self.scrollContainerView];
|
|
|
+ [self.scrollContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.edges.equalTo(self.scrollView);
|
|
|
+ make.width.equalTo(self.scrollView);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.scrollContainerView addSubview:self.countryView];
|
|
|
+ [self.countryView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.mas_equalTo(0);
|
|
|
+ make.left.right.mas_equalTo(0);
|
|
|
+ make.height.mas_equalTo(155);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.scrollContainerView addSubview:self.recommendTitle];
|
|
|
+ [self.recommendTitle mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(self.countryView.mas_bottom).offset(41);
|
|
|
+ make.left.mas_equalTo(26);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.scrollContainerView addSubview:self.collectionView];
|
|
|
+ [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.top.equalTo(self.recommendTitle.mas_bottom).offset(18);
|
|
|
+ make.left.mas_equalTo(24);
|
|
|
+ make.right.mas_equalTo(-24);
|
|
|
+ make.height.mas_equalTo(555);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.scrollContainerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.bottom.equalTo(self.collectionView).offset(20);
|
|
|
+ }];
|
|
|
+
|
|
|
+ [self.view addSubview:self.finishBtn];
|
|
|
+ CGFloat bottomOffset = KIsiPhoneX ? 20 : 0;
|
|
|
+ [self.finishBtn mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
|
+ make.left.mas_equalTo(20);
|
|
|
+ make.right.mas_equalTo(-20);
|
|
|
+ make.height.mas_equalTo(80);
|
|
|
+ make.bottom.mas_equalTo(-bottomOffset);
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)finishBtnAction {
|
|
|
+ [self followTheRecommand];
|
|
|
}
|
|
|
-*/
|
|
|
+
|
|
|
+- (void)followTheRecommand{
|
|
|
+ NSMutableArray *arr = [NSMutableArray array];
|
|
|
+
|
|
|
+ for (MOUserProfile *object in self.dataArr) {
|
|
|
+ if(object.isSelect){
|
|
|
+ [arr addObject:object.id];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(arr.count == 0){
|
|
|
+ [self setUserInfoAboutCountyWith:self.selectModel];
|
|
|
+ } else{
|
|
|
+ NSDictionary *dict = @{@"type":@"1",
|
|
|
+ @"target":arr};
|
|
|
+
|
|
|
+ WEAKSELF
|
|
|
+ [kHttpManager toSubmitForFollowWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
|
|
|
+ if(kCode_Success){
|
|
|
+// [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
|
|
|
+ [weakSelf setUserInfoAboutCountyWith:weakSelf.selectModel];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ kShowNetError(data)
|
|
|
+ }
|
|
|
+ }];
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setUserInfoAboutCountyWith:(MOCountryList *)model{
|
|
|
+
|
|
|
+ WEAKSELF
|
|
|
+ if(model.code.length == 0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ NSString *countryStr = model.code;
|
|
|
+
|
|
|
+ NSDictionary *dict = @{@"country":countryStr};
|
|
|
+
|
|
|
+ [kHttpManager toSettingInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
|
|
|
+ if(kCode_Success){
|
|
|
+ [MBProgressHUD showTipMessageInWindow:NSLocalString(@"mimo_common_success")];
|
|
|
+ [weakSelf performSelector:@selector(toMainVC) withObject:nil afterDelay:1.0];
|
|
|
+ }
|
|
|
+ else{
|
|
|
+ kShowNetError(data)
|
|
|
+ }
|
|
|
+ }];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)toMainVC {
|
|
|
+ SendNotification(@"kNotification_MOCountryAndRecommendVCDismiss")//选择语言和推荐主播页面退出通知
|
|
|
+ if (self.navigationController.presentingViewController) {//如果是present出来的要dismiss
|
|
|
+ [self.navigationController dismissViewControllerAnimated:YES completion:nil];
|
|
|
+ }
|
|
|
+
|
|
|
+ MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
|
|
|
+ [mainTabbar toResetSetupTabbar];
|
|
|
+ [UIApplication sharedApplication].keyWindow.rootViewController = mainTabbar;
|
|
|
+}
|
|
|
+
|
|
|
+#pragma mark --UICollectionViewDatasource & delegate
|
|
|
+- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView{
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
|
|
|
+ return self.dataArr.count;
|
|
|
+}
|
|
|
+
|
|
|
+-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
|
|
|
+
|
|
|
+ MOUserProfile *model = self.dataArr[indexPath.row];
|
|
|
+ MORecommendAnchorCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:MORecommendAnchorCell_ID forIndexPath:indexPath];
|
|
|
+
|
|
|
+ cell.cellModel = model;
|
|
|
+ WEAKSELF
|
|
|
+ cell.itemClickBlock = ^(MOUserProfile * _Nonnull cellModel) {
|
|
|
+
|
|
|
+ for (MOUserProfile *object in weakSelf.dataArr) {
|
|
|
+ if([cellModel.id isEqualToString:object.id]){
|
|
|
+ object.isSelect = !object.isSelect;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ [weakSelf.collectionView reloadData];
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
+ return cell;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (UIImageView *)bgImgView {
|
|
|
+ if (!_bgImgView) {
|
|
|
+ _bgImgView = [[UIImageView alloc] init];
|
|
|
+ NSArray *bgImgColorArr = @[[MOTools colorWithHexString:@"#EDF1FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
|
|
|
+ UIImage *bgImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT) Colors:bgImgColorArr GradientType:1];
|
|
|
+ _bgImgView.image = bgImage;
|
|
|
+ }
|
|
|
+ return _bgImgView;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIImageView *)topImgView {
|
|
|
+ if (!_topImgView) {
|
|
|
+ _topImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"icon_welcome_top_bg"]];
|
|
|
+ }
|
|
|
+ return _topImgView;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIScrollView *)scrollView {
|
|
|
+ if (!_scrollView) {
|
|
|
+ _scrollView = [[UIScrollView alloc] init];
|
|
|
+ _scrollView.backgroundColor = [UIColor clearColor];
|
|
|
+ _scrollView.alwaysBounceVertical = YES;
|
|
|
+ _scrollView.bounces = YES;
|
|
|
+ }
|
|
|
+ return _scrollView;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIView *)scrollContainerView {
|
|
|
+ if (!_scrollContainerView) {
|
|
|
+ _scrollContainerView = [[UIView alloc] init];
|
|
|
+ _scrollContainerView.backgroundColor = [UIColor clearColor];
|
|
|
+ }
|
|
|
+ return _scrollContainerView;
|
|
|
+}
|
|
|
+
|
|
|
+- (MOLanguageItemView *)countryView {
|
|
|
+ if (!_countryView) {
|
|
|
+ _countryView = [[MOLanguageItemView alloc] init];
|
|
|
+ _countryView.titleLab.text = @"Select country";
|
|
|
+ WEAKSELF
|
|
|
+ _countryView.selectBlock = ^(MOCountryList * _Nonnull itemModel) {
|
|
|
+ weakSelf.selectModel = itemModel;
|
|
|
+ };
|
|
|
+ }
|
|
|
+ return _countryView;
|
|
|
+}
|
|
|
+
|
|
|
+- (UILabel *)recommendTitle {
|
|
|
+ if (!_recommendTitle) {
|
|
|
+ _recommendTitle = [[UILabel alloc] init];
|
|
|
+ _recommendTitle.text = @"Anchor Recommend";
|
|
|
+ _recommendTitle.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:@"Akrobat"];
|
|
|
+ _recommendTitle.textColor = [MOTools colorWithHexString:@"#282828" alpha:1.0];
|
|
|
+ _recommendTitle.textAlignment = NSTextAlignmentLeft;
|
|
|
+ _recommendTitle.numberOfLines = 0;
|
|
|
+ }
|
|
|
+ return _recommendTitle;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+- (UICollectionView *)collectionView {
|
|
|
+ if (!_collectionView) {
|
|
|
+ MORecommendFlowLayout *flow = [[MORecommendFlowLayout alloc] init];
|
|
|
+ flow.itemSize = CGSizeMake(90.0, 120.0);
|
|
|
+ flow.minimumLineSpacing = 10.0;//行间距
|
|
|
+ flow.minimumInteritemSpacing = 10.0;//列间距
|
|
|
+ _collectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, 400) collectionViewLayout:flow];
|
|
|
+ [_collectionView registerNib:[UINib nibWithNibName:@"MORecommendAnchorCell" bundle:nil] forCellWithReuseIdentifier:@"MORecommendAnchorCell_ID"];
|
|
|
+ _collectionView.contentInset = UIEdgeInsetsMake(18, 0, 20, 0);
|
|
|
+ _collectionView.scrollEnabled = NO;
|
|
|
+
|
|
|
+ _collectionView.layer.masksToBounds = YES;
|
|
|
+ _collectionView.layer.cornerRadius = 13;
|
|
|
+ _collectionView.dataSource = self;
|
|
|
+ _collectionView.delegate = self;
|
|
|
+ }
|
|
|
+ return _collectionView;
|
|
|
+}
|
|
|
+
|
|
|
+- (NSMutableArray *)dataArr{
|
|
|
+ if(!_dataArr){
|
|
|
+ _dataArr = [NSMutableArray array];
|
|
|
+ }
|
|
|
+
|
|
|
+ return _dataArr;
|
|
|
+}
|
|
|
+
|
|
|
+- (UIButton *)finishBtn {
|
|
|
+ if (!_finishBtn) {
|
|
|
+ _finishBtn = [[UIButton alloc] init];
|
|
|
+ [_finishBtn setImage:[UIImage imageNamed:@"icon_next_step"] forState:UIControlStateNormal];
|
|
|
+ [_finishBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:@"Akrobat"]];
|
|
|
+ [_finishBtn setTitle:@"Finish" forState:UIControlStateNormal];
|
|
|
+ [_finishBtn setTitleColor:[MOTools colorWithHexString:@"#000000"] forState:UIControlStateNormal];
|
|
|
+ _finishBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
|
|
|
+ _finishBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
|
|
|
+ [_finishBtn addTarget:self action:@selector(finishBtnAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [_finishBtn setBackgroundImage:[UIImage imageNamed:@"icon_next_step_btn_bg_apple"] forState:UIControlStateNormal];
|
|
|
+ }
|
|
|
+ return _finishBtn;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
@end
|