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

Fixes #3886 #3898

Merged
merged 14 commits into from
Sep 24, 2023
Merged

Fixes #3886 #3898

merged 14 commits into from
Sep 24, 2023

Conversation

yatiksihag01
Copy link
Contributor

Description

Disabled file modification while the copy/paste snackbar is visible. This behavior is expected, and it is implemented in almost all popular file manager apps. When users choose to paste a file into the same folder from which they copied it, they will be presented with the option to Rename & Save. This option will automatically append (1), (2), etc., at the end of the file name and save it.

Issue tracker

Fixes #3886

Automatic tests

  • Added test cases

Manual tests

  • Done
  • Device: Samsung Galaxy A13
  • OS: Android 13

Build tasks success

Successfully running following tasks on local:

  • ./gradlew assembledebug
  • ./gradlew spotlessCheck

do {
newName =
oldName.substring(0, oldName.lastIndexOf("."))
+ "("
Copy link
Member

Choose a reason for hiding this comment

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

@TranceLove @VishnuSanal your inputs here. Do we have a library or a utility class that we can utilise for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Related #2078 sorry but still need some time to work on it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

You may want to see if #3913 can help.

Copy link
Member

@VishnuSanal VishnuSanal left a comment

Choose a reason for hiding this comment

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

@yatiksihag01 hi, great work! here are some things I noticed:

  • currently, the renaming works only for files. if I try to copy a directory & paste it, it renames every file inside of that folder - which is not the expected behavior; the directory simply should be renamed instead.

@yatiksihag01
Copy link
Contributor Author

@VishnuSanal thanks for your feedback and for pointing out the issue. Sorry for the oversight, I'll try to make the necessary changes asap.

@yatiksihag01
Copy link
Contributor Author

yatiksihag01 commented Aug 13, 2023

Hi @VishnuSanal in this commit I've made following changes:

  • Pasting in the same directory with a conflicting non-directory file (e.g. images, videos etc.) will prompt a rename or skip choice.
  • Move operation in same directory is restricted.
  • If the conflicting file is a directory, it's automatically renamed and saved without showing any dialog. This workaround avoids the complexity of showing a dialog in this scenario, as it would require significant changes. Because during tree creation, the original conflicting directory is already removed and a new node is created. And now all the files and subdirectories under this new node behave as conflicting entities. Ig this approach offers the best solution. I'm open to any suggestions or feedback you might have.

Note: When I use MakeDirectoryOperation.mkdirs() method to create new directory in my Android 13 device, it creates two directories, one at the specified path and another one inside this new directory but with same name.

@VishnuSanal
Copy link
Member

@yatiksihag01 awesome! i will review the PR in a while.

Copy link
Member

@VishnuSanal VishnuSanal left a comment

Choose a reason for hiding this comment

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

@yatiksihag01 awesome work! operation with files works great as expected! I noticed some glitches on working with directories:

  • moving/copying a file from a path to another path simply falls back to the previous implementation (i.e, skip, overwrite, cancel). the dialog appears for every file within, if a directory is moved/copied.
  • can you think of a solution to fix the creation of empty directories within?

@yatiksihag01
Copy link
Contributor Author

Hi @VishnuSanal,

  • As I explained in my previous comment, when conflicting file is a directory, the original conflicting directory gets removed and a new node is created. And now all the files and subdirectories under this new node behave as conflicting files. This problem is even with stable version of app. So we've two choices, either we simply rename and save conflicting directories without showing any dialog or explore an entirely new implementation using Kotlin, maybe using suspendCancellableCoroutine or something else I'm not sure.
  • I haven't fully investigated the mkdirs() bug yet, as I wasn't sure whether there's an existing open issue and if someone is fixing it. I'll try to fix it.

@yatiksihag01
Copy link
Contributor Author

Actually the duplicate subdirectory issue was caused by the wrong HybridFile constructor I used. I resolved this issue and also documented the MakeDirectoryOperation.mkdirs() method to provide guidance for future developers.

@yatiksihag01 yatiksihag01 marked this pull request as draft August 20, 2023 04:50
@VishnuSanal
Copy link
Member

VishnuSanal commented Sep 3, 2023

I tested here & there were some unexpected behaviors; I'll post a detailed review comment in a while. (edit: or should I? since this is still in WIP? 🤔)

@yatiksihag01
Copy link
Contributor Author

@VishnuSanal, I still have some work to do, but please tell about the unexpected behavior you encountered.

@VishnuSanal
Copy link
Member

@VishnuSanal, I still have some work to do, but please tell about the unexpected behavior you encountered.

i see. I basically wasn't able to rename. copying & moving from a different directory prompted me a dialog, clicking on 'rename' resulted in a Toast message saying 'no file overwritten' (both files & directories). copying from the same directory resulted in the same too. moving to the same directory resulted in the new operation not permitted Toast message.

@yatiksihag01
Copy link
Contributor Author

yatiksihag01 commented Sep 7, 2023

@VishnuSanal I fixed the issues you mentioned. There are still these bugs to be resolved by @TranceLove. And when user try to move the files in same directory they should see this toast message as it doesn't makes any sense to move file in same directory.

@yatiksihag01 yatiksihag01 marked this pull request as ready for review September 9, 2023 19:13
@VishalNehra
Copy link
Member

@VishnuSanal please review here as you get time

@VishalNehra
Copy link
Member

@yatiksihag01 please see and resolve the static code analysis errors in the build
https://github.com/TeamAmaze/AmazeFileManager/pull/3898/checks?check_run_id=16643918735

@yatiksihag01
Copy link
Contributor Author

@VishalNehra One error in static code analysis is about showDialog() function length. I can reduce the length but it'll add unnecessary complication. So should I do that?

@VishalNehra
Copy link
Member

Yes please

@VishalNehra
Copy link
Member

@VishnuSanal please review here

@VishalNehra
Copy link
Member

You're not using filenamehelper from #3913 ?

@yatiksihag01
Copy link
Contributor Author

@VishalNehra Yes, I'm using #3913 for renaming.

Copy link
Member

@VishnuSanal VishnuSanal left a comment

Choose a reason for hiding this comment

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

great job! works as expected. operations I tested:

  • moving to the same directory
    • "same destination & source Toast" (both for directories & files)
  • copying to the same directory
    • works as expected (both for directories & files)
  • copying/moving from another directory
    • directory: works as expected
    • file: works as expected most of the times; but when I rename the source folder & try copy/cut & paste again, renaming fails. if cut option is selected, the source files are getting deleted.

approving this for merge for now, since failure is happening only on an edge case (which most users wouldn't even notice, IMO) - @yatiksihag01 you can fix this in this PR if you can figure out why this happens from the top of your head, else, we can have a new issue & you can fix it later as you wish.

awesome work, once again!

(PS: sorry for the delayed review 😔)

@VishalNehra VishalNehra merged commit 6783e4d into TeamAmaze:release/4.0 Sep 24, 2023
3 checks passed
@VishalNehra
Copy link
Member

Write to us on telegram for a bounty on this issue thanks again for contributing 🙂

@yatiksihag01
Copy link
Contributor Author

file: works as expected most of the times; but when I rename the source folder & try copy/cut & paste again, renaming fails. if cut option is selected, the source files are getting deleted.

Hi @VishnuSanal, appreciate your feedback and approval. Could you provide more details on the issue and steps to reproduce it? Kindly open an issue and assign it to me. I'll work on a fix soon.

@yatiksihag01
Copy link
Contributor Author

Hi @VishalNehra, thank you for your kind offer of a bounty for my contribution but I did not expect any monetary rewards for this PR. I'm grateful for the opportunity to have contributed to the project:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NPE when pasting a deleted/modified file
4 participants