Эх сурвалжийг харах

Fix files lock UX

- use "lock/unlock **file**" to make it clearer what is being locked
- use "Locked by APPNAME app", to make a distinction between a user and an app lock
- show remaining locked time, or fallback to lock creation time
- re-order lock actions depending on if file is locked

Signed-off-by: Henrik Storch <henrik.storch@nextcloud.com>
Henrik Storch 3 жил өмнө
parent
commit
94404b901d

+ 2 - 2
iOSClient/Main/NCFunctionCenter.swift

@@ -616,7 +616,7 @@ import SVGKit
             }
         }
         let titleOffline = isOffline ? NSLocalizedString("_remove_available_offline_", comment: "") :  NSLocalizedString("_set_available_offline_", comment: "")
-        let titleLock = metadata.lock ? NSLocalizedString("_unlock_action_", comment: "") :  NSLocalizedString("_lock_action_", comment: "")
+        let titleLock = metadata.lock ? NSLocalizedString("_unlock_file_", comment: "") :  NSLocalizedString("_lock_file_", comment: "")
         let iconLock = metadata.lock ? "lock.open" : "lock"
         let copy = UIAction(title: NSLocalizedString("_copy_file_", comment: ""), image: UIImage(systemName: "doc.on.doc")) { _ in
             self.copyPasteboard(pasteboardOcIds: [metadata.ocId], hudView: viewController.view)
@@ -751,7 +751,7 @@ import SVGKit
             children.append(delete)
             children.insert(rename, at: 3)
             if NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1 {
-                children.insert(lockUnlock, at: 2)
+                children.insert(lockUnlock, at: metadata.lock ? 0 : 1)
             }
         } else if enableDeleteLocal {
             children.append(deleteConfirmLocal)

+ 32 - 9
iOSClient/Menu/NCCollectionViewCommon+Menu.swift

@@ -71,14 +71,21 @@ extension NCCollectionViewCommon {
                 action: nil
             )
         )
-        
+
         if metadata.lock {
-            let lockOwnerName = metadata.lockOwnerDisplayName.isEmpty ? metadata.lockOwner : metadata.lockOwnerDisplayName
-            let lockTime = DateFormatter.localizedString(from: metadata.lockTime ?? Date(), dateStyle: .short, timeStyle: .short)
+            var lockTimeString: String?
+            var lockOwnerName = metadata.lockOwnerDisplayName.isEmpty ? metadata.lockOwner : metadata.lockOwnerDisplayName
+            if metadata.lockOwnerType != 0 { lockOwnerName += " app" }
+            if let lockTime = metadata.lockTimeOut, let timeInterval = (lockTime.timeIntervalSince1970 - Date().timeIntervalSince1970).format() {
+                lockTimeString = String(format: NSLocalizedString("_time_remaining_", comment: ""), timeInterval)
+            } else if let lockTime = metadata.lockTime {
+                lockTimeString = DateFormatter.localizedString(from: lockTime, dateStyle: .short, timeStyle: .short)
+            } // else: don't show date detail
+
             actions.append(
                 NCMenuAction(
                     title: String(format: NSLocalizedString("_locked_by_", comment: ""), lockOwnerName),
-                    details: lockTime,
+                    details: lockTimeString,
                     icon: NCUtility.shared.loadUserImage(
                         for: metadata.lockOwner,
                            displayName: lockOwnerName,
@@ -86,7 +93,7 @@ extension NCCollectionViewCommon {
                     action: nil)
             )
         }
-        
+
         actions.append(.seperator)
 
         //
@@ -106,10 +113,6 @@ extension NCCollectionViewCommon {
             )
         )
 
-        if !metadata.directory, canUnlock, NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1 {
-            actions.append(.lockUnlockFiles(shouldLock: !metadata.lock, metadatas: [metadata]))
-        }
-
         //
         // DETAIL
         //
@@ -124,6 +127,15 @@ extension NCCollectionViewCommon {
                 )
             )
         }
+        if !metadata.directory, canUnlock, NCManageDatabase.shared.getCapabilitiesServerInt(account: appDelegate.account, elements: NCElementsJSON.shared.capabilitiesFilesLockVersion) >= 1 {
+            let lockAction = NCMenuAction.lockUnlockFiles(shouldLock: !metadata.lock, metadatas: [metadata])
+            if metadata.lock {
+                // make unlock first action, after info rows & seperator
+                actions.insert(lockAction, at: 3)
+            } else {
+                actions.append(lockAction)
+            }
+        }
 
         //
         // OFFLINE
@@ -344,3 +356,14 @@ extension NCCollectionViewCommon {
         presentMenu(with: actions)
     }
 }
+
+
+extension TimeInterval {
+    func format() -> String? {
+        let formatter = DateComponentsFormatter()
+        formatter.allowedUnits = [.day, .hour, .minute]
+        formatter.unitsStyle = .full
+        formatter.maximumUnitCount = 1
+        return formatter.string(from: self)
+    }
+}

+ 8 - 2
iOSClient/Menu/NCMenuAction.swift

@@ -226,11 +226,17 @@ extension NCMenuAction {
         )
     }
 
-    /// Lock or unlock a file using files_lock
+    /// Lock or unlock a file using *files_lock*
     static func lockUnlockFiles(shouldLock: Bool, metadatas: [tableMetadata], completion: (() -> Void)? = nil) -> NCMenuAction {
+        let titleKey: String
+        if metadatas.count == 1 {
+            titleKey = shouldLock ? "_lock_file_" : "_unlock_file_"
+        } else {
+            titleKey = shouldLock ? "_lock_selected_files_" : "_unlock_selected_files_"
+        }
         let imageName = !shouldLock ? "lock.open" : "lock"
         return NCMenuAction(
-            title: NSLocalizedString(shouldLock ? "_lock_action_" : "_unlock_action_", comment: ""),
+            title: NSLocalizedString(titleKey, comment: ""),
             icon: NCUtility.shared.loadImage(named: imageName),
             action: { _ in
                 for metadata in metadatas where metadata.lock != shouldLock {

+ 7 - 4
iOSClient/Supporting Files/en.lproj/Localizable.strings

@@ -149,10 +149,12 @@
 
 /* MARK: Files lock */
 
-"_lock_file_"               = "Lock";
-"_unlock_file_"             = "Unlock";
-"_locked_by_"               = "Locked by %@";
-"_file_locked_no_override_" = "This file is locked. It cannot be overridden.";
+"_lock_file_"                       = "Lock file";
+"_unlock_file_"                     = "Unock file";
+"_lock_selected_files_"             = "Lock files";
+"_unlock_selected_files_"           = "Unock files";
+"_locked_by_"                       = "Locked by %@";
+"_file_locked_no_override_"         = "This file is locked. It cannot be overridden.";
 
 /* Remove a file from a list, don't delete it entirely */
 "_remove_file_"             = "Remove file";
@@ -352,6 +354,7 @@
 "_disable_files_app_footer_"    = "Do not permit the access of files via the iOS Files application";
 "_trial_"                       = "Trial";
 "_trial_expired_day_"           = "Days remaining";
+"_time_remaining_"              = "%@ remaining";
 "_disableLocalCacheAfterUpload_footer_" = "After uploading the file, do not keep it in the local cache";
 "_disableLocalCacheAfterUpload_"        = "Disable local cache";
 "_autoupload_"                      = "Auto upload photos/videos";