YOUPAILZHotMusicCell.m 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. //
  2. // YOUPAILZHotMusicCell.m
  3. // YOUQU
  4. //
  5. // Created by CY on 2021/12/10.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZHotMusicCell.h"
  9. @interface YOUPAILZHotMusicCell ()
  10. @property (nonatomic, weak) UILabel *youpaipsongNameL; // 歌曲名称
  11. @property (nonatomic, weak) UILabel *youpaipsingerL; // 演唱者
  12. @property (nonatomic, weak) UIButton *youpaipaddBtn; // 点播
  13. @property (nonatomic, strong) YOUPAILZMusicListItemModel *youpaipmodel;
  14. @end
  15. @implementation YOUPAILZHotMusicCell
  16. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  17. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  18. self.selectionStyle = UITableViewCellSelectionStyleNone;
  19. self.backgroundColor = [UIColor clearColor];
  20. [self youpaifinitUI];
  21. }
  22. return self;
  23. }
  24. - (void)youpaifinitUI{
  25. UIButton *youpaipaddBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  26. [youpaipaddBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(58.0f, 25.0f) FromColors:@[HexColorFromRGB(0xFF0084),HexColorFromRGB(0xFF3A00)] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  27. [youpaipaddBtn setBackgroundImage:[LCTools ColorImage:CGSizeMake(58.0f, 25.0f) FromColors:@[HexColorFromRGB(0x4F4B5B),HexColorFromRGB(0x4F4B5B)] ByGradientType:GradientLeftToRight] forState:UIControlStateSelected];
  28. [youpaipaddBtn setTitle:@"点播" forState:UIControlStateNormal];
  29. [youpaipaddBtn setTitle:@"已点" forState:UIControlStateSelected];
  30. [youpaipaddBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  31. youpaipaddBtn.titleLabel.font = LCFont(13.0f);
  32. youpaipaddBtn.clipsToBounds = YES;
  33. youpaipaddBtn.layer.cornerRadius = 2.0f;
  34. [youpaipaddBtn addTarget:self action:@selector(youpaifaddBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  35. [self.contentView addSubview:youpaipaddBtn];
  36. self.youpaipaddBtn = youpaipaddBtn;
  37. [youpaipaddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  38. make.right.offset(-14.0f);
  39. make.size.mas_offset(CGSizeMake(58.0f, 25.0f));
  40. make.centerY.equalTo(self.contentView);
  41. }];
  42. UILabel *youpaipsongNameL = [[UILabel alloc] init];
  43. youpaipsongNameL.font = LCFont(14.0f);
  44. youpaipsongNameL.textColor = [UIColor whiteColor];
  45. [self.contentView addSubview:youpaipsongNameL];
  46. self.youpaipsongNameL = youpaipsongNameL;
  47. [youpaipsongNameL mas_makeConstraints:^(MASConstraintMaker *make) {
  48. make.left.offset(14.0f);
  49. make.top.offset(14.0f);
  50. make.right.equalTo(youpaipaddBtn.mas_left).offset(-14.0f);
  51. }];
  52. UILabel *youpaipsingerL = [[UILabel alloc] init];
  53. youpaipsingerL.font = LCFont(11.0f);
  54. youpaipsingerL.textColor = HexColorFromRGB(0x9F9DA5);
  55. [self.contentView addSubview:youpaipsingerL];
  56. self.youpaipsingerL = youpaipsingerL;
  57. [youpaipsingerL mas_makeConstraints:^(MASConstraintMaker *make) {
  58. make.top.equalTo(youpaipsongNameL.mas_bottom).offset(6.0f);
  59. make.left.offset(14.0f);
  60. make.right.equalTo(youpaipaddBtn.mas_left).offset(-14.0f);
  61. }];
  62. }
  63. - (void)youpaifaddBtnClick:(UIButton *)sender{
  64. sender.selected = !sender.selected;
  65. if (sender.selected == YES) {
  66. [[YOUPAILZMusicManager shareManager] youpaifaddMusic:self.youpaipmodel];
  67. NSDictionary *params = @{
  68. @"songCode":self.youpaipmodel.youpaipsongCode,
  69. @"duration":self.youpaipmodel.youpaipduration,
  70. @"singer":self.youpaipmodel.youpaipsinger,
  71. @"name":self.youpaipmodel.youpaipname,
  72. @"poster":self.youpaipmodel.youpaipposter,
  73. };
  74. [LCHttpHelper requestWithURLString:AddMySong parameters:params needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  75. NSDictionary* dict = (NSDictionary*)responseObject;
  76. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  77. if (code == 0) {//成功
  78. self.youpaipmodel.youpaipis_add = YES;
  79. }
  80. } failure:^(NSError *error) {
  81. }];
  82. }else{
  83. [[YOUPAILZMusicManager shareManager] youpaifremoveMusic:self.youpaipmodel];
  84. [LCHttpHelper requestWithURLString:DelMySong parameters:@{@"songCode":self.youpaipmodel.youpaipsongCode} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  85. NSDictionary* dict = (NSDictionary*)responseObject;
  86. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  87. if (code == 0) {//成功
  88. self.youpaipmodel.youpaipis_add = NO;
  89. }
  90. } failure:^(NSError *error) {
  91. }];
  92. }
  93. }
  94. -(void)youpaifreloadWithModel:(YOUPAILZMusicListItemModel *)model{
  95. self.youpaipmodel = model;
  96. self.youpaipsongNameL.text = model.youpaipname;
  97. self.youpaipaddBtn.selected = self.youpaipmodel.youpaipis_add;
  98. //
  99. // NSMutableString *artistStr = [NSMutableString string];
  100. // for (YOUPAILZMusicArtistModel *artistModel in model.youpaipartist) {
  101. // [artistStr appendString:artistModel.youpaipname];
  102. // if (artistModel != model.youpaipartist.lastObject) {
  103. // [artistStr appendString:@"/"];
  104. // }
  105. // }
  106. // if (artistStr.length != 0 && model.youpaipalbumName.length != 0) {
  107. // [artistStr appendString:@" - "];
  108. // }
  109. // [artistStr appendString:model.youpaipalbumName];
  110. self.youpaipsingerL.text = model.youpaipsinger;
  111. }
  112. @end