Skip to content

Commit

Permalink
[feature/drag-drop-setting] Setting to disable dragging files inside …
Browse files Browse the repository at this point in the history
…the app (#643)

* #581 Added new setting to disable dragging files inside the app

* addressed CR findings and changed the title and the default value

* changed variable name for prevent dragging files and folders
  • Loading branch information
hosy authored Mar 17, 2020
1 parent c5ae2ed commit 86de363
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 6 deletions.
4 changes: 4 additions & 0 deletions ownCloud/Client/ClientQueryViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,10 @@ extension ClientQueryViewController: UITableViewDragDelegate {

func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {

if DisplaySettings.shared.preventDraggingFiles {
return [UIDragItem]()
}

if !self.tableView.isEditing {
self.populateToolbar()
}
Expand Down
3 changes: 2 additions & 1 deletion ownCloud/Resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,9 @@
"Increase Slider Value" = "Increase Slider Value";

/* Display settings */
"Display settings" = "Display settings";
"Advanced settings" = "Advanced settings";
"Show hidden files and folders" = "Show hidden files and folders";
"Prevent dragging of files and folders" = "Prevent dragging of files and folders";

/* Passcode Messages */

Expand Down
8 changes: 7 additions & 1 deletion ownCloud/Settings/DisplaySettingsSection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ class DisplaySettingsSection: SettingsSection {
override init(userDefaults: UserDefaults) {
super.init(userDefaults: userDefaults)

self.headerTitle = "Display settings".localized
self.headerTitle = "Advanced settings".localized

self.add(row: StaticTableViewRow(switchWithAction: { (row, _) in
if let newShowHiddenFiles = row.value as? Bool {
DisplaySettings.shared.showHiddenFiles = newShowHiddenFiles
}
}, title: "Show hidden files and folders".localized, value: DisplaySettings.shared.showHiddenFiles, identifier: "show-hidden-files-switch"))

self.add(row: StaticTableViewRow(switchWithAction: { (row, _) in
if let disableDragging = row.value as? Bool {
DisplaySettings.shared.preventDraggingFiles = disableDragging
}
}, title: "Prevent dragging of files and folders".localized, value: DisplaySettings.shared.preventDraggingFiles, identifier: "prevent-dragging-files-switch"))
}
}
5 changes: 5 additions & 0 deletions ownCloudAppFramework/Display Settings/DisplaySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,22 @@ NS_ASSUME_NONNULL_BEGIN
#pragma mark - Show hidden files
@property(assign,nonatomic) BOOL showHiddenFiles;

#pragma mark - Drag files
@property(assign,nonatomic) BOOL preventDraggingFiles;

#pragma mark - Query updating
- (void)updateQueryWithDisplaySettings:(OCQuery *)query;

@end

extern NSString *DisplaySettingsShowHiddenFilesPrefsKey; //!< The UserDefaults Key containing the BOOL value for .showHiddenFiles
extern NSString *DisplaySettingsPreventDraggingFilesPrefsKey; //!< The UserDefaults Key containing the BOOL value for .preventDraggingFiles

extern OCIPCNotificationName OCIPCNotificationNameDisplaySettingsChanged; //!< Posted when display settings changed (internal use only)
extern NSNotificationName DisplaySettingsChanged; //!< Posted when display settings changed (for use by app + File Provider)

extern OCClassSettingsIdentifier OCClassSettingsIdentifierDisplay; //!< The class settings identifier for the Display Settings
extern OCClassSettingsKey OCClassSettingsKeyDisplayShowHiddenFiles; //!< The class settings key for Show Hidden Files
extern OCClassSettingsKey OCClassSettingsKeyDisplayPreventDraggingFiles; //!< The class settings key if Drag Files is enabled

NS_ASSUME_NONNULL_END
32 changes: 31 additions & 1 deletion ownCloudAppFramework/Display Settings/DisplaySettings.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ + (OCClassSettingsIdentifier)classSettingsIdentifier
if ([identifier isEqual:OCClassSettingsIdentifierDisplay])
{
return (@{
OCClassSettingsKeyDisplayShowHiddenFiles : @(NO)
OCClassSettingsKeyDisplayShowHiddenFiles : @(NO),
OCClassSettingsKeyDisplayPreventDraggingFiles : @(NO)
});
}

Expand Down Expand Up @@ -59,6 +60,7 @@ - (instancetype)init
}];

_showHiddenFiles = [self _showHiddenFilesValue];
_preventDraggingFiles = [self _preventDraggingFilesValue];
}

return (self);
Expand All @@ -76,6 +78,10 @@ - (void)_handleDisplaySettingsChanged
_showHiddenFiles = [self _showHiddenFilesValue];
[self didChangeValueForKey:@"showHiddenFiles"];

[self willChangeValueForKey:@"preventDraggingFiles"];
_preventDraggingFiles = [self _preventDraggingFilesValue];
[self didChangeValueForKey:@"preventDraggingFiles"];

[[NSNotificationCenter defaultCenter] postNotificationName:DisplaySettingsChanged object:self];
}

Expand All @@ -101,6 +107,28 @@ - (void)setShowHiddenFiles:(BOOL)showHiddenFiles
[OCIPNotificationCenter.sharedNotificationCenter postNotificationForName:OCIPCNotificationNameDisplaySettingsChanged ignoreSelf:YES];
}

#pragma mark - Drag files
- (BOOL)_preventDraggingFilesValue
{
NSNumber *preventDraggingFilesNumber;

if ((preventDraggingFilesNumber = [OCAppIdentity.sharedAppIdentity.userDefaults objectForKey:DisplaySettingsPreventDraggingFilesPrefsKey]) != nil)
{
return (preventDraggingFilesNumber.boolValue);
}

return ([[self classSettingForOCClassSettingsKey:OCClassSettingsKeyDisplayPreventDraggingFiles] boolValue]);
}

- (void)setPreventDraggingFiles:(BOOL)preventDraggingFiles
{
_preventDraggingFiles = preventDraggingFiles;

[OCAppIdentity.sharedAppIdentity.userDefaults setBool:preventDraggingFiles forKey:DisplaySettingsPreventDraggingFilesPrefsKey];

[OCIPNotificationCenter.sharedNotificationCenter postNotificationForName:OCIPCNotificationNameDisplaySettingsChanged ignoreSelf:YES];
}

#pragma mark - Query updating
- (void)updateQueryWithDisplaySettings:(OCQuery *)query
{
Expand Down Expand Up @@ -135,10 +163,12 @@ - (BOOL)query:(OCQuery *)query shouldIncludeItem:(OCItem *)item
@end

NSString *DisplaySettingsShowHiddenFilesPrefsKey = @"display-show-hidden-files";
NSString *DisplaySettingsPreventDraggingFilesPrefsKey = @"display-prevent-dragging-files";

OCIPCNotificationName OCIPCNotificationNameDisplaySettingsChanged = @"org.owncloud.display-settings-changed";

NSNotificationName DisplaySettingsChanged = @"org.owncloud.display-settings-changed";

OCClassSettingsIdentifier OCClassSettingsIdentifierDisplay = @"display";
OCClassSettingsKey OCClassSettingsKeyDisplayShowHiddenFiles = @"show-hidden-files";
OCClassSettingsKey OCClassSettingsKeyDisplayPreventDraggingFiles = @"prevent-dragging-files";
7 changes: 4 additions & 3 deletions ownCloudTests/SettingsTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ class SettingsTests: XCTestCase {
EarlGrey.selectElement(with: grey_accessibilityID("theme")).assert(grey_sufficientlyVisible())
EarlGrey.selectElement(with: grey_accessibilityID("logging")).assert(grey_sufficientlyVisible())
}

/*
* PASSED if: Show hidden files and folders are displayed as part of the "Display Settings" section of Settings
* PASSED if: Show hidden files and folders, Drag Files are displayed as part of the "Advanced Settings" section of Settings
*/
func testCheckDisplaySettings () {

//Assert
EarlGrey.selectElement(with: grey_accessibilityID("show-hidden-files-switch")).assert(grey_sufficientlyVisible())
EarlGrey.selectElement(with: grey_accessibilityID("prevent-dragging-files-switch")).assert(grey_sufficientlyVisible())
}

/*
Expand Down

0 comments on commit 86de363

Please sign in to comment.