POLanguageVC.m 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. //
  2. // POLanguageVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2023/10/9.
  6. //
  7. #import "POLanguageVC.h"
  8. #import "MOLanguageItemView.h"
  9. #import "MOAnchorRecommendVC.h"
  10. @interface POLanguageVC ()
  11. @property (weak, nonatomic) IBOutlet UIImageView *bgImgView;
  12. @property (weak, nonatomic) IBOutlet UIButton *skipBtn;///<skip按钮
  13. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *skipBtnTop;///<顶部约束
  14. @property (nonatomic, strong) NSMutableArray *languageArr;
  15. @property (nonatomic, strong) NSMutableArray *countryArr;
  16. @property (weak, nonatomic) IBOutlet MOLanguageItemView *lanView;
  17. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *lanHeight;
  18. @property (weak, nonatomic) IBOutlet MOLanguageItemView *countryView;
  19. @property (weak, nonatomic) IBOutlet NSLayoutConstraint *countryHeight;
  20. @property (weak, nonatomic) IBOutlet UIButton *finishBtn;
  21. @property (nonatomic, strong) MOCountryList *selectModel;
  22. @property (weak, nonatomic) IBOutlet UILabel *tipOneLab;
  23. @property (weak, nonatomic) IBOutlet UILabel *tipTwoLab;
  24. @property (weak, nonatomic) IBOutlet UILabel *tipBottomOneLab;
  25. @property (weak, nonatomic) IBOutlet UILabel *tipBottomTwoLab;
  26. @end
  27. @implementation POLanguageVC
  28. - (void)viewDidLoad {
  29. [super viewDidLoad];
  30. // Do any additional setup after loading the view from its nib.
  31. [self setupUI];
  32. [self prepareData];
  33. // self.lanView.titleLab.text = @"Choose a language";
  34. // self.lanView.dataArr = [self.languageArr mutableCopy];
  35. // self.lanHeight.constant = 170.0;
  36. // self.lanView.selectBlock = ^(NSString * _Nonnull chooseString) {
  37. // MOLogV(@"%@",chooseString);
  38. // };
  39. WEAKSELF
  40. self.countryView.titleLab.text = @"Select country";
  41. self.countryView.dataArr = [self.countryArr mutableCopy];
  42. self.countryHeight.constant = 400.0;
  43. self.countryView.layer.cornerRadius = 14.0;
  44. self.countryView.selectBlock = ^(MOCountryList * _Nonnull itemModel) {
  45. weakSelf.selectModel = itemModel;
  46. };
  47. [self getHttpDataAboutCountry];
  48. }
  49. - (void)setupUI{
  50. NSArray *bgImgColorArr = @[[MOTools colorWithHexString:@"#EDF1FD" alpha:1.0],[MOTools colorWithHexString:@"#FAFAFC" alpha:1.0]];
  51. UIImage *bgImage = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, SCREENWIDTH, SCREENHEIGHT) Colors:bgImgColorArr GradientType:1];
  52. [self.bgImgView setImage:bgImage];
  53. [self.skipBtn setFont:[MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr]];
  54. self.tipOneLab.font = [MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr];
  55. self.tipTwoLab.font = [MOTextTools getTheFontWithSize:36.0 AndFontName:kNormalContentFontStr];
  56. self.tipBottomOneLab.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
  57. self.tipBottomTwoLab.font = [MOTextTools getTheFontWithSize:12.0 AndFontName:kNormalContentFontStr];
  58. [self.finishBtn setFont:[MOTextTools getTheFontWithSize:20.0 AndFontName:kNormalContentFontStr]];
  59. // self.skipBtn.layer.cornerRadius = 22.0 / 2.0;
  60. // self.skipBtn.layer.masksToBounds = YES;
  61. CGFloat statusBarHeight = STATUS_BAR_HEIGHT;
  62. self.skipBtnTop.constant = statusBarHeight + 20.0;
  63. // NSArray *colorArr = @[[MOTools colorWithHexString:@"#0BDDFC" alpha:1.0],[MOTools colorWithHexString:@"#0BDDFC" alpha:1.0]];
  64. // UIImage *image = [MOTools createGradientRectImageWithBounds:CGRectMake(0, 0, (SCREENWIDTH - 45.0 * 2), 44.0) Colors:colorArr GradientType:0];
  65. // [self.finishBtn setBackgroundImage:image forState:UIControlStateNormal];
  66. // self.finishBtn.layer.cornerRadius = 44.0 / 2.0;
  67. // self.finishBtn.layer.masksToBounds = YES;
  68. self.finishBtn.semanticContentAttribute = UISemanticContentAttributeForceRightToLeft;
  69. self.finishBtn.imageEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
  70. }
  71. //获取国家列表
  72. - (void)getHttpDataAboutCountry{
  73. WEAKSELF
  74. [kHttpManager getCountryAndRegionListWithParams:nil andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  75. __strong typeof(weakSelf) self = weakSelf;
  76. if(kCode_Success){
  77. MOLogV(@"%@",[[NSString alloc] initWithData:[NSJSONSerialization dataWithJSONObject:data options:0 error:nil] encoding:NSUTF8StringEncoding]);
  78. MOCountryBaseData *countryBase = [MOCountryBaseData modelObjectWithDictionary:data[@"data"]];
  79. if(countryBase.countryList.count > 0){
  80. MOCountryList *firstObject = countryBase.countryList.firstObject;
  81. firstObject.isChoose = YES;
  82. self.selectModel = firstObject;
  83. }
  84. self.countryArr = [countryBase.countryList mutableCopy];
  85. self.countryView.dataArr = [self.countryArr mutableCopy];
  86. [self updataUIWithProperty];
  87. }
  88. else
  89. {
  90. kShowNetError(data)
  91. }
  92. }];
  93. }
  94. - (void)updataUIWithProperty{
  95. CGFloat height = 170.0;
  96. if(self.countryArr.count > 0){
  97. height = ceil(self.countryArr.count / 2.0) * (54.0 + 12.0) + 80.0;
  98. }
  99. self.countryHeight.constant = height;
  100. }
  101. ///跳过按钮
  102. - (IBAction)skipBtnClick:(id)sender {
  103. MOMainTabController *mainTabbar = [MOMainTabController sharedSingleton];
  104. [mainTabbar toResetSetupTabbar];
  105. [UIApplication sharedApplication].keyWindow.rootViewController = mainTabbar;
  106. }
  107. ///完成按钮
  108. - (IBAction)finishBtnClick:(id)sender {
  109. [self setUserInfoAboutCountyWith:self.selectModel];
  110. }
  111. - (void)setUserInfoAboutCountyWith:(MOCountryList *)model{
  112. WEAKSELF
  113. if(model.code.length == 0){
  114. return;
  115. }
  116. NSString *countryStr = model.code;
  117. NSDictionary *dict = @{@"country":countryStr};
  118. [kHttpManager toSettingInfoWithParams:dict andBlock:^(id _Nonnull data, NSError * _Nonnull error) {
  119. if(kCode_Success){
  120. MOAnchorRecommendVC *vc = [[MOAnchorRecommendVC alloc] init];
  121. [weakSelf.navigationController pushViewController:vc animated:YES];
  122. }
  123. else{
  124. kShowNetError(data)
  125. }
  126. }];
  127. }
  128. - (NSMutableArray *)languageArr
  129. {
  130. if(_languageArr == nil)
  131. {
  132. _languageArr = [NSMutableArray array];
  133. }
  134. return _languageArr;
  135. }
  136. - (NSMutableArray *)countryArr
  137. {
  138. if(_countryArr == nil)
  139. {
  140. _countryArr = [NSMutableArray array];
  141. }
  142. return _countryArr;
  143. }
  144. - (void)prepareData
  145. {
  146. //准备语言数据
  147. // NSArray *lanTemArr = @[@"中文",@"English",@"Indonesia",@"Filipino",@"Malaysian"];
  148. // self.languageArr = [self constructDataWith:lanTemArr];
  149. //
  150. // //准备城市数据
  151. // NSArray *countryArr = @[@"Pilipinas",@"Malaysia",@"Việt Nam",@"Indonesia"];
  152. // self.countryArr = [self constructDataWith:countryArr];
  153. }
  154. - (NSMutableArray *)constructDataWith:(NSArray *)dataArr{
  155. NSMutableArray *tempArr = [NSMutableArray array];
  156. for (NSString * titleString in dataArr) {
  157. MOLanItemModel *model = [[MOLanItemModel alloc] init];
  158. model.title = titleString;
  159. model.choose = NO;
  160. [tempArr addObject:model];
  161. }
  162. return tempArr;
  163. }
  164. @end