HaveNewVersionView.m 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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)setVersionModel:(HWVersionModel *)versionModel
  35. {
  36. _versionModel = versionModel;
  37. [self drawAnyView];
  38. }
  39. - (void)drawAnyView
  40. {
  41. if(bgView){
  42. [bgView removeFromSuperview];
  43. }
  44. self.tag = 111111;
  45. [self setBackgroundColor:HW000000Color60];
  46. NSString *tipStr = _versionModel.versionInfo;
  47. CGFloat curHeight = [tipStr boundingRectWithSize:CGSizeMake(300 -40, 1000) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.0]} context:nil].size.height;
  48. curHeight += 10;
  49. if( (curHeight + 280) >= SCREEN_H){
  50. curHeight = SCREEN_H - 280 - 10;
  51. }
  52. bgView = [[UIView alloc] init];
  53. [bgView setBackgroundColor:[UIColor whiteColor]];
  54. [bgView.layer setCornerRadius:8.f];
  55. [self addSubview:bgView];
  56. [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  57. make.height.mas_equalTo(280.f + curHeight);
  58. make.width.mas_equalTo(300.f);
  59. make.centerX.equalTo(self.mas_centerX);
  60. make.centerY.equalTo(self.mas_centerY);
  61. }];
  62. // 图片
  63. UIImageView *topImageView = [[UIImageView alloc] init];
  64. topImageView.image = [UIImage imageNamed:@"gengxinbeijing_pic"];
  65. topImageView.contentMode = UIViewContentModeScaleAspectFit;
  66. [bgView addSubview:topImageView];
  67. [topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  68. make.top.mas_equalTo(bgView.mas_top);
  69. make.left.mas_equalTo(bgView.mas_left);
  70. make.right.mas_equalTo(bgView.mas_right);
  71. make.height.mas_equalTo(141);
  72. }];
  73. /*提示文字*/
  74. UILabel *tipsLabel = [[UILabel alloc] init];
  75. //[tipsLabel setText:NSLocalizedString(@"app_update_new_version_tips",nil)];
  76. [tipsLabel setText:tipStr];
  77. [tipsLabel setTextColor:HW0A132BColor];
  78. [tipsLabel setFont:[UIFont systemFontOfSize:13.f]];
  79. //[tipsLabel setTextAlignment:(NSTextAlignmentCenter)];
  80. [tipsLabel setNumberOfLines:0];
  81. [bgView addSubview:tipsLabel];
  82. [tipsLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.top.equalTo(topImageView.mas_bottom).offset(20.f);
  84. make.left.mas_equalTo(20);
  85. make.right.mas_equalTo(-20);
  86. make.height.mas_equalTo(curHeight);
  87. }];
  88. /*删除按钮*/
  89. deleteBtn = [[UIButton alloc] init];
  90. [deleteBtn setBackgroundColor:[UIColor clearColor]];
  91. //[deleteBtn setImage:[UIImage imageNamed:@"guanbi_bai_icon"] forState:(UIControlStateNormal)];
  92. [deleteBtn setImage:[UIImage imageNamed:@"common_del"] forState:(UIControlStateNormal)];
  93. [deleteBtn addTarget:self action:@selector(deleteBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  94. [bgView addSubview:deleteBtn];
  95. [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.height.mas_equalTo(45.f);
  97. make.width.mas_equalTo(45.f);
  98. make.right.mas_equalTo(bgView.mas_right).mas_offset(0);
  99. make.top.mas_equalTo(bgView.mas_top).mas_offset(0);
  100. }];
  101. deleteBtn.hidden = YES;
  102. // 分割线
  103. UIView *line = [[UIView alloc] init];
  104. line.backgroundColor = HWCCCCCCColor;
  105. [bgView addSubview:line];
  106. [line mas_makeConstraints:^(MASConstraintMaker *make) {
  107. make.left.mas_equalTo(0);
  108. make.right.mas_equalTo(0);
  109. make.height.mas_equalTo(1);
  110. make.bottom.mas_equalTo(-92);
  111. }];
  112. // /*确定按钮*/
  113. // UIButton *okBtn = [[UIButton alloc] init];
  114. // [okBtn setBackgroundImage:[UIImage imageNamed:@"login_select_corner"] forState:(UIControlStateNormal)];
  115. // [okBtn setTitle:@"更新" forState:(UIControlStateNormal)];
  116. // [okBtn.titleLabel setFont:[UIFont systemFontOfSize:14.f]];
  117. // [okBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  118. // [okBtn.layer setCornerRadius:20.f];
  119. // okBtn.layer.masksToBounds = YES;
  120. // [bgView addSubview:okBtn];
  121. //
  122. // [okBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  123. // make.height.mas_equalTo(40.f);
  124. // make.width.mas_equalTo(168.f);
  125. // make.centerX.equalTo(bgView.mas_centerX);
  126. // make.bottom.mas_equalTo(-20.f);
  127. // }];
  128. UIButton *updatekBtn = [[UIButton alloc] init];
  129. updatekBtn.frame = CGRectMake(0, 0, 160.f, 48.f);
  130. // gradient
  131. CAGradientLayer *gl = [CAGradientLayer layer];
  132. gl.frame = CGRectMake(0,0,160.f,48.f);
  133. gl.startPoint = CGPointMake(0, 0.5);
  134. gl.endPoint = CGPointMake(1, 0.5);
  135. gl.colors = @[(__bridge id)HW0CDEFDColor.CGColor, (__bridge id)HW058DFBColor.CGColor];
  136. gl.locations = @[@(0), @(1.0f)];
  137. [updatekBtn.layer addSublayer:gl];
  138. [updatekBtn addTarget:self action:@selector(updateBtnPressed) forControlEvents:(UIControlEventTouchUpInside)];
  139. [updatekBtn setTitle:NSLocalizedString(@"app_update_update",nil) forState:(UIControlStateNormal)];
  140. [updatekBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  141. [updatekBtn.titleLabel setFont:[UIFont systemFontOfSize:16.f]];
  142. [updatekBtn.layer setCornerRadius:8.f];
  143. updatekBtn.clipsToBounds = YES;
  144. [bgView addSubview:updatekBtn];
  145. [updatekBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  146. make.centerX.equalTo(bgView.mas_centerX);
  147. make.width.mas_equalTo(160.f);
  148. make.bottom.mas_equalTo(-20.f);
  149. make.height.mas_equalTo(48.f);
  150. }];
  151. // UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 1, 1) style:(UITableViewStylePlain)];
  152. // tableView.delegate = self;
  153. // tableView.dataSource = self;
  154. // [tableView setSeparatorStyle:(UITableViewCellSeparatorStyleNone)];
  155. // [tableView setSeparatorColor:[UIColor clearColor]];
  156. // [tableView setBackgroundColor:[UIColor clearColor]];
  157. // if (@available(iOS 15.0, *)) {
  158. // tableView.sectionHeaderTopPadding = 0;
  159. // }
  160. // [bgView addSubview:tableView];
  161. // [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
  162. // make.left.mas_equalTo(0);
  163. // make.right.mas_equalTo(0);
  164. // make.top.mas_equalTo(topImageView.mas_bottom);
  165. // make.bottom.mas_equalTo(line.mas_top);
  166. // }];
  167. }
  168. - (void)deleteBtnPressed
  169. {
  170. [self removeFromSuperview];
  171. self.isShow = NO;
  172. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  173. [_delegate closeBtnBePressed];
  174. }
  175. if(_closeViewFun){
  176. _closeViewFun();
  177. }
  178. }
  179. - (void)updateBtnPressed {
  180. if (!self.versionModel.necessary) { // 非强制更新
  181. self.isShow = NO;
  182. [self removeFromSuperview];
  183. if ([_delegate respondsToSelector:@selector(closeBtnBePressed)]) {
  184. [_delegate closeBtnBePressed];
  185. }
  186. }
  187. /*跳转蒲公英*/
  188. NSURL * url = [NSURL URLWithString:self.versionModel.downUrl];
  189. HLog(@"立即更新-跳转到:%@",self.versionModel.downUrl);
  190. // NSString *url = [self.versionModel.downUrl stringByReplacingOccurrencesOfString:@" " withString:@""]; // 防止url里有空格字符导致无法跳转
  191. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {
  192. ;
  193. }];
  194. }
  195. #pragma mark - 列表委托
  196. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
  197. return 1;
  198. }
  199. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  200. return self.dataSource.count;
  201. }
  202. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  203. static NSString *identifier = @"newVersionInfoCellidentifier";
  204. NSInteger row = indexPath.row;
  205. NSString *tipsString = self.dataSource[row];
  206. UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
  207. cell.selectionStyle = UITableViewCellSelectionStyleNone;
  208. UITableViewCell *payTypecell = [tableView dequeueReusableCellWithIdentifier:identifier];
  209. payTypecell.selectionStyle = UITableViewCellSelectionStyleNone;
  210. if (!cell)
  211. {
  212. cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:identifier];
  213. [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
  214. [cell setBackgroundColor:[UIColor clearColor]];
  215. /*文字*/
  216. [cell.textLabel setFont:[UIFont systemFontOfSize:14.f]];
  217. [cell.textLabel setTextColor:HWCFD1D4Color];
  218. cell.textLabel.numberOfLines = 0;
  219. [cell.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  220. make.left.mas_equalTo(15);
  221. make.right.mas_equalTo(-15);
  222. make.top.mas_equalTo(5);
  223. make.bottom.mas_equalTo(5);
  224. }];
  225. }
  226. cell.textLabel.text = [NSString stringWithFormat:@"·%@",tipsString];
  227. return cell;
  228. }
  229. - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  230. return UITableViewAutomaticDimension;
  231. }
  232. - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
  233. UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_W, 37)];
  234. bgView.backgroundColor = HWF5F7FAColor;
  235. UILabel *label1 = [[UILabel alloc] init];
  236. label1.text = [NSString stringWithFormat:@"发现新版本(%@)", self.versionModel.versionNumber];
  237. label1.textColor = HWCFD1D4Color;
  238. label1.font = [UIFont boldSystemFontOfSize:14.f];
  239. [bgView addSubview:label1];
  240. [label1 mas_makeConstraints:^(MASConstraintMaker *make) {
  241. make.left.mas_equalTo(15);
  242. make.top.mas_equalTo(10);
  243. }];
  244. UILabel *label2 = [[UILabel alloc] init];
  245. label2.text = [NSString stringWithFormat:@"大小:%@MB", self.versionModel.fileSize];
  246. label2.textColor = HWF5F7FAColor;
  247. label2.font = [UIFont systemFontOfSize:10.f];
  248. [bgView addSubview:label2];
  249. [label2 mas_makeConstraints:^(MASConstraintMaker *make) {
  250. make.left.mas_equalTo(label1.mas_right).mas_offset(5);
  251. make.centerY.mas_equalTo(label1.mas_centerY);
  252. }];
  253. return bgView;
  254. }
  255. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
  256. return 35;
  257. }
  258. - (NSMutableArray *)dataSource {
  259. if (!_dataSource) {
  260. NSArray *tips = [self.versionModel.versionInfo componentsSeparatedByString:@"&&"];
  261. _dataSource = [NSMutableArray arrayWithArray:tips];
  262. }
  263. return _dataSource;
  264. }
  265. @end