123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- //
- // CCShareDB.m
- // Crypto Cloud Technology Nextcloud
- //
- // Created by Marino Faggiana on 13/11/15.
- // Copyright (c) 2014 TWS. All rights reserved.
- //
- #import "CCShareDB.h"
- #import "AppDelegate.h"
- @interface CCShareDB ()
- @end
- @implementation CCShareDB
- - (instancetype)initWithCoder:(NSCoder *)coder
- {
- self = [super initWithCoder:coder];
- if (self) {
- [self initializeForm];
- }
- return self;
- }
- - (void)initializeForm
- {
- XLFormDescriptor *form ;
- XLFormSectionDescriptor *section;
- XLFormRowDescriptor *row;
-
- form = [XLFormDescriptor formDescriptor];
- form.rowNavigationOptions = XLFormRowNavigationOptionNone;
-
- section = [XLFormSectionDescriptor formSection];
- [form addFormSection:section];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharelink" rowType:XLFormRowDescriptorTypeBooleanSwitch title:NSLocalizedString(@"_share_link_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- [section addFormRow:row];
-
- row = [XLFormRowDescriptor formRowDescriptorWithTag:@"sharelinkbutton" rowType:XLFormRowDescriptorTypeButton title:NSLocalizedString(@"_share_link_button_", nil)];
- [row.cellConfig setObject:[UIFont systemFontOfSize:15.0]forKey:@"textLabel.font"];
- row.action.formSelector = @selector(shareLinkButton:);
- [section addFormRow:row];
- self.form = form;
- }
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- // Color
- [CCAspect aspectNavigationControllerBar:self.navigationController.navigationBar hidden:NO];
- [CCAspect aspectTabBar:self.tabBarController.tabBar hidden:NO];
-
- // view tint color
- [self.view setTintColor:COLOR_BRAND];
-
- [self reloadData];
-
- 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]];
- else self.fileImageView.image = [UIImage imageNamed:self.metadata.iconName];
-
- self.labelTitle.text = self.metadata.fileNamePrint;
- [self.endButton setTitle:NSLocalizedString(@"_done_", nil) forState:UIControlStateNormal];
- self.endButton.tintColor = [COLOR_BRAND colorWithAlphaComponent:0.8];
-
- self.tableView.tableHeaderView = ({UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.tableView.frame.size.width, 0.1 / UIScreen.mainScreen.scale)];
- line.backgroundColor = self.tableView.separatorColor;
- line;
- });
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Reload Data =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)reloadData
- {
- self.shareLink = [app.sharesLink objectForKey:[self.serverUrl stringByAppendingString:self.metadata.fileName]];
- self.form.delegate = nil;
- XLFormRowDescriptor *rowShareLink = [self.form formRowWithTag:@"sharelink"];
- XLFormRowDescriptor *rowShareLinkButton = [self.form formRowWithTag:@"sharelinkbutton"];
-
- if ([self.shareLink length] > 0) [rowShareLink setValue:@1]; else [rowShareLink setValue:@0];
-
- rowShareLinkButton.hidden = [NSString stringWithFormat:@"$sharelink==0"];
-
- self.form.disabled = NO;
- self.form.delegate = self;
-
- [self.tableView reloadData];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Change Value & Button =====
- #pragma --------------------------------------------------------------------------------------------
- - (void)shareLinkButton:(XLFormRowDescriptor *)sender
- {
- [self deselectFormRow:sender];
-
- NSString *url = self.shareLink;
-
- NSArray *activityItems = @[[NSString stringWithFormat:@""], [NSURL URLWithString:url]];
- NSArray *applicationActivities = nil;
-
- UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:applicationActivities];
-
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) [self presentViewController:activityController animated:YES completion:nil];
- if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
-
- UIPopoverController *popup;
-
- popup = [[UIPopoverController alloc] initWithContentViewController:activityController];
- [popup presentPopoverFromRect:CGRectMake(120, 100, 200, 400) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
- }
- }
- -(void)formRowDescriptorValueHasChanged:(XLFormRowDescriptor *)rowDescriptor oldValue:(id)oldValue newValue:(id)newValue
- {
- [super formRowDescriptorValueHasChanged:rowDescriptor oldValue:oldValue newValue:newValue];
-
- if ([rowDescriptor.tag isEqualToString:@"sharelink"]) {
-
- if ([[rowDescriptor.value valueData] boolValue] == YES) {
-
- // share
- [self.delegate share:self.metadata serverUrl:self.serverUrl password:@""];
- [self disableForm];
-
- } else {
-
- // unshare
- [self.delegate unShare:self.shareLink metadata:self.metadata serverUrl:self.serverUrl];
- [self disableForm];
- }
- }
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Button =====
- #pragma --------------------------------------------------------------------------------------------
- - (IBAction)endButtonAction:(id)sender
- {
- // reload delegate
- [self.delegate getDataSourceWithReloadTableView:self.metadata.directoryID fileID:nil selector:nil];
-
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- #pragma --------------------------------------------------------------------------------------------
- #pragma mark ===== Utility =====
- #pragma --------------------------------------------------------------------------------------------
- -(void)disableForm
- {
- self.form.disabled = YES;
- [self.tableView reloadData];
- }
- @end
|