HaveNewVersionView.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  1. //
  2. // HaveNewVersionView.m
  3. // VclustersGemini
  4. //
  5. // Created by APPLE on 2020/2/24.
  6. // Copyright © 2020 APPLE. All rights reserved.
  7. //
  8. #import "HaveNewVersionView.h"
  9. @interface HaveNewVersionView ()<UITableViewDelegate,UITableViewDataSource>
  10. @property (nonatomic,strong) NSMutableArray *dataSource;
  11. @end
  12. @implementation HaveNewVersionView
  13. @synthesize titleLabel;
  14. @synthesize detailLabel;
  15. @synthesize bgView;
  16. @synthesize deleteBtn;
  17. static HaveNewVersionView * _instance;
  18. + (instancetype)shardInstance {
  19. static dispatch_once_t HaveNewVersionViewonceToken;
  20. dispatch_once(&HaveNewVersionViewonceToken, ^{
  21. _instance = [[self alloc] init];
  22. });
  23. return _instance;
  24. }
  25. - (id)initWithFrame:(CGRect)frame
  26. {
  27. self = [super initWithFrame:frame];
  28. if (self)
  29. {
  30. [self drawAnyView];
  31. }
  32. return self;
  33. }
  34. - (void)drawAnyView
  35. {
  36. self.tag = 111111;
  37. [self setBackgroundColor:[UIColor clearColor]];
  38. bgView = [[UIView alloc] init];
  39. [bgView setBackgroundColor:HWF5F7FAColor];
  40. [bgView.layer setCornerRadius:20.f];
  41. [self addSubview:bgView];
  42. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  43. make.height.mas_equalTo(320.f);
  44. make.width.mas_equalTo(260.f);
  45. make.centerX.equalTo(self.mas_centerX);
  46. make.centerY.equalTo(self.mas_centerY);
  47. }];
  48. // 图片
  49. UIImageView *topImageView = [[UIImageView alloc] init];
  50. topImageView.image = [UIImage imageNamed:@"gengxinbeijing_pic"];
  51. topImageView.contentMode = UIViewContentModeScaleAspectFit;
  52. [bgView addSubview:topImageView];
  53. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_equalTo(bgView.mas_top);
  55. make.left.mas_equalTo(bgView.mas_left);
  56. make.right.mas_equalTo(bgView.mas_right);
  57. make.height.mas_equalTo(134);
  58. }];
  59. /*删除按钮*/
  60. deleteBtn = [[UIButton alloc] init];
  61. [deleteBtn setBackgroundColor:[UIColor clearColor]];
  62. [deleteBtn setImage:[UIImage imageNamed:@"guanbi_bai_icon"] forState:(UIControlStateNormal)];
  63. [deleteBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  64. [bgView addSubview:deleteBtn];
  65. [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  66. make.height.mas_equalTo(45.f);
  67. make.width.mas_equalTo(45.f);
  68. make.right.mas_equalTo(bgView.mas_right).mas_offset(0);
  69. make.top.mas_equalTo(bgView.mas_top).mas_offset(0);
  70. }];
  71. // deleteBtn.hidden = YES;
  72. // 分割线
  73. UIView *line = [[UIView alloc] init];
  74. line.backgroundColor = HW666666Color;
  75. [bgView addSubview:line];
  76. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.left.mas_equalTo(0);
  78. make.right.mas_equalTo(0);
  79. make.height.mas_equalTo(1);
  80. make.bottom.mas_equalTo(-70);
  81. }];
  82. /*确定按钮*/
  83. UIButton *okBtn = [[UIButton alloc] init];
  84. [okBtn setBackgroundImage:[UIImage imageNamed:@"login_select_corner"] forState:(UIControlStateNormal)];
  85. [okBtn setTitle:@"下载更新" forState:(UIControlStateNormal)];
  86. [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  87. [okBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  88. [okBtn.layer setCornerRadius:20.f];
  89. okBtn.layer.masksToBounds = YES;
  90. [bgView addSubview:okBtn];
  91. [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.height.mas_equalTo(40.f);
  93. make.width.mas_equalTo(168.f);
  94. make.centerX.equalTo(bgView.mas_centerX);
  95. make.bottom.mas_equalTo(-20.f);
  96. }];
  97. UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) style:(UITableViewStylePlain)];
  98. tableView.delegate = self;
  99. tableView.dataSource = self;
  100. [tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  101. [tableView setSeparatorColor:[UIColor clearColor]];
  102. [tableView setBackgroundColor:[UIColor clearColor]];
  103. if (@available(iOS 15.0, *)) {
  104. tableView.sectionHeaderTopPadding = 0;
  105. }
  106. [bgView addSubview:tableView];
  107. [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  108. make.left.mas_equalTo(0);
  109. make.right.mas_equalTo(0);
  110. make.top.mas_equalTo(topImageView.mas_bottom);
  111. make.bottom.mas_equalTo(line.mas_top);
  112. }];
  113. }
  114. - (void)deleteBtnPressed
  115. {
  116. [self removeFromSuperview];
  117. self.isShow = NO;
  118. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  119. [_delegate closeBtnBePressed];
  120. }
  121. }
  122. - (void)updateBtnPressed {
  123. if (!self.versionModel.necessary) { // 非强制更新
  124. self.isShow = NO;
  125. [self removeFromSuperview];
  126. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  127. [_delegate closeBtnBePressed];
  128. }
  129. }
  130. // NSString *fileKey = FileAPPManifestKey;
  131. // NSString *appID = [[NSBundle mainBundle] bundleIdentifier];
  132. // if ([appID containsString:@"com.kxly.cloudgame"]){
  133. // fileKey = @"LowLevelMultipartUpload_25944032109132595200";
  134. // }
  135. //
  136. // NSURL * url = [NSURL URLWithString:[NSString stringWithFormat:@"itms-services://?action=download-manifest&url=https://file.phone.androidscloud.com:8121/document/newFile/download/1/%@/%@/manifest.plist",Const_File_Access_Key,fileKey]];
  137. //
  138. //// HLog(@"立即更新-跳转到:%@",self.versionModel.downUrl);
  139. //// NSString *url = [self.versionModel.downUrl stringByReplacingOccurrencesOfString:@" " withString:@""]; // 防止url里有空格字符导致无法跳转
  140. // [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  141. // ;
  142. // }];
  143. }
  144. #pragma mark - 列表委托
  145. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  146. return 1;
  147. }
  148. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  149. return self.dataSource.count;
  150. }
  151. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  152. static NSString *identifier = @"newVersionInfoCellidentifier";
  153. NSInteger row = indexPath.row;
  154. NSString *tipsString = self.dataSource[row];
  155. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  156. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  157. UITableViewCell *payTypecell = [tableView dequeueReusableCellWithIdentifier:identifier];
  158. payTypecell.selectionStyle = UITableViewCellSelectionStyleNone;
  159. if (!cell)
  160. {
  161. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  162. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  163. [cell setBackgroundColor:[UIColor clearColor]];
  164. /*文字*/
  165. [cell.textLabel setFont:[UIFont systemFontOfSize:14.f]];
  166. [cell.textLabel setTextColor:HWCFD1D4Color];
  167. cell.textLabel.numberOfLines = 0;
  168. [cell.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  169. make.left.mas_equalTo(15);
  170. make.right.mas_equalTo(-15);
  171. make.top.mas_equalTo(5);
  172. make.bottom.mas_equalTo(5);
  173. }];
  174. }
  175. cell.textLabel.text = [NSString stringWithFormat:@"·%@",tipsString];
  176. return cell;
  177. }
  178. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  179. return UITableViewAutomaticDimension;
  180. }
  181. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  182. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 37)];
  183. bgView.backgroundColor = HWF5F7FAColor;
  184. UILabel *label1 = [[UILabel alloc] init];
  185. label1.text = [NSString stringWithFormat:@"发现新版本(%@)", self.versionModel.versionNumber];
  186. label1.textColor = HWCFD1D4Color;
  187. label1.font = [UIFont boldSystemFontOfSize:14.f];
  188. [bgView addSubview:label1];
  189. [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
  190. make.left.mas_equalTo(15);
  191. make.top.mas_equalTo(10);
  192. }];
  193. UILabel *label2 = [[UILabel alloc] init];
  194. label2.text = [NSString stringWithFormat:@"大小:%@MB", self.versionModel.fileSize];
  195. label2.textColor = HWF5F7FAColor;
  196. label2.font = [UIFont systemFontOfSize:10.f];
  197. [bgView addSubview:label2];
  198. [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
  199. make.left.mas_equalTo(label1.mas_right).mas_offset(5);
  200. make.centerY.mas_equalTo(label1.mas_centerY);
  201. }];
  202. return bgView;
  203. }
  204. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  205. return 35;
  206. }
  207. - (NSMutableArray *)dataSource {
  208. if (!_dataSource) {
  209. NSArray *tips = [self.versionModel.versionInfo componentsSeparatedByString:@"&&"];
  210. _dataSource = [NSMutableArray arrayWithArray:tips];
  211. }
  212. return _dataSource;
  213. }
  214. @end