WaterMarkViewController.mm 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. //
  2. // WaterMarkViewController.m
  3. // FunSDKDemo
  4. //
  5. // Created by wujiangbo on 2018/12/19.
  6. // Copyright © 2018 wujiangbo. All rights reserved.
  7. //
  8. #import "WaterMarkViewController.h"
  9. #import "WaterMarkConfig.h"
  10. #import "ItemTableviewCell.h"
  11. #import "EncodeItemViewController.h"
  12. #import "Header.h"
  13. @interface WaterMarkViewController ()<UITableViewDelegate,UITableViewDataSource,WaterMarkConfigDelegate,UITextFieldDelegate>
  14. {
  15. WaterMarkConfig *config; //水印配置
  16. NSArray *titleArray; //水印配置数组
  17. UITableView *tableView; //水印配置列表
  18. }
  19. @end
  20. @implementation WaterMarkViewController
  21. - (void)viewDidLoad {
  22. [super viewDidLoad];
  23. self.view.backgroundColor = [UIColor whiteColor];
  24. //初始化数据和界面
  25. [self initDataSource];
  26. [self configSubView];
  27. //设置导航栏
  28. [self setNaviStyle];
  29. //获取配置
  30. [self getConfig];
  31. }
  32. -(void)viewWillDisappear:(BOOL)animated{
  33. if ([SVProgressHUD isVisible]) {
  34. [SVProgressHUD dismiss];
  35. }
  36. }
  37. - (void)setNaviStyle {
  38. self.navigationItem.title = TS("Watermark_setting");
  39. }
  40. #pragma mark - 获取配置
  41. -(void)getConfig{
  42. [SVProgressHUD show];
  43. if (!config) {
  44. config = [[WaterMarkConfig alloc] init];
  45. config.delegate = self;
  46. }
  47. //获取水印信息
  48. [config getLogoConfig];
  49. }
  50. #pragma mark - 保存配置
  51. -(void)saveConfig{
  52. [SVProgressHUD show];
  53. [config setWaterMarkConfig];
  54. }
  55. #pragma mark - tableView代理方法
  56. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  57. return titleArray.count;
  58. }
  59. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  60. ItemTableviewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ItemTableviewCell"];
  61. if (!cell) {
  62. cell = [[ItemTableviewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"ItemTableviewCell"];
  63. }
  64. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
  65. NSString *title = [titleArray objectAtIndex:indexPath.row];
  66. cell.textLabel.text = title;
  67. if ([title isEqualToString:TS("Watermark_switch")]) {
  68. int enable = [config getLogoEnable];
  69. cell.Labeltext.text = enable == 0 ? TS("close"):TS("open");
  70. }
  71. else if ([title isEqualToString:TS("Watermark_text")]){
  72. cell.Labeltext.text = [config getLogoTitle];
  73. }
  74. else if ([title isEqualToString:TS("Osd_Watermark_switch")]){
  75. int enable = [config getOsdLogoEnable];
  76. cell.Labeltext.text = enable == 0 ? TS("close"):TS("open");
  77. }
  78. return cell;
  79. }
  80. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
  81. NSString *titleStr = titleArray[indexPath.row];
  82. if ([titleStr isEqualToString:TS("Watermark_switch")]) {
  83. //初始化各个配置的item单元格
  84. EncodeItemViewController *itemVC = [[EncodeItemViewController alloc] init];
  85. [itemVC setTitle:titleStr];
  86. itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
  87. //itemVC的单元格点击回调,设置各种属性
  88. ItemTableviewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  89. cell.Labeltext.text = encodeString;
  90. if ([encodeString isEqualToString:TS("close")]) {
  91. [config setLossEnable:0];
  92. }
  93. else{
  94. [config setLossEnable:1];
  95. }
  96. };
  97. [itemVC setValueArray:[@[TS("close"),TS("open")] mutableCopy]];
  98. [self.navigationController pushViewController:itemVC animated:YES];
  99. }
  100. else if ([titleStr isEqualToString:TS("Watermark_text")]){
  101. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:TS("enter_custom_watermark") preferredStyle:UIAlertControllerStyleAlert];
  102. //增加取消按钮;
  103. [alertController addAction:[UIAlertAction actionWithTitle:TS("Cancel") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  104. }]];
  105. //增加确定按钮
  106. [alertController addAction:[UIAlertAction actionWithTitle:TS("OK") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  107. //获取第1个输入框
  108. UITextField *userNameTextField = alertController.textFields.firstObject;
  109. NSLog(@"shuiyin = %@",userNameTextField.text);
  110. [config setLogoTitle:userNameTextField.text];
  111. [tableView reloadData];
  112. }]];
  113. //定义一个输入框
  114. [alertController addTextFieldWithConfigurationHandler:^(UITextField * _Nonnull textField) {
  115. textField.placeholder = TS("enter_custom_watermark");
  116. textField.text = [config getLogoTitle];
  117. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textFieldChanged:) name:UITextFieldTextDidChangeNotification object:textField];
  118. }];
  119. [self presentViewController:alertController animated:true completion:nil];
  120. }
  121. else if ([titleStr isEqualToString:TS("Osd_Watermark_switch")]){
  122. //初始化各个配置的item单元格
  123. EncodeItemViewController *itemVC = [[EncodeItemViewController alloc] init];
  124. [itemVC setTitle:titleStr];
  125. itemVC.itemSelectStringBlock = ^(NSString *encodeString) {
  126. //itemVC的单元格点击回调,设置各种属性
  127. ItemTableviewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
  128. cell.Labeltext.text = encodeString;
  129. if ([encodeString isEqualToString:TS("close")]) {
  130. [config setOsdLogoEnable:0];
  131. }
  132. else{
  133. [config setOsdLogoEnable:1];
  134. }
  135. };
  136. [itemVC setValueArray:[@[TS("close"),TS("open")] mutableCopy]];
  137. [self.navigationController pushViewController:itemVC animated:YES];
  138. }
  139. }
  140. #pragma mark - textFieldDelegate
  141. -(void)textFieldChanged:(NSNotification*)notificaton{
  142. UITextField *textField = (UITextField *)notificaton.object;
  143. if (textField.text.length > 10) {
  144. textField.text = [textField.text substringToIndex:10];
  145. }
  146. }
  147. #pragma mark - funsdk回调处理
  148. -(void)getLogoWidgetResult:(NSInteger)result{
  149. if (result > 0) {
  150. //成功,刷新界面数据
  151. [tableView reloadData];
  152. [SVProgressHUD dismiss];
  153. }else{
  154. [MessageUI ShowErrorInt:(int)result];
  155. }
  156. }
  157. -(void)getOsdLogoConfigResult:(NSInteger)result{
  158. if (result > 0) {
  159. //成功,刷新界面数据
  160. [tableView reloadData];
  161. [SVProgressHUD dismiss];
  162. }else{
  163. [MessageUI ShowErrorInt:(int)result];
  164. }
  165. }
  166. -(void)setLogoWidgetResult:(NSInteger)result{
  167. if (result > 0) {
  168. //成功
  169. [SVProgressHUD dismissWithSuccess:TS("Success")];
  170. }else{
  171. [MessageUI ShowErrorInt:(int)result];
  172. }
  173. }
  174. -(void)setOsdLogoConfigResult:(NSInteger)result{
  175. if (result > 0) {
  176. //成功
  177. [SVProgressHUD dismissWithSuccess:TS("Success")];
  178. }else{
  179. [MessageUI ShowErrorInt:(int)result];
  180. }
  181. }
  182. #pragma mark - 界面和数据初始化
  183. -(void)initDataSource {
  184. titleArray = @[TS("Watermark_switch"),TS("Watermark_text"),TS("Osd_Watermark_switch")];
  185. }
  186. - (void)configSubView {
  187. UIBarButtonItem *rightButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(saveConfig)];
  188. self.navigationItem.rightBarButtonItem = rightButton;
  189. [self.view addSubview:self.tableView];
  190. }
  191. - (UITableView *)tableView{
  192. if (!tableView) {
  193. tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight ) style:UITableViewStylePlain];
  194. tableView.delegate = self;
  195. tableView.dataSource = self;
  196. [tableView registerClass:[ItemTableviewCell class] forCellReuseIdentifier:@"ItemTableviewCell"];
  197. }
  198. return tableView;
  199. }
  200. @end