Browse Source

new share view

marinofaggiana 5 years ago
parent
commit
26bcbb1b27
2 changed files with 17 additions and 16 deletions
  1. 15 15
      iOSClient/Share/NCShareLinkMenuView.swift
  2. 2 1
      iOSClient/Share/NCShareUserMenuView.swift

+ 15 - 15
iOSClient/Share/NCShareLinkMenuView.swift

@@ -98,27 +98,29 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
     }
     
     func reloadData(idRemoteShared: Int) {
-        tableShare = NCManageDatabase.sharedInstance.getTableShare(account: metadata!.account, idRemoteShared: idRemoteShared)
         
+        tableShare = NCManageDatabase.sharedInstance.getTableShare(account: metadata!.account, idRemoteShared: idRemoteShared)
+        guard let tableShare = self.tableShare else { return }
+
         // Allow editing
-        if tableShare != nil && tableShare!.permissions > Int(k_read_share_permission) {
+        if UtilsFramework.isAnyPermission(toEdit: tableShare.permissions) {
             switchAllowEditing.setOn(true, animated: false)
         } else {
             switchAllowEditing.setOn(false, animated: false)
         }
         
         // Hide download
-        if tableShare != nil && tableShare!.hideDownload {
+        if tableShare.hideDownload {
             switchHideDownload.setOn(true, animated: false)
         } else {
             switchHideDownload.setOn(false, animated: false)
         }
         
         // Password protect
-        if tableShare != nil && tableShare!.shareWith.count > 0 {
+        if tableShare.shareWith.count > 0 {
             switchPasswordProtect.setOn(true, animated: false)
             fieldPasswordProtect.isEnabled = true
-            fieldPasswordProtect.text = tableShare!.shareWith
+            fieldPasswordProtect.text = tableShare.shareWith
         } else {
             switchPasswordProtect.setOn(false, animated: false)
             fieldPasswordProtect.isEnabled = false
@@ -126,14 +128,14 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         }
         
         // Set expiration date
-        if tableShare != nil && tableShare!.expirationDate != nil {
+        if tableShare.expirationDate != nil {
             switchSetExpirationDate.setOn(true, animated: false)
             fieldSetExpirationDate.isEnabled = true
             
             let dateFormatter = DateFormatter()
             dateFormatter.formatterBehavior = .behavior10_4
             dateFormatter.dateStyle = .medium
-            fieldSetExpirationDate.text = dateFormatter.string(from: tableShare!.expirationDate! as Date)
+            fieldSetExpirationDate.text = dateFormatter.string(from: tableShare.expirationDate! as Date)
         } else {
             switchSetExpirationDate.setOn(false, animated: false)
             fieldSetExpirationDate.isEnabled = false
@@ -141,11 +143,7 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         }
         
         // Note to recipient
-        if tableShare != nil {
-            fieldNoteToRecipient.text = tableShare!.note
-        } else {
-            fieldNoteToRecipient.text = ""
-        }
+        fieldNoteToRecipient.text = tableShare.note
     }
     
     // MARK: - IBAction
@@ -155,11 +153,12 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
         
         guard let tableShare = self.tableShare else { return }
         
-        var permission = 0
+        var permission: Int = 0
+        
         if sender.isOn {
-            permission = Int(k_read_share_permission) + Int(k_update_share_permission)
+            permission = UtilsFramework.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: false, andIsFolder: metadata!.directory)
         } else {
-            permission = Int(k_read_share_permission)
+            permission = UtilsFramework.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: false, andIsFolder: metadata!.directory)
         }
         
         let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
@@ -233,6 +232,7 @@ class NCShareLinkMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
     @IBAction func buttonDeleteShareLink(sender: UIButton) {
         
         guard let tableShare = self.tableShare else { return }
+        
         let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
         
         networking.unShare(idRemoteShared: tableShare.idRemoteShared)

+ 2 - 1
iOSClient/Share/NCShareUserMenuView.swift

@@ -82,6 +82,7 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
     }
     
     func reloadData(idRemoteShared: Int) {
+        
         tableShare = NCManageDatabase.sharedInstance.getTableShare(account: metadata!.account, idRemoteShared: idRemoteShared)
         guard let tableShare = self.tableShare else { return }
 
@@ -133,7 +134,6 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
                 permission = UtilsFramework.getPermissionsValue(byCanEdit: true, andCanCreate: true, andCanChange: true, andCanDelete: true, andCanShare: false, andIsFolder: metadata!.directory)
             } else {
                 permission = UtilsFramework.getPermissionsValue(byCanEdit: false, andCanCreate: false, andCanChange: false, andCanDelete: false, andCanShare: false, andIsFolder: metadata!.directory)
-
             }
         }
     
@@ -176,6 +176,7 @@ class NCShareUserMenuView: UIView, UIGestureRecognizerDelegate, NCShareNetworkin
     @IBAction func buttonUnshare(sender: UIButton) {
         
         guard let tableShare = self.tableShare else { return }
+        
         let networking = NCShareNetworking.init(account: metadata!.account, activeUrl: appDelegate.activeUrl,  view: self, delegate: self)
         
         networking.unShare(idRemoteShared: tableShare.idRemoteShared)