Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/rename #102

Merged
merged 17 commits into from
Aug 17, 2018
Merged

Feature/rename #102

merged 17 commits into from
Aug 17, 2018

Conversation

pablocarmu
Copy link
Contributor

@pablocarmu pablocarmu commented Aug 3, 2018

Description

This pull request provides a way to rename items.

Related Issue

#21

Motivation and Context

How Has This Been Tested?

Screenshots (if appropriate):

simulator screen shot - iphone 6 plus - 2018-08-03 at 07 44 33

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

BUGS & improvements

@codecov
Copy link

codecov bot commented Aug 3, 2018

Codecov Report

Merging #102 into master will decrease coverage by 1.32%.
The diff coverage is 0.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #102      +/-   ##
==========================================
- Coverage   23.31%   21.98%   -1.33%     
==========================================
  Files          57       58       +1     
  Lines        4877     5172     +295     
==========================================
  Hits         1137     1137              
- Misses       3740     4035     +295
Impacted Files Coverage Δ
ownCloud/Client/Actions/NamingViewController.swift 0% <0%> (ø)
ownCloud/SDK Extensions/OCItem+Extension.swift 4.19% <0%> (-0.06%) ⬇️
ownCloud/Client/ClientQueryViewController.swift 0% <0%> (ø) ⬆️
ownCloud/Theming/NSObject+ThemeApplication.swift 78.15% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 421ff3b...9912c0c. Read the comment docs.

@jesmrec
Copy link
Contributor

jesmrec commented Aug 3, 2018

(1)

Renaming to a blank name should not be allowed.

current behaviour: if you rename a item to blank, an alert is shown with message "already exists", so that the name of the file is "\", same as the webdav name of the folder.

expected behaviour: rename to blank not allowed. For example, by disabling "Done" option.

tested with iPhoneX v11.4

@jesmrec
Copy link
Contributor

jesmrec commented Aug 3, 2018

(2)

Look at these steps (SDK involved @felix-schwarz )

  1. Set plane mode
  2. Rename an item
  3. Rename again the same item with a different name
  4. Go online again

Current: When the second renaming is performed, the source item does not already exist (was renamed before), so an alert is displayed with the initial file name. The final name of the item is the one in step 2. Maybe confusing for user who expects to get the name of the latest renaming.

@jesmrec
Copy link
Contributor

jesmrec commented Aug 3, 2018

(3)

Characters like "\" and "/" are forbidden in the name of the items. Server shows the message File name cannot contain <char> when you try to put them.

App does not behaves correctly is such cases. Displays error or gives no feedback about the issue.

@jesmrec
Copy link
Contributor

jesmrec commented Aug 3, 2018

(4)

The following one is not a correct user-use-case, pay attention:

Rename a image file by renaming the extension (f.ex. pic.jpg -> pic.pdf)

Thumbnail of the image is shown in list file. If you swipe to rename, in the renaming view appears the pdf icon.

Maybe, this is not the regular behaviour but if renaming removes the extension (f.ex pic.jpg -> pic), same issue appears in renaming view.

@jesmrec
Copy link
Contributor

jesmrec commented Aug 6, 2018

(5)

The rename view shows the option to confirm in different way in iPhone and iPad:

iPhone: Done
iPad: OK

Both should display the same wording

@jesmrec jesmrec mentioned this pull request Aug 7, 2018
7 tasks
@CLAassistant
Copy link

CLAassistant commented Aug 7, 2018

CLA assistant check
Thank you for your submission, we really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ pablocarmu
❌ felix-schwarz
You have signed the CLA already but the status is still pending? Let us recheck it.

pablocarmu pushed a commit that referenced this pull request Aug 8, 2018
pablocarmu pushed a commit that referenced this pull request Aug 8, 2018
@pablocarmu
Copy link
Contributor Author

pablocarmu commented Aug 8, 2018

About #102 (comment):

I use the standard iOS UIBarButtonItem init method:

convenience init(barButtonSystemItem systemItem: UIBarButtonItem.SystemItem, target: Any?, action: Selector?)

so the done button is initialized as:

doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(doneButtonPressed))

I have tested it with iOS 12 beta 5 and the iPad button now say Done so it seems that in iOS 11.* Apple has some diffs in the naming for this kind of UIBarButtons
One thing I could do is to hardcode the Done label to be always sure the label displayed its the same in all the devices/system versions

Copy link
Contributor

@felix-schwarz felix-schwarz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done!

Please see the comments for the few changes I think should be made.

The only issue not mentioned there: right now, the layout doesn't seem to adapt to the space needed by the software keyboard - and likewise doesn't vertically center the views when a hardware keyboard is used. I'm not sure if we should deal with that right away, or - in the name of faster progress - leave it as a TODO.

thumbnailImageView.image = item.icon(fitInSize: thumbnailSize)

if item.thumbnailAvailability != .none {
let displayThumbnail = { (thumbnail: OCItemThumbnail?) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since displayThumbnail is only used in the retrieveHandler, maybe inline that code there rather than creating a separate block for it.

private var thumbnailHeightAnchorConstraint: NSLayoutConstraint

private var stackViewLeftAnchorConstraint: NSLayoutConstraint?
private var stackviewRightAnchorConstraint: NSLayoutConstraint?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo here, you likely meant to start both with either stackview or stackView.

import UIKit
import ownCloudSDK

class RenameViewController: UIViewController {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we can use the same kind of UI for different operations (like naming newly created folders f.ex.), would be great to give this a different name and make it reusable for other purposes.

Thanks to the use of a completionHandler, we're already there, but for truly general purpose use of the view controller, this is still missing:

  • a block that allows validation of the entered string (like the part where you currently check for forbidden characters)
  • the itemToRename property should be renamed to something neutral
  • it should be possible to provide a string for the text field independent from the item (in case there is no item yet, like f.ex. when creating a new folder). Ideally the text field's content and that additional string property are kept in sync.
  • this view controller should also be passed to the completionHandler, so the completionHandler has access to all of its properties


@objc private func doneButtonPressed() {
if nameTextField.text!.contains("/") || nameTextField.text!.contains("\\") {
let controller = UIAlertController(title: "Forbiden Characters".localized, message: "File name cannot contain / or \\".localized, preferredStyle: .alert)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small typo here: should probably read "Forbidden characters."

})
}

_ = core!.retrieveThumbnail(for: item, maximumSize: self.thumbnailSize, scale: 0, retrieveHandler: { (error, _, _, thumbnail, _, progress) in
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be careful not to capture self strongly here (I think the displayThumbnail block captures it, and this captures displayThumbnail), since that block can be kept around for an extended amount of time.

self.core = core
self.completion = completion

blurView = UIVisualEffectView.init(effect: UIBlurEffect(style: .regular))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The view controller currently doesn't support theming. For this to really work well, however, it should also be possible to request the blur effect from the theme as well, so it fits in.

Since both is best done together, and the theme just isn't there yet, please just leave a TODO for theming support for now, so we can deal with it in the future.

let renamevc = RenameViewController(with: item, core: self.core, completion: { newName in
var summary : ProgressSummary = ProgressSummary(indeterminate: true, progress: 1.0, message: nil, progressCount: 1)
summary.message = NSString(format: "Renaming to %@".localized as NSString, newName) as String
self.queryProgressSummary = summary
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queryProgressSummary is reserved for usage by the OCQuery driving the ClientQueryViewController. To add progress information for the rename, please use the Progress object returned by OCCore.move and add it to the ClientQueryViewController's progressSummarizer via startTracking. The ProgressSummarizer will automatically remove the progress object once it indicates that it is done, so that's all. Like for deletion, the SDK currently doesn't provide progress information for moving, but this will change in a future SDK version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've seen the changes you made in the feature/delete pull request and I'll change it to that way!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@@ -80,7 +80,7 @@ extension NSObject {
let navigationController : UINavigationController = (self as? UINavigationController)!

navigationController.navigationBar.applyThemeCollection(collection, itemStyle: itemStyle)
navigationController.view.backgroundColor = collection.tableBackgroundColor
//navigationController.view.backgroundColor = collection.tableBackgroundColor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you comment out this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've left this line commented because when you launch a ThemeNavigationController with a RootViewController that has some transparency or blur view, this navigation controller background color interferes with the background color of your previous view you only see this color or this color with a blur. I've checked the app with the different themes we already support and I didn't notice any change.

Is there another better solution taking advantage of our Theme support mechanism?

Copy link
Contributor

@felix-schwarz felix-schwarz Aug 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point that was off my radar! Did you notice any regressions or visual glitches anywhere by leaving this line out?

@@ -23,4 +23,8 @@ extension String {
var localized: String {
return NSLocalizedString(self, comment: "")
}

func fileExtension() -> String? {
return NSURL(fileURLWithPath: self).pathExtension
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can achieve them same with less overhead with return (self as NSString).pathExtension. Since this method is only called once in the code, I would also suggest inlining it in the sole place that it is called from.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I can change the location of this method to OCItem+Extension.swift renaming it to item extension to be able to reuse it in the future if it's needed instead of coding it again. Or even create a new property in OCItem+Extension.swift like:

var extension: String {
 return (name as NSString).pathExtension
}

What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extension, of course, would be best, but I'm afraid of colliding with what Apple might provide in the future. What do you think about fileSuffix? That's recognizable for us, but not a reserved Swift keyboard and not what Apple could likely choose in the future (pathExtension).

pablocarmu pushed a commit that referenced this pull request Aug 10, 2018
pablocarmu pushed a commit that referenced this pull request Aug 10, 2018
@jesmrec
Copy link
Contributor

jesmrec commented Aug 14, 2018

About the reported issues:

(2) and (4) are adressed to the SDK
(1) -> Fixed for files, not for folders. Renaming folders set a blank as default
(3) -> Only a wording issue: Forbiden -> Forbidden
(5) -> Won't fix. Wording by system.

On the other hand: layout in landscape is OK and suggestions bar correctly removed.

@jesmrec
Copy link
Contributor

jesmrec commented Aug 14, 2018

(6)

UX improvement:

  1. Rename an item, but do not change the name
  2. click on "Done"

Current: Alert is shown, because the name already exists.
Suggested: In case an item is not renamed or renamed with the same name before, user should not be warned

pablocarmu pushed a commit that referenced this pull request Aug 14, 2018
@jesmrec
Copy link
Contributor

jesmrec commented Aug 14, 2018

All stuff reviewed from my side and it is OK.

@jesmrec jesmrec added the Approved by QA Approved by QA label Aug 14, 2018
- Removed the background color for UINavigationController in NSObject+Theme.swift to prevent errors with blur backgrounds.
- Coded a trailing swipe in ClientQueryViewController.swift with the rename action.
…extension remains untouched for consistency/security.
	- also call completionHandler if cancel is hit
	- make use of tuple result easier to read/maintain
@pablocarmu pablocarmu merged commit 5155165 into master Aug 17, 2018
@pablocarmu pablocarmu deleted the feature/rename branch August 17, 2018 11:45
@jesmrec jesmrec mentioned this pull request Jan 22, 2019
45 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants