EncodingFormatViewController.mm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // EncodingFormatViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/12/17.
  6. // Copyright © 2018 wujiangbo. All rights reserved.
  7. //
  8. #import "EncodingFormatViewController.h"
  9. #import "ItemTableviewCell.h"
  10. #import "EncodeItemViewController.h"
  11. #import "SystemFunctionConfig.h"
  12. @interface EncodingFormatViewController ()<UITableViewDelegate,UITableViewDataSource,SystemFunctionConfigDelegate>
  13. {
  14. NSArray *encodeTitleArray; //编码格式数组
  15. UITableView *ebcodeTableView; //编码格式列表
  16. }
  17. @property (nonatomic, strong) SystemFunctionConfig * functionConfig;
  18. @end
  19. @implementation EncodingFormatViewController
  20. - (void)viewDidLoad {
  21. [super viewDidLoad];
  22. //初始化数据和界面
  23. [self initDataSource];
  24. [self configSubView];
  25. //设置导航栏
  26. [self setNaviStyle];
  27. //获取配置
  28. [self getConfig];
  29. }
  30. -(void)viewWillDisappear:(BOOL)animated{
  31. if ([SVProgressHUD isVisible]) {
  32. [SVProgressHUD dismiss];
  33. }
  34. }
  35. - (void)setNaviStyle {
  36. self.navigationItem.title = TS("Encoding_format");
  37. }
  38. #pragma mark - tableView代理方法
  39. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  40. return encodeTitleArray.count;
  41. }
  42. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  43. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  44. if (!cell) {
  45. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  46. }
  47. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  48. NSString *title = [encodeTitleArray objectAtIndex:indexPath.row];
  49. cell.textLabel.text = title;
  50. return cell;
  51. }
  52. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  53. NSString *titleStr = encodeTitleArray[indexPath.row];
  54. //初始化各个配置的item单元格
  55. EncodeItemViewController *itemVC = [[EncodeItemViewController alloc] init];
  56. [itemVC setTitle:titleStr];
  57. __weak typeof(self) weakSelf = self;
  58. itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
  59. //itemVC的单元格点击回调,设置各种属性
  60. ItemTableviewCell *cell = [weakSelf.ebcodeTableView cellForRowAtIndexPath:indexPath];
  61. cell.Labeltext.text = encodeString;
  62. };
  63. [itemVC setValueArray:[@[TS("close"),TS("open")] mutableCopy]];
  64. [self.navigationController pushViewController:itemVC animated:YES];
  65. }
  66. #pragma mark - 保存编码配置
  67. -(void)saveConfig{
  68. [SVProgressHUD show];
  69. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  70. ItemTableviewCell *cell = [self.ebcodeTableView cellForRowAtIndexPath:indexPath];
  71. NSString *valueStr = cell.Labeltext.text;
  72. if ([valueStr isEqualToString:TS("close")]) {
  73. [self.functionConfig setSmartH264Info:0];
  74. }
  75. else{
  76. [self.functionConfig setSmartH264Info:1];
  77. }
  78. }
  79. #pragma mark - 获取编码配置
  80. -(void)getConfig{
  81. [SVProgressHUD show];
  82. if (!_functionConfig) {
  83. _functionConfig = [[SystemFunctionConfig alloc] init];
  84. _functionConfig.delegate = self;
  85. }
  86. [self.functionConfig getSmartH264Info];
  87. }
  88. #pragma mark - 获取编码配置回调
  89. -(void)SmartH264InfoConfigGetResult:(BOOL)result smartH264:(int)SmartH264{
  90. NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  91. ItemTableviewCell *cell = [self.ebcodeTableView cellForRowAtIndexPath:indexPath];
  92. cell.Labeltext.text = SmartH264 == 0 ? TS("close") : TS("open");
  93. }
  94. #pragma mark - 界面和数据初始化
  95. -(void)initDataSource {
  96. encodeTitleArray = @[TS("H264+")];
  97. }
  98. - (void)configSubView {
  99. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
  100. self.navigationItem.rightBarButtonItem = rightButton;
  101. [self.view addSubview:self.ebcodeTableView];
  102. }
  103. - (UITableView *)ebcodeTableView {
  104. if (!ebcodeTableView) {
  105. ebcodeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  106. ebcodeTableView.delegate = self;
  107. ebcodeTableView.dataSource = self;
  108. [ebcodeTableView registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  109. }
  110. return ebcodeTableView;
  111. }
  112. @end