XYLiveManger.m 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878
  1. //
  2. // XYLiveManger.m
  3. // Starbuds
  4. //
  5. // Created by pajia on 2019/12/31.
  6. // Copyright © 2019 翟玉磊. All rights reserved.
  7. //
  8. #import "XYLiveManger.h"
  9. #import "XYLiveRoomAPIManager.h"
  10. #import "NSString+Utility.h"
  11. #import "XYShortVideoController.h"
  12. #import "XYExpressionItemView.h"
  13. #import "XYNiceNumView.h"
  14. static XYLiveManger *_sharedInstance;
  15. @interface XYLiveManger(){
  16. }
  17. @property (nonatomic, strong) NSString *whitenValue; //美白
  18. @property (nonatomic, strong) NSString *smoothValue; //磨皮
  19. @property (nonatomic, strong) NSString *redRosyValue; //红润
  20. @property (nonatomic, strong) NSString *highLightValue; //去高光
  21. @property (nonatomic, strong) NSString *faceLiftValue; //瘦脸
  22. @property (nonatomic, strong) NSString *enlargeEyeValue; //大眼
  23. @property (nonatomic, strong) NSString *smallFaceValue; //小脸
  24. @property (nonatomic, strong) NSString *faceOverallValue; //窄脸
  25. @property (nonatomic, strong) NSString *roundEyesValue; //圆眼
  26. @property (nonatomic, strong) NSString *jawValue; //下巴
  27. @property (nonatomic, strong) NSString *foreheadValue; //额头
  28. @property (nonatomic, strong) NSString *appleMuscleValue; //苹果肌
  29. @property (nonatomic, strong) NSString *thinNoseValue; //瘦鼻翼
  30. @property (nonatomic, strong) NSString *proboscidesValue; //长鼻
  31. @property (nonatomic, strong) UILabel *titlelab;
  32. @property (nonatomic, strong) NSTimer *keepBrightScreenTimer;
  33. @end
  34. @implementation XYLiveManger
  35. +(XYLiveManger *)shareInstance{
  36. @synchronized(self){
  37. if (_sharedInstance == nil){
  38. _sharedInstance = [[self alloc] init];
  39. }
  40. }
  41. return _sharedInstance;
  42. }
  43. - (instancetype)init{
  44. if (self = [super init]) {
  45. _whitenValue = @"0.5"; //美白
  46. _smoothValue = @"0.65"; //磨皮
  47. _redRosyValue = @"0.5"; //红润
  48. _highLightValue = @"0.0"; //去高光0.5
  49. _faceLiftValue = @"0.5"; //瘦脸
  50. _enlargeEyeValue = @"0.0"; //大眼
  51. _smallFaceValue = @"0.0"; //小脸
  52. _faceOverallValue = @"0.0"; //窄脸
  53. _roundEyesValue = @"0.0"; //圆眼
  54. _jawValue = @"0.0"; //下巴
  55. _foreheadValue = @"0.0"; //额头
  56. _appleMuscleValue = @"0.0"; //苹果肌
  57. _thinNoseValue = @"0.0"; //瘦鼻翼
  58. _proboscidesValue = @"0.0"; //长鼻
  59. NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveBeautyDefaultValue"];
  60. if (dict[@"whitenValue"]) {
  61. _whitenValue = dict[@"whitenValue"];
  62. }
  63. if (dict[@"smoothValue"]) {
  64. _smoothValue = dict[@"smoothValue"];
  65. }
  66. if (dict[@"redRosyValue"]) {
  67. _redRosyValue = dict[@"redRosyValue"];
  68. }
  69. if (dict[@"highLightValue"]) {
  70. _highLightValue = dict[@"highLightValue"];
  71. }
  72. if (dict[@"faceLiftValue"]) {
  73. _faceLiftValue = dict[@"faceLiftValue"];
  74. }
  75. if (dict[@"enlargeEyeValue"]) {
  76. _enlargeEyeValue = dict[@"enlargeEyeValue"];
  77. }
  78. if (dict[@"smallFaceValue"]) {
  79. _smallFaceValue = dict[@"smallFaceValue"];
  80. }
  81. if (dict[@"faceOverallValue"]) {
  82. _faceOverallValue = dict[@"faceOverallValue"];
  83. }
  84. if (dict[@"roundEyesValue"]) {
  85. _roundEyesValue = dict[@"roundEyesValue"];
  86. }
  87. if (dict[@"jawValue"]) {
  88. _jawValue = dict[@"jawValue"];
  89. }
  90. if (dict[@"foreheadValue"]) {
  91. _foreheadValue = dict[@"foreheadValue"];
  92. }
  93. if (dict[@"appleMuscleValue"]) {
  94. _appleMuscleValue = dict[@"appleMuscleValue"];
  95. }
  96. if (dict[@"thinNoseValue"]) {
  97. _thinNoseValue = dict[@"thinNoseValue"];
  98. }
  99. if (dict[@"proboscidesValue"]) {
  100. _proboscidesValue = dict[@"proboscidesValue"];
  101. }
  102. _currentFilterName = kLocalizedString(@"正常");
  103. NSDictionary *dict1 = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveFilterDefault"];
  104. if (dict1[@"currentFilterName"]) {
  105. _currentFilterName = dict1[@"currentFilterName"];
  106. }
  107. if (dict1[@"currentFilterPath"]) {
  108. _currentFilterPath = dict1[@"currentFilterPath"];
  109. }
  110. if (dict1[@"currentFilterValue"]) {
  111. _currentFilterValue = dict1[@"currentFilterValue"];
  112. }
  113. if ([[NSUserDefaults standardUserDefaults] objectForKey:@"HDWindowLoggerShow"]) {
  114. _HDWindowLoggerShow = YES;
  115. }
  116. }
  117. return self;
  118. }
  119. - (NSString *)stringFromTxtFile:(NSString *)path{
  120. NSData *data = [NSData dataWithContentsOfFile:path];
  121. NSMutableString *content = [[NSMutableString alloc] initWithData:data encoding:NSUTF8StringEncoding];
  122. return content;
  123. }
  124. - (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
  125. if (jsonString == nil) {
  126. return nil;
  127. }
  128. NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
  129. NSError *err;
  130. NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
  131. if(err){
  132. return nil;
  133. }
  134. return dic;
  135. }
  136. -(NSString*)dictionaryToJson:(NSDictionary *)dic{
  137. NSError *parseError = nil;
  138. NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&parseError];
  139. return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
  140. }
  141. - (UIImage *)convertViewToImage:(UIView *)view {
  142. view.backgroundColor = [UIColor clearColor];
  143. UIImage *imageRet = [[UIImage alloc] init];
  144. UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, [UIScreen mainScreen].scale);
  145. [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  146. imageRet = UIGraphicsGetImageFromCurrentImageContext();
  147. UIGraphicsEndImageContext();
  148. return imageRet;
  149. }
  150. #pragma mark - liveroomlogic
  151. #pragma mark chatlist
  152. ///房间聊天列表、个人详情,设置用户标签(等级等),richText后面追加内容(名字lable)
  153. - (void)setUserMarks:(XYLiveRoomMessageInfo *)info andRichText:(AWRichText *)richText{
  154. XYUserMarkIconInfo *markInfo = [[XYUserMarkIconInfo alloc] init];
  155. //新人标签
  156. if (info.userInfo.isNew) {
  157. markInfo.isNewMan = YES;
  158. }
  159. //官方标签
  160. if ([info.userRole integerValue] == XYVoiceRoomRoleOfficial) {
  161. markInfo.isOfficial = YES;
  162. }
  163. //主持人
  164. if ([info.userRole integerValue] == XYVoiceRoomRoleHost) {
  165. markInfo.isHost = YES;
  166. }
  167. //房管
  168. if ([info.userRole integerValue] == XYVoiceRoomRoleMaster) {
  169. markInfo.isManager = YES;
  170. }
  171. //房主
  172. if ([info.userRole integerValue] == XYVoiceRoomRoleAdmin) {
  173. markInfo.isHouseOwer = YES;
  174. }
  175. //超管(直播时用的)
  176. if ([info.userRole integerValue] == XYVoiceRoomRoleSuper) {
  177. markInfo.isSuperManager = YES;
  178. }
  179. //勋章
  180. if (info.medalId.length > 0) {
  181. markInfo.medalId = info.medalId;
  182. }
  183. //用户等级
  184. if (info.grageNum > 0) {
  185. markInfo.wealthLevel = info.grageNum;
  186. markInfo.wealthMedalStatus = info.grageMedalStatus;
  187. }
  188. //语音等级
  189. if ([info.starLevel integerValue] > 0) {
  190. markInfo.starLevel = [info.starLevel integerValue];
  191. }
  192. //靓号
  193. if ([info.niceNo integerValue] > 0 && info.niceLevel> 0) {
  194. markInfo.niceNo = info.niceNo;
  195. markInfo.niceLevel = info.niceLevel;
  196. }
  197. //性别
  198. if (info.userSex) {
  199. markInfo.sex = info.userSex;
  200. markInfo.age = [info.userAge integerValue];
  201. }
  202. //贵族标签
  203. if ([info.nobleValue integerValue] > 0) {
  204. markInfo.nobleLevel = [info.nobleValue integerValue];;
  205. }
  206. //vip标签
  207. if ([info.vipValue integerValue] > 0) {
  208. markInfo.vipValue = [info.vipValue integerValue];
  209. }
  210. //勋章
  211. if (info.activityMedals.count > 0) {
  212. markInfo.activityMedals = info.activityMedals;
  213. }
  214. XYUserMarkIconView *markView = [[XYUserMarkIconView alloc] init];
  215. [markView reload:markInfo andRichText:richText];
  216. }
  217. #pragma mark barrage
  218. - (UIImage *)getGradeNumImage:(XYLiveRoomMessageInfo *)info{
  219. // UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
  220. // view.backgroundColor = [UIColor clearColor];
  221. //
  222. // UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
  223. // imgView.contentMode = UIViewContentModeScaleAspectFill;
  224. // imgView.image = [UIImage imageNamed:[self getGradeImg:info]];
  225. // [view addSubview:imgView];
  226. //
  227. // UILabel *lab = [[UILabel alloc]init];
  228. // lab.font = [UIFont fontWithName:kPFSCMediumFont size:12];
  229. // lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  230. // lab.textAlignment = NSTextAlignmentRight;
  231. // lab.text = [NSString stringWithFormat:@"%ld",(long)info.grageNum];
  232. // lab.frame = CGRectMake(0, 0, 34, 20);
  233. // [view addSubview:lab];
  234. //
  235. // UIImage *gradeImg = [self convertViewToImage:view];
  236. // return gradeImg;
  237. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 48, 20)];
  238. view.backgroundColor = [UIColor clearColor];
  239. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 48, 20)];
  240. imgView.contentMode = UIViewContentModeScaleAspectFill;
  241. imgView.image = [UIImage imageNamed:[self getGradeImg:info]];
  242. [view addSubview:imgView];
  243. UIImage *gradeImg = [self convertViewToImage:view];
  244. return gradeImg;
  245. }
  246. - (NSString *)getGradeImg:(XYLiveRoomMessageInfo *)info{
  247. // if (info.grageNum <= 10) {
  248. // return @"xy-icon-grade1";
  249. //
  250. // }else if (info.grageNum >= 11 && info.grageNum <= 20){
  251. // return @"xy-icon-grade2";
  252. //
  253. // }else if (info.grageNum >= 21 && info.grageNum <= 30){
  254. // return @"xy-icon-grade3";
  255. //
  256. // }else if (info.grageNum >= 31 && info.grageNum <= 40){
  257. // return @"xy-icon-grade4";
  258. //
  259. // }else if (info.grageNum >= 51 && info.grageNum <= 50){
  260. // return @"xy-icon-grade5";
  261. //
  262. // }
  263. // return @"xy-icon-grade5";
  264. NSString *imgname = [NSString stringWithFormat:@"X_LV_%ld",info.grageNum];
  265. return imgname;
  266. }
  267. - (UIImage *)getAnchorGradeNumImage:(XYLiveRoomMessageInfo *)info{
  268. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
  269. view.backgroundColor = [UIColor clearColor];
  270. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
  271. imgView.contentMode = UIViewContentModeScaleAspectFill;
  272. imgView.image = [UIImage imageNamed:[self getAnchorGradeImg:info]];
  273. [view addSubview:imgView];
  274. UILabel *lab = [[UILabel alloc]init];
  275. lab.font = [UIFont fontWithName:kPFSCMediumFont size:12];
  276. lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  277. lab.textAlignment = NSTextAlignmentRight;
  278. lab.text = [NSString stringWithFormat:@"%ld",(long)info.anchorGrageNum];
  279. lab.frame = CGRectMake(0, 0, 34, 20);
  280. [view addSubview:lab];
  281. UIImage *gradeImg = [self convertViewToImage:view];
  282. return gradeImg;
  283. }
  284. - (NSString *)getAnchorGradeImg:(XYLiveRoomMessageInfo *)info{
  285. if (info.anchorGrageNum <= 10) {
  286. return @"xy-icon-anchorgrade1";
  287. }else if (info.anchorGrageNum >= 11 && info.anchorGrageNum <= 20){
  288. return @"xy-icon-anchorgrade2";
  289. }else if (info.anchorGrageNum >= 21 && info.anchorGrageNum <= 30){
  290. return @"xy-icon-anchorgrade3";
  291. }else if (info.anchorGrageNum >= 31 && info.anchorGrageNum <= 40){
  292. return @"xy-icon-anchorgrade4";
  293. }else if (info.anchorGrageNum >= 51 && info.anchorGrageNum <= 50){
  294. return @"xy-icon-anchorgrade5";
  295. }
  296. return @"xy-icon-anchorgrade1";
  297. }
  298. - (UIImage *)getVoiceRoomLevelImage:(XYLiveRoomMessageInfo *)info{
  299. UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
  300. view.backgroundColor = [UIColor clearColor];
  301. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
  302. imgView.contentMode = UIViewContentModeScaleAspectFill;
  303. imgView.image = [UIImage imageNamed:[self getVoiceRoomLevelImg:info]];
  304. [view addSubview:imgView];
  305. UILabel *lab = [[UILabel alloc]init];
  306. lab.font = [UIFont fontWithName:kPFSCMediumFont size:12];
  307. lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  308. lab.textAlignment = NSTextAlignmentRight;
  309. lab.text = [NSString stringWithFormat:@"%@",info.starLevel];
  310. lab.frame = CGRectMake(0, 0, 34, 20);
  311. [view addSubview:lab];
  312. UIImage *gradeImg = [self convertViewToImage:view];
  313. return gradeImg;
  314. }
  315. - (NSString *)getVoiceRoomLevelImg:(XYLiveRoomMessageInfo *)info{
  316. if ([info.starLevel integerValue] <= 10) {
  317. return @"xy-icon-voiceroom-tag1~10";
  318. }else if ([info.starLevel integerValue] >= 11 && [info.starLevel integerValue] <= 20){
  319. return @"xy-icon-voiceroom-tag11~20";
  320. }else if ([info.starLevel integerValue] >= 21 && [info.starLevel integerValue] <= 30){
  321. return @"xy-icon-voiceroom-tag21~30";
  322. }else if ([info.starLevel integerValue] >= 31 && [info.starLevel integerValue]<= 40){
  323. return @"xy-icon-voiceroom-tag31~40";
  324. }else if ([info.starLevel integerValue] >= 51 && [info.starLevel integerValue]<= 50){
  325. return @"xy-icon-voiceroom-tag41~50";
  326. }
  327. return @"xy-icon-voiceroom-tag1~10";
  328. }
  329. - (UIImage *)getFansNameImage{
  330. UIView *view = [[UIView alloc] init];
  331. view.backgroundColor = [UIColor clearColor];
  332. UIImageView *imgView = [[UIImageView alloc] init];
  333. [view addSubview:imgView];
  334. UILabel *lab = [[UILabel alloc] init];
  335. lab.font = [UIFont fontWithName:kPFSCMediumFont size:10];
  336. lab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  337. lab.textAlignment = NSTextAlignmentRight;
  338. lab.text = self.currentRoomFansName;
  339. [view addSubview:lab];
  340. float fansNameStrWidth = [lab.text stringWidth:lab.font andHeight:20];
  341. lab.frame = CGRectMake(18, 0, fansNameStrWidth, 20);
  342. fansNameStrWidth = fansNameStrWidth + 4;
  343. UIImage *image = [UIImage imageNamed:@"xy-icon-userfans"];
  344. image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
  345. imgView.image = image;
  346. imgView.frame = CGRectMake(0, 0, fansNameStrWidth + 20, 20);
  347. view.frame = CGRectMake(0, 0, fansNameStrWidth + 20, 20);
  348. UIImage *gradeImg = [self convertViewToImage:view];
  349. return gradeImg;
  350. }
  351. - (UIImage *)getNiceNoImage:(XYLiveRoomMessageInfo *)info{
  352. UIView *view = [[UIView alloc] init];
  353. view.backgroundColor = [UIColor clearColor];
  354. UIImageView *imgView = [[UIImageView alloc] init];
  355. [view addSubview:imgView];
  356. UILabel *lab = [[UILabel alloc] init];
  357. lab.font = [UIFont fontWithName:kPFSCMediumFont size:10];
  358. lab.textColor = [UIColor colorWithHexString:@"#2A1824" alpha:1];
  359. lab.textAlignment = NSTextAlignmentRight;
  360. lab.text = [NSString stringWithFormat:@"%@",info.niceNo];
  361. [view addSubview:lab];
  362. float labTextWidth = [lab.text stringWidth:lab.font andHeight:14];
  363. lab.frame = CGRectMake(4, 0, labTextWidth, 20);
  364. UIImage *image = [UIImage imageNamed:@"xy-lr-icon-niceshadow"];
  365. image = [image stretchableImageWithLeftCapWidth:image.size.width * 0.5 topCapHeight:image.size.height * 0.5];
  366. imgView.image = image;
  367. imgView.frame = CGRectMake(0, 0, labTextWidth + 8, 20);
  368. view.frame = CGRectMake(0, 0, labTextWidth + 8, 20);
  369. UIImage *niceNoImage = [self convertViewToImage:view];
  370. return niceNoImage;
  371. }
  372. - (UIView *)getSexView:(XYLiveRoomMessageInfo *)info{
  373. UIView *view = [[UIView alloc] init];
  374. if (info.userSex == 1) {
  375. view.backgroundColor = [UIColor colorWithHexString:@"#79E5FF" alpha:1];
  376. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  377. imgView.image = [UIImage imageNamed:@"xy-icon-userboy"];
  378. [view addSubview:imgView];
  379. }
  380. if (info.userSex == 2) {
  381. view.backgroundColor = [UIColor colorWithHexString:@"#FD7A8F" alpha:1];
  382. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
  383. imgView.image = [UIImage imageNamed:@"xy-icon-usergirl"];
  384. [view addSubview:imgView];
  385. }
  386. if ([info.userAge integerValue] > 0) {
  387. view.frame = CGRectMake(0, 0, 36, 20);
  388. UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, view.width-4, view.height)];
  389. lab.text = info.userAge;
  390. lab.textAlignment = NSTextAlignmentRight;
  391. lab.font = [UIFont fontWithName:kPFSCMediumFont size:12];
  392. lab.textColor = [UIColor whiteColor];
  393. [view addSubview:lab];
  394. }else{
  395. view.frame = CGRectMake(0, 0, 20, 20);
  396. }
  397. kViewRadius(view, 4);
  398. return view;
  399. }
  400. - (void)stopAnchorLiveRoom{
  401. NSString *liveHisId = [[NSUserDefaults standardUserDefaults] objectForKey:@"liveHisId"];
  402. if (liveHisId.length) {
  403. NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
  404. [param setObject:liveHisId forKey:@"liveHisId"];
  405. [[XYLiveRoomAPIManager new] liveStopLive:param successHandler:^(ZYLResponseModel *responseModel) {
  406. [[NSUserDefaults standardUserDefaults] removeObjectForKey:@"liveHisId"];
  407. } failureHandler:^(ZYLNetworkError *error) {
  408. }];
  409. }
  410. }
  411. //礼物界面用户分数等级值
  412. - (void)requestGiftListUserScoreData{
  413. if ([XYUserInfoManager nowUser]) {
  414. NSMutableDictionary *param = [[NSMutableDictionary alloc] init];
  415. [param setObject:@"11" forKey:@"scoreType"];
  416. [[XYLiveRoomAPIManager new] getScoreLevelInfo:param successHandler:^(ZYLResponseModel *responseModel) {
  417. [XYLiveManger shareInstance].scoreLevelInfoDataDict = responseModel.data;
  418. } failureHandler:^(ZYLNetworkError *error) {
  419. }];
  420. }
  421. }
  422. - (void)beautyEffectViewClear{
  423. }
  424. - (void)saveBeautyDefaultValue{
  425. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  426. [dict setObject:self.whitenValue forKey:@"whitenValue"];
  427. [dict setObject:self.smoothValue forKey:@"smoothValue"];
  428. [dict setObject:self.redRosyValue forKey:@"redRosyValue"];
  429. [dict setObject:self.highLightValue forKey:@"highLightValue"];
  430. [dict setObject:self.faceLiftValue forKey:@"faceLiftValue"];
  431. [dict setObject:self.enlargeEyeValue forKey:@"enlargeEyeValue"];
  432. [dict setObject:self.smallFaceValue forKey:@"smallFaceValue"];
  433. [dict setObject:self.faceOverallValue forKey:@"faceOverallValue"];
  434. [dict setObject:self.roundEyesValue forKey:@"roundEyesValue"];
  435. [dict setObject:self.jawValue forKey:@"jawValue"];
  436. [dict setObject:self.foreheadValue forKey:@"foreheadValue"];
  437. [dict setObject:self.appleMuscleValue forKey:@"appleMuscleValue"];
  438. [dict setObject:self.thinNoseValue forKey:@"thinNoseValue"];
  439. [dict setObject:self.proboscidesValue forKey:@"proboscidesValue"];
  440. [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"saveBeautyDefaultValue"];
  441. }
  442. - (void )setBeautyDefaultValue:(LiveRoomBeautyType )type andValue:(NSString *)value{
  443. }
  444. - (NSString *)getBeautyDefaultValue:(LiveRoomBeautyType )type{
  445. if (type == LiveRoomBeautyTypeWhiten){
  446. return self.whitenValue;
  447. }else if (type == LiveRoomBeautyTypeSmooth){
  448. return self.smoothValue;
  449. }else if (type == LiveRoomBeautyTypeRedRosy){
  450. return self.redRosyValue;
  451. }else if (type == LiveRoomBeautyTypeHighLight){
  452. return self.highLightValue;
  453. }else if (type == LiveRoomBeautyTypeFaceLift){
  454. return self.faceLiftValue;
  455. }else if (type == LiveRoomBeautyTypeEnlargeEye){
  456. return self.enlargeEyeValue;
  457. }else if (type == LiveRoomBeautyTypeSmallFace){
  458. return self.smallFaceValue;
  459. }else if (type == LiveRoomBeautyTypeFaceOverall){
  460. return self.faceOverallValue;
  461. }else if (type == LiveRoomBeautyTypeRoundEyes){
  462. return self.roundEyesValue;
  463. }else if (type == LiveRoomBeautyTypeJaw){
  464. return self.jawValue;
  465. }else if (type == LiveRoomBeautyTypeForehead){
  466. return self.foreheadValue;
  467. }else if (type == LiveRoomBeautyTypeAppleMuscle){
  468. return self.appleMuscleValue;
  469. }else if (type == LiveRoomBeautyTypeThinNose){
  470. return self.thinNoseValue;
  471. }else if (type == LiveRoomBeautyTypeProboscides){
  472. return self.proboscidesValue;
  473. }
  474. return nil;
  475. }
  476. - (void)saveFilterDefault{
  477. NSMutableDictionary *dict = [[NSMutableDictionary alloc] init];
  478. [dict setObject:self.currentFilterPath forKey:@"currentFilterPath"];
  479. [dict setObject:self.currentFilterValue forKey:@"currentFilterValue"];
  480. [dict setObject:self.currentFilterName forKey:@"currentFilterName"];
  481. [[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"saveFilterDefault"];
  482. }
  483. - (void)setFilterDefault{
  484. NSDictionary *dict = [[NSUserDefaults standardUserDefaults] objectForKey:@"saveFilterDefault"];
  485. self.currentFilterPath = dict[@"currentFilterPath"];
  486. self.currentFilterValue = dict[@"currentFilterValue"];
  487. self.currentFilterName = dict[@"currentFilterName"];
  488. if (!self.currentFilterName.length) {
  489. self.currentFilterName = kLocalizedString(@"正常");
  490. }
  491. }
  492. - (void)setFilterDefaultPath:(NSString *)path andValue:(NSString *)value{
  493. self.currentFilterPath = path;
  494. self.currentFilterValue = value;
  495. }
  496. - (NSString *)getFilterDefaultPath:(LiveRoomBeautyType )type{
  497. return self.currentFilterPath;
  498. }
  499. - (NSString *)getFilterDefaultValue:(LiveRoomBeautyType )type{
  500. return self.currentFilterPath;
  501. }
  502. - (NSString *)caluteWValue:(NSInteger )a{
  503. NSString *value;
  504. NSInteger b = a / 10000;
  505. if (b < 1) {
  506. value = [NSString stringWithFormat:@"%ld",(long)a];
  507. return value;
  508. }
  509. NSInteger c = a % 10000;
  510. NSInteger d = c / 1000;
  511. value = [NSString stringWithFormat:@"%ld.%ldW",(long)b,(long)d];
  512. return value;
  513. }
  514. - (CGSize )getABstringSize:(NSAttributedString *)abString{
  515. self.titlelab.attributedText = abString;
  516. [self.titlelab sizeToFit];
  517. //CGRect frame = self.titlelab.frame;
  518. return self.titlelab.size;
  519. }
  520. - (UILabel *)titlelab{
  521. if (_titlelab == nil) {
  522. _titlelab = [[UILabel alloc] init];
  523. _titlelab.text = @"";
  524. _titlelab.textAlignment = NSTextAlignmentLeft;
  525. _titlelab.textColor = [UIColor colorWithHexString:@"#FFFFFF" alpha:1];
  526. _titlelab.font = [UIFont fontWithName:kPFSCMediumFont size:16];
  527. [_titlelab sizeToFit];
  528. //_titlelab.hidden = YES;
  529. //[[UIApplication sharedApplication].keyWindow addSubview:_titlelab];
  530. }
  531. return _titlelab;
  532. }
  533. - (void)judgeCameraMic{
  534. kWEAKSELF
  535. NSString *mediaType = AVMediaTypeVideo;// Or AVMediaTypeAudio
  536. AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
  537. if (authStatus == AVAuthorizationStatusAuthorized) {
  538. AVAudioSession *avSession = [AVAudioSession sharedInstance];
  539. if ([avSession respondsToSelector:@selector(requestRecordPermission:)]) {
  540. [avSession requestRecordPermission:^(BOOL available) {
  541. if (available) {
  542. //completionHandler
  543. dispatch_async(dispatch_get_main_queue(), ^{
  544. if (weakSelf.AppCameraMicBlock) {
  545. weakSelf.AppCameraMicBlock(YES);
  546. }
  547. });
  548. }else{
  549. dispatch_async(dispatch_get_main_queue(), ^{
  550. NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME];
  551. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){
  552. if ([title isEqualToString:kLocalizedString(@"设置")]) {
  553. [weakSelf intoSystemSet];
  554. }
  555. }];
  556. [al show];
  557. });
  558. }
  559. }];
  560. }
  561. }else if(authStatus == AVAuthorizationStatusNotDetermined){
  562. // Explicit user permission is required for media capture, but the user has not yet granted or denied such permission.
  563. [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) {
  564. if(granted){//点击允许访问时调用
  565. //用户明确许可与否,媒体需要捕获,但用户尚未授予或拒绝许可。
  566. AVAudioSession *avSession = [AVAudioSession sharedInstance];
  567. if ([avSession respondsToSelector:@selector(requestRecordPermission:)]) {
  568. [avSession requestRecordPermission:^(BOOL available) {
  569. if (available) {
  570. //completionHandler
  571. dispatch_async(dispatch_get_main_queue(), ^{
  572. if (weakSelf.AppCameraMicBlock) {
  573. weakSelf.AppCameraMicBlock(YES);
  574. }
  575. });
  576. }else{
  577. dispatch_async(dispatch_get_main_queue(), ^{
  578. NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME];
  579. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){
  580. if ([title isEqualToString:kLocalizedString(@"设置")]) {
  581. [weakSelf intoSystemSet];
  582. }
  583. }];
  584. [al show];
  585. });
  586. }
  587. }];
  588. }
  589. }else {
  590. dispatch_async(dispatch_get_main_queue(), ^{
  591. NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME];
  592. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){
  593. if ([title isEqualToString:kLocalizedString(@"设置")]) {
  594. [weakSelf intoSystemSet];
  595. }
  596. }];
  597. [al show];
  598. });
  599. }
  600. }];
  601. }else{
  602. dispatch_async(dispatch_get_main_queue(), ^{
  603. NSString *content = [NSString stringWithFormat:kLocalizedString(@"请在“设置-隐私-麦克风”选项中允许‘%@’访问你的麦克风"), APP_NAME];
  604. CustomActionAlertController *al = [[CustomActionAlertController alloc] initWithTitle:[NSString stringWithFormat:@"%@%@",APP_NAME, kLocalizedString(@"想访问您的麦克风")] message:content sure:kLocalizedString(@"设置") cancel:kLocalizedString(@"取消") selctedBlock:^(NSInteger index, NSString * _Nonnull title){
  605. if ([title isEqualToString:kLocalizedString(@"设置")]) {
  606. [weakSelf intoSystemSet];
  607. }
  608. }];
  609. [al show];
  610. });
  611. }
  612. }
  613. - (void)intoSystemSet{
  614. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  615. [[UIApplication sharedApplication] openURL:url];
  616. }
  617. - (void)intoSystemAvdioSet{
  618. NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
  619. [[UIApplication sharedApplication] openURL:url];
  620. }
  621. - (void)keepBrightScreen{
  622. if (!self.keepBrightScreenTimer) {
  623. self.keepBrightScreenTimer = [NSTimer scheduledTimerWithTimeInterval:3 target:self selector:@selector(keepBrightScreenTimerAction) userInfo:nil repeats:YES];
  624. [UIApplication sharedApplication].idleTimerDisabled = YES;
  625. }
  626. }
  627. - (void)keepBrightScreenTimerAction{
  628. [UIApplication sharedApplication].idleTimerDisabled = YES;
  629. }
  630. - (void)cancelKeepBrightScreen{
  631. [self.keepBrightScreenTimer invalidate];
  632. self.keepBrightScreenTimer = nil;
  633. [UIApplication sharedApplication].idleTimerDisabled = NO;
  634. }
  635. - (void)pushLiveRoom:(NSString *)userid extra:(XYLiveRoomVCInfo *)extraInfo{
  636. }
  637. - (void)removeControllerWithClass:(Class)newClass {
  638. //删除指定栈内的控制器
  639. NSMutableArray *marr = [[NSMutableArray alloc]initWithArray:[AppDelegate sharedDelegate].getCurrentController.navigationController.viewControllers];
  640. for (NSInteger i = 0; i < marr.count; i++) {
  641. UIViewController *vc = marr[i];
  642. //防止删掉当前控制器
  643. if (i != (marr.count-1)) {
  644. if ([vc isKindOfClass:newClass]) {
  645. [marr removeObject:vc];
  646. break;
  647. }
  648. }
  649. }
  650. [AppDelegate sharedDelegate].getCurrentController.navigationController.viewControllers = marr;
  651. /*
  652. Removes the the receiver from its parent's children controllers array. If this method is overridden then
  653. the super implementation must be called.
  654. */
  655. // [self removeFromParentViewController];
  656. }
  657. - (UIView *)getSvgaView:(XYLiveRoomMessageInfo *)info{
  658. XYExpressionItemView *view = [[XYExpressionItemView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
  659. [view reload:info];
  660. return view;
  661. }
  662. - (NSAttributedString *)formatMessageString:(NSString *)text
  663. {
  664. //先判断text是否存在
  665. if (text == nil || text.length == 0) {
  666. NSLog(@"TTextMessageCell formatMessageString failed , current text is nil");
  667. return [[NSMutableAttributedString alloc] initWithString:@""];
  668. }
  669. //1、创建一个可变的属性字符串
  670. NSMutableAttributedString *attributeString = [[NSMutableAttributedString alloc] initWithString:text];
  671. UIFont *textFont = [UIFont fontWithName:kPFSCFont size:14];
  672. [attributeString addAttribute:NSFontAttributeName value:textFont range:NSMakeRange(0, attributeString.length)];
  673. return attributeString;
  674. // if([TUIKit sharedInstance].config.faceGroups.count == 0){
  675. // [attributeString addAttribute:NSFontAttributeName value:textFont range:NSMakeRange(0, attributeString.length)];
  676. // return attributeString;
  677. // }
  678. //
  679. // //2、通过正则表达式来匹配字符串
  680. // NSString *regex_emoji = @"\\[[a-zA-Z0-9\\/\\u4e00-\\u9fa5]+\\]"; //匹配表情
  681. //
  682. // NSError *error = nil;
  683. // NSRegularExpression *re = [NSRegularExpression regularExpressionWithPattern:regex_emoji options:NSRegularExpressionCaseInsensitive error:&error];
  684. // if (!re) {
  685. // NSLog(@"%@", [error localizedDescription]);
  686. // return attributeString;
  687. // }
  688. //
  689. // NSArray *resultArray = [re matchesInString:text options:0 range:NSMakeRange(0, text.length)];
  690. //
  691. // TFaceGroup *group = [TUIKit sharedInstance].config.faceGroups[0];
  692. //
  693. // //3、获取所有的表情以及位置
  694. // //用来存放字典,字典中存储的是图片和图片对应的位置
  695. // NSMutableArray *imageArray = [NSMutableArray arrayWithCapacity:resultArray.count];
  696. // //根据匹配范围来用图片进行相应的替换
  697. // for(NSTextCheckingResult *match in resultArray) {
  698. // //获取数组元素中得到range
  699. // NSRange range = [match range];
  700. // //获取原字符串中对应的值
  701. // NSString *subStr = [text substringWithRange:range];
  702. //
  703. // for (TFaceCellData *face in group.faces) {
  704. // if ([face.name isEqualToString:subStr]) {
  705. // //face[i][@"png"]就是我们要加载的图片
  706. // //新建文字附件来存放我们的图片,iOS7才新加的对象
  707. // NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init];
  708. // //给附件添加图片
  709. // textAttachment.image = [[TUIImageCache sharedInstance] getFaceFromCache:face.path];
  710. // //调整一下图片的位置,如果你的图片偏上或者偏下,调整一下bounds的y值即可
  711. // textAttachment.bounds = CGRectMake(0, -(textFont.lineHeight-textFont.pointSize)/2, textFont.pointSize, textFont.pointSize);
  712. // //把附件转换成可变字符串,用于替换掉源字符串中的表情文字
  713. // NSAttributedString *imageStr = [NSAttributedString attributedStringWithAttachment:textAttachment];
  714. // //把图片和图片对应的位置存入字典中
  715. // NSMutableDictionary *imageDic = [NSMutableDictionary dictionaryWithCapacity:2];
  716. // [imageDic setObject:imageStr forKey:@"image"];
  717. // [imageDic setObject:[NSValue valueWithRange:range] forKey:@"range"];
  718. // //把字典存入数组中
  719. // [imageArray addObject:imageDic];
  720. // break;
  721. // }
  722. // }
  723. // }
  724. //
  725. // //4、从后往前替换,否则会引起位置问题
  726. // for (int i = (int)imageArray.count -1; i >= 0; i--) {
  727. // NSRange range;
  728. // [imageArray[i][@"range"] getValue:&range];
  729. // //进行替换
  730. // [attributeString replaceCharactersInRange:range withAttributedString:imageArray[i][@"image"]];
  731. // }
  732. //
  733. //
  734. // [attributeString addAttribute:NSFontAttributeName value:textFont range:NSMakeRange(0, attributeString.length)];
  735. //
  736. // return attributeString;
  737. }
  738. @end