CCShareDB.m 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. //
  2. // CCShareDB.m
  3. // Crypto Cloud Technology Nextcloud
  4. //
  5. // Created by Marino Faggiana on 13/11/15.
  6. // Copyright (c) 2014 TWS. All rights reserved.
  7. //
  8. #import "CCShareDB.h"
  9. #import "AppDelegate.h"
  10. @interface CCShareDB ()
  11. @end
  12. @implementation CCShareDB
  13. - (instancetype)initWithCoder:(NSCoder *)coder
  14. {
  15. self = [super initWithCoder:coder];
  16. if (self) {
  17. [self initializeForm];
  18. }
  19. return self;
  20. }
  21. - (void)initializeForm
  22. {
  23. XLFormDescriptor *form ;
  24. XLFormSectionDescriptor *section;
  25. XLFormRowDescriptor *row;
  26. form = [XLFormDescriptor formDescriptor];
  27. form.rowNavigationOptions = XLFormRowNavigationOptionNone;
  28. section = [XLFormSectionDescriptor formSection];
  29. [form addFormSection:section];
  30. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharelink" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)];
  31. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  32. [section addFormRow:row];
  33. row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharelinkbutton" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_share_link_button_", nil)];
  34. [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
  35. row.action.formSelector = @selector(shareLinkButton:);
  36. [section addFormRow:row];
  37. self.form = form;
  38. }
  39. - (void)viewDidLoad
  40. {
  41. [super viewDidLoad];
  42. // Color
  43. [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
  44. [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
  45. // view tint color
  46. [self.view setTintColor:COLOR_BRAND];
  47. [self reloadData];
  48. if ([[NSFileManager defaultManager] fileExistsAtPath:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadata.fileID]]) self.fileImageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@.ico", app.directoryUser, self.metadata.fileID]];
  49. else self.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
  50. self.labelTitle.text = self.metadata.fileNamePrint;
  51. [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
  52. self.endButton.tintColor = [COLOR_BRAND colorWithAlphaComponent:0.8];
  53. self.tableView.tableHeaderView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0.1 / UIScreen.mainScreen.scale)];
  54. line.backgroundColor = self.tableView.separatorColor;
  55. line;
  56. });
  57. }
  58. #pragma --------------------------------------------------------------------------------------------
  59. #pragma mark ===== Reload Data =====
  60. #pragma --------------------------------------------------------------------------------------------
  61. - (void)reloadData
  62. {
  63. self.shareLink = [app.sharesLink objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]];
  64. self.form.delegate = nil;
  65. XLFormRowDescriptor *rowShareLink = [self.form formRowWithTag:@"sharelink"];
  66. XLFormRowDescriptor *rowShareLinkButton = [self.form formRowWithTag:@"sharelinkbutton"];
  67. if ([self.shareLink length] > 0) [rowShareLink setValue:@1]; else [rowShareLink setValue:@0];
  68. rowShareLinkButton.hidden = [NSString stringWithFormat:@"$sharelink==0"];
  69. self.form.disabled = NO;
  70. self.form.delegate = self;
  71. [self.tableView reloadData];
  72. }
  73. #pragma --------------------------------------------------------------------------------------------
  74. #pragma mark ===== Change Value & Button =====
  75. #pragma --------------------------------------------------------------------------------------------
  76. - (void)shareLinkButton:(XLFormRowDescriptor *)sender
  77. {
  78. [self deselectFormRow:sender];
  79. NSString *url = self.shareLink;
  80. NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]];
  81. NSArray *applicationActivities = nil;
  82. UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
  83. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self presentViewController:activityController animated:YES completion:nil];
  84. if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
  85. UIPopoverController *popup;
  86. popup = [[UIPopoverController alloc] initWithContentViewController:activityController];
  87. [popup presentPopoverFromRect:CGRectMake(120, 100, 200, 400) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
  88. }
  89. }
  90. -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
  91. {
  92. [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
  93. if ([rowDescriptor.tag isEqualToString:@"sharelink"]) {
  94. if ([[rowDescriptor.value valueData] boolValue] == YES) {
  95. // share
  96. [self.delegate share:self.metadata serverUrl:self.serverUrl password:@""];
  97. [self disableForm];
  98. } else {
  99. // unshare
  100. [self.delegate unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl];
  101. [self disableForm];
  102. }
  103. }
  104. }
  105. #pragma --------------------------------------------------------------------------------------------
  106. #pragma mark ===== Button =====
  107. #pragma --------------------------------------------------------------------------------------------
  108. - (IBAction)endButtonAction:(id)sender
  109. {
  110. // reload delegate
  111. [self.delegate getDataSourceWithReloadTableView:self.metadata.directoryID fileID:nil selector:nil];
  112. [self dismissViewControllerAnimated:YES completion:nil];
  113. }
  114. #pragma --------------------------------------------------------------------------------------------
  115. #pragma mark ===== Utility =====
  116. #pragma --------------------------------------------------------------------------------------------
  117. -(void)disableForm
  118. {
  119. self.form.disabled = YES;
  120. [self.tableView reloadData];
  121. }
  122. @end