HaveNewVersionView.m 13 KB

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